"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.__tsfTypeAliases = exports.HttpRequestLogger = void 0;
const tslib_1 = require("tslib");
const _a = tslib_1.__importStar(require("@zyno-io/ts-reflection/type-metadata-runtime"));
const const_1 = require("../app/const");
const logger_1 = require("../services/logger");
const errors_1 = require("./errors");
const request_error_state_1 = require("./request-error-state");
const __tsf_metadata_type = _a.createCompactMetadataRegistryV1("[1,[{\"kind\":3},{\"kind\":18,\"typeName\":\"ResponseLoggingTarget\",\"types\":[{\"kind\":20,\"name\":\"statusCode\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"writableEnded\",\"type\":{\"kind\":8},\"optional\":false}]},{\"kind\":2},{\"kind\":7},{\"kind\":8}]]", []);
let _HttpRequestLoggerMetadata_1;
class HttpRequestLogger {
    config;
    logger;
    options;
    constructor(config, logger, options = {}) {
        this.config = config;
        this.logger = logger;
        this.options = options;
    }
    createState(request, outgoing) {
        const state = {
            request,
            logger: this.logger,
            mode: this.config.HTTP_REQUEST_LOGGING_MODE ?? getDefaultRequestLoggingMode(),
            startedAt: Date.now(),
            skipped: this.shouldSkip(request),
            aborted: false,
            finished: false,
            hooked: false
        };
        const onClose = () => {
            if (state.finished || state.aborted || outgoing.writableFinished)
                return;
            state.aborted = true;
            if (this.shouldLogAbort(state)) {
                this.loggerFor(state).warn('Request aborted during processing', {
                    method: request.method,
                    url: request.url,
                    duration: Date.now() - state.startedAt
                });
            }
            this.dispose(state, outgoing);
        };
        const onFinish = () => {
            this.finish(state, outgoing);
            this.dispose(state, outgoing);
        };
        state.onClose = onClose;
        state.onFinish = onFinish;
        outgoing.on('close', onClose);
        outgoing.on('finish', onFinish);
        return state;
    }
    start(state) {
        state.request.store['$RequestTime'] = state.startedAt;
        if (state.mode !== 'e2e' || state.skipped)
            return;
        this.loggerFor(state).info('Request', {
            method: state.request.method,
            url: state.request.url,
            remoteAddress: state.request.getRemoteAddress(),
            contentLength: state.request.headers['content-length']
        });
    }
    finish(state, response) {
        if (state.finished || state.aborted)
            return;
        state.finished = true;
        if (!this.shouldLogFinish(state, response.statusCode))
            return;
        this.loggerFor(state).info('Response', {
            method: state.request.method,
            url: state.request.url,
            statusCode: response.statusCode,
            duration: Date.now() - state.startedAt
        });
    }
    hook(state, response) {
        if (state.finished || state.aborted || state.hooked || response.writableEnded)
            return;
        state.hooked = true;
        if (!this.shouldLogFinish(state, response.statusCode))
            return;
        this.loggerFor(state).info('Response stream hooked by controller', {
            method: state.request.method,
            url: state.request.url,
            statusCode: response.statusCode,
            duration: Date.now() - state.startedAt
        });
    }
    error(state, error, response) {
        if (!error || state.skipped || state.mode === 'none')
            return;
        if (error instanceof errors_1.HttpError) {
            const requestError = (0, request_error_state_1.getHttpRequestErrorState)(state.request);
            if (requestError?.error === error && requestError.matchedRoute) {
                this.loggerFor(state).warn('Request processing error', { 'error.message': error.message });
            }
            return;
        }
        if (response.statusCode < 500)
            return;
        this.loggerFor(state).error('Request processing error', error, {
            method: state.request.method,
            url: state.request.url,
            statusCode: response.statusCode,
            duration: Date.now() - state.startedAt
        });
    }
    errorForRequest(request, response, startedAt, error) {
        this.error({
            request,
            logger: this.logger,
            mode: this.config.HTTP_REQUEST_LOGGING_MODE ?? getDefaultRequestLoggingMode(),
            startedAt,
            skipped: this.shouldSkip(request),
            aborted: false,
            finished: false,
            hooked: false
        }, error, response);
    }
    loggerFor(state) {
        const httpContext = (0, logger_1.projectLoggerHttpContext)(state.request.context);
        return httpContext ? state.logger.data({ http: httpContext }) : state.logger;
    }
    dispose(state, outgoing) {
        if (state.onClose)
            outgoing.off('close', state.onClose);
        if (state.onFinish)
            outgoing.off('finish', state.onFinish);
    }
    shouldSkip(request) {
        if (request.path === '/metrics')
            return true;
        if (['/healthz', '/readyz', '/livez'].includes(request.path) && this.config.HEALTHZ_ENABLE_REQUEST_LOGGING !== true)
            return true;
        return this.options.excludePaths?.some(path => matchesPath(request.path, path)) ?? false;
    }
    shouldLogFinish(state, _statusCode) {
        if (state.skipped)
            return false;
        if (state.mode === 'none')
            return false;
        if (state.mode === 'errors')
            return false;
        return true;
    }
    shouldLogAbort(state) {
        if (state.skipped)
            return false;
        return state.mode === 'e2e' || state.mode === 'errors';
    }
    static __tsfType = _HttpRequestLoggerMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"HttpRequestLogger\",\"typeName\":\"HttpRequestLogger\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[{\"name\":\"createState\",\"parameters\":[{\"name\":\"request\",\"type\":{\"kind\":16,\"typeName\":\"HttpRequest\",\"classType\":{\"$tsfImport\":[1,\"./request\",\"HttpRequest\"]}},\"optional\":false,\"default\":false},{\"name\":\"outgoing\",\"type\":{\"$tsfAlias\":[1,\"node:http\",\"ServerResponse\",\"ServerResponse\"]},\"optional\":false,\"default\":false}],\"returnType\":{\"kind\":18,\"typeName\":\"RequestLoggingState\",\"types\":[{\"kind\":20,\"name\":\"request\",\"type\":{\"kind\":16,\"typeName\":\"HttpRequest\",\"classType\":{\"$tsfImport\":[1,\"./request\",\"HttpRequest\"]}},\"optional\":false},{\"kind\":20,\"name\":\"logger\",\"type\":{\"kind\":16,\"typeName\":\"ScopedLogger\",\"classType\":{\"$tsfImport\":[1,\"../services/logger\",\"ScopedLogger\"]}},\"optional\":false},{\"kind\":20,\"name\":\"mode\",\"type\":{\"kind\":12,\"types\":[{\"kind\":10,\"literal\":\"none\"},{\"kind\":10,\"literal\":\"e2e\"},{\"kind\":10,\"literal\":\"finish\"},{\"kind\":10,\"literal\":\"errors\"}],\"typeName\":\"RequestLoggingMode\"},\"optional\":false},{\"kind\":20,\"name\":\"startedAt\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"skipped\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"aborted\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"finished\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"hooked\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"onClose\",\"type\":{\"kind\":12,\"types\":[{\"kind\":2,\"typeName\":\"() =\\u003e void\"},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"onFinish\",\"type\":{\"kind\":12,\"types\":[{\"kind\":2,\"typeName\":\"() =\\u003e void\"},{\"kind\":4}]},\"optional\":true}]}},{\"name\":\"start\",\"parameters\":[{\"name\":\"state\",\"type\":{\"kind\":18,\"typeName\":\"RequestLoggingState\",\"types\":[{\"kind\":20,\"name\":\"request\",\"type\":{\"kind\":16,\"typeName\":\"HttpRequest\",\"classType\":{\"$tsfImport\":[1,\"./request\",\"HttpRequest\"]}},\"optional\":false},{\"kind\":20,\"name\":\"logger\",\"type\":{\"kind\":16,\"typeName\":\"ScopedLogger\",\"classType\":{\"$tsfImport\":[1,\"../services/logger\",\"ScopedLogger\"]}},\"optional\":false},{\"kind\":20,\"name\":\"mode\",\"type\":{\"kind\":12,\"types\":[{\"kind\":10,\"literal\":\"none\"},{\"kind\":10,\"literal\":\"e2e\"},{\"kind\":10,\"literal\":\"finish\"},{\"kind\":10,\"literal\":\"errors\"}],\"typeName\":\"RequestLoggingMode\"},\"optional\":false},{\"kind\":20,\"name\":\"startedAt\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"skipped\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"aborted\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"finished\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"hooked\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"onClose\",\"type\":{\"kind\":12,\"types\":[{\"kind\":2,\"typeName\":\"() =\\u003e void\"},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"onFinish\",\"type\":{\"kind\":12,\"types\":[{\"kind\":2,\"typeName\":\"() =\\u003e void\"},{\"kind\":4}]},\"optional\":true}]},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":0}},{\"name\":\"finish\",\"parameters\":[{\"name\":\"state\",\"type\":{\"kind\":18,\"typeName\":\"RequestLoggingState\",\"types\":[{\"kind\":20,\"name\":\"request\",\"type\":{\"kind\":16,\"typeName\":\"HttpRequest\",\"classType\":{\"$tsfImport\":[1,\"./request\",\"HttpRequest\"]}},\"optional\":false},{\"kind\":20,\"name\":\"logger\",\"type\":{\"kind\":16,\"typeName\":\"ScopedLogger\",\"classType\":{\"$tsfImport\":[1,\"../services/logger\",\"ScopedLogger\"]}},\"optional\":false},{\"kind\":20,\"name\":\"mode\",\"type\":{\"kind\":12,\"types\":[{\"kind\":10,\"literal\":\"none\"},{\"kind\":10,\"literal\":\"e2e\"},{\"kind\":10,\"literal\":\"finish\"},{\"kind\":10,\"literal\":\"errors\"}],\"typeName\":\"RequestLoggingMode\"},\"optional\":false},{\"kind\":20,\"name\":\"startedAt\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"skipped\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"aborted\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"finished\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"hooked\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"onClose\",\"type\":{\"kind\":12,\"types\":[{\"kind\":2,\"typeName\":\"() =\\u003e void\"},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"onFinish\",\"type\":{\"kind\":12,\"types\":[{\"kind\":2,\"typeName\":\"() =\\u003e void\"},{\"kind\":4}]},\"optional\":true}]},\"optional\":false,\"default\":false},{\"name\":\"response\",\"type\":{\"$tsfType\":1},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":0}},{\"name\":\"hook\",\"parameters\":[{\"name\":\"state\",\"type\":{\"kind\":18,\"typeName\":\"RequestLoggingState\",\"types\":[{\"kind\":20,\"name\":\"request\",\"type\":{\"kind\":16,\"typeName\":\"HttpRequest\",\"classType\":{\"$tsfImport\":[1,\"./request\",\"HttpRequest\"]}},\"optional\":false},{\"kind\":20,\"name\":\"logger\",\"type\":{\"kind\":16,\"typeName\":\"ScopedLogger\",\"classType\":{\"$tsfImport\":[1,\"../services/logger\",\"ScopedLogger\"]}},\"optional\":false},{\"kind\":20,\"name\":\"mode\",\"type\":{\"kind\":12,\"types\":[{\"kind\":10,\"literal\":\"none\"},{\"kind\":10,\"literal\":\"e2e\"},{\"kind\":10,\"literal\":\"finish\"},{\"kind\":10,\"literal\":\"errors\"}],\"typeName\":\"RequestLoggingMode\"},\"optional\":false},{\"kind\":20,\"name\":\"startedAt\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"skipped\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"aborted\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"finished\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"hooked\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"onClose\",\"type\":{\"kind\":12,\"types\":[{\"kind\":2,\"typeName\":\"() =\\u003e void\"},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"onFinish\",\"type\":{\"kind\":12,\"types\":[{\"kind\":2,\"typeName\":\"() =\\u003e void\"},{\"kind\":4}]},\"optional\":true}]},\"optional\":false,\"default\":false},{\"name\":\"response\",\"type\":{\"$tsfType\":1},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":0}},{\"name\":\"error\",\"parameters\":[{\"name\":\"state\",\"type\":{\"kind\":18,\"typeName\":\"RequestLoggingState\",\"types\":[{\"kind\":20,\"name\":\"request\",\"type\":{\"kind\":16,\"typeName\":\"HttpRequest\",\"classType\":{\"$tsfImport\":[1,\"./request\",\"HttpRequest\"]}},\"optional\":false},{\"kind\":20,\"name\":\"logger\",\"type\":{\"kind\":16,\"typeName\":\"ScopedLogger\",\"classType\":{\"$tsfImport\":[1,\"../services/logger\",\"ScopedLogger\"]}},\"optional\":false},{\"kind\":20,\"name\":\"mode\",\"type\":{\"kind\":12,\"types\":[{\"kind\":10,\"literal\":\"none\"},{\"kind\":10,\"literal\":\"e2e\"},{\"kind\":10,\"literal\":\"finish\"},{\"kind\":10,\"literal\":\"errors\"}],\"typeName\":\"RequestLoggingMode\"},\"optional\":false},{\"kind\":20,\"name\":\"startedAt\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"skipped\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"aborted\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"finished\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"hooked\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"onClose\",\"type\":{\"kind\":12,\"types\":[{\"kind\":2,\"typeName\":\"() =\\u003e void\"},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"onFinish\",\"type\":{\"kind\":12,\"types\":[{\"kind\":2,\"typeName\":\"() =\\u003e void\"},{\"kind\":4}]},\"optional\":true}]},\"optional\":false,\"default\":false},{\"name\":\"error\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false},{\"name\":\"response\",\"type\":{\"$tsfType\":1},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":0}},{\"name\":\"errorForRequest\",\"parameters\":[{\"name\":\"request\",\"type\":{\"kind\":16,\"typeName\":\"HttpRequest\",\"classType\":{\"$tsfImport\":[1,\"./request\",\"HttpRequest\"]}},\"optional\":false,\"default\":false},{\"name\":\"response\",\"type\":{\"$tsfType\":1},\"optional\":false,\"default\":false},{\"name\":\"startedAt\",\"type\":{\"$tsfType\":3},\"optional\":false,\"default\":false},{\"name\":\"error\",\"type\":{\"$tsfType\":2},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":0}},{\"name\":\"dispose\",\"parameters\":[{\"name\":\"state\",\"type\":{\"kind\":18,\"typeName\":\"RequestLoggingState\",\"types\":[{\"kind\":20,\"name\":\"request\",\"type\":{\"kind\":16,\"typeName\":\"HttpRequest\",\"classType\":{\"$tsfImport\":[1,\"./request\",\"HttpRequest\"]}},\"optional\":false},{\"kind\":20,\"name\":\"logger\",\"type\":{\"kind\":16,\"typeName\":\"ScopedLogger\",\"classType\":{\"$tsfImport\":[1,\"../services/logger\",\"ScopedLogger\"]}},\"optional\":false},{\"kind\":20,\"name\":\"mode\",\"type\":{\"kind\":12,\"types\":[{\"kind\":10,\"literal\":\"none\"},{\"kind\":10,\"literal\":\"e2e\"},{\"kind\":10,\"literal\":\"finish\"},{\"kind\":10,\"literal\":\"errors\"}],\"typeName\":\"RequestLoggingMode\"},\"optional\":false},{\"kind\":20,\"name\":\"startedAt\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"skipped\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"aborted\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"finished\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"hooked\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"onClose\",\"type\":{\"kind\":12,\"types\":[{\"kind\":2,\"typeName\":\"() =\\u003e void\"},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"onFinish\",\"type\":{\"kind\":12,\"types\":[{\"kind\":2,\"typeName\":\"() =\\u003e void\"},{\"kind\":4}]},\"optional\":true}]},\"optional\":false,\"default\":false},{\"name\":\"outgoing\",\"type\":{\"$tsfAlias\":[1,\"node:http\",\"ServerResponse\",\"ServerResponse\"]},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":0}},{\"name\":\"shouldSkip\",\"parameters\":[{\"name\":\"request\",\"type\":{\"kind\":16,\"typeName\":\"HttpRequest\",\"classType\":{\"$tsfImport\":[1,\"./request\",\"HttpRequest\"]}},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":4}},{\"name\":\"shouldLogFinish\",\"parameters\":[{\"name\":\"state\",\"type\":{\"kind\":18,\"typeName\":\"Pick\",\"utilityType\":\"Pick\",\"typeArguments\":[{\"kind\":18,\"typeName\":\"RequestLoggingState\",\"types\":[{\"kind\":20,\"name\":\"request\",\"type\":{\"kind\":16,\"typeName\":\"HttpRequest\",\"classType\":{\"$tsfImport\":[1,\"./request\",\"HttpRequest\"]}},\"optional\":false},{\"kind\":20,\"name\":\"logger\",\"type\":{\"kind\":16,\"typeName\":\"ScopedLogger\",\"classType\":{\"$tsfImport\":[1,\"../services/logger\",\"ScopedLogger\"]}},\"optional\":false},{\"kind\":20,\"name\":\"mode\",\"type\":{\"kind\":12,\"types\":[{\"kind\":10,\"literal\":\"none\"},{\"kind\":10,\"literal\":\"e2e\"},{\"kind\":10,\"literal\":\"finish\"},{\"kind\":10,\"literal\":\"errors\"}],\"typeName\":\"RequestLoggingMode\"},\"optional\":false},{\"kind\":20,\"name\":\"startedAt\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"skipped\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"aborted\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"finished\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"hooked\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"onClose\",\"type\":{\"kind\":12,\"types\":[{\"kind\":2,\"typeName\":\"() =\\u003e void\"},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"onFinish\",\"type\":{\"kind\":12,\"types\":[{\"kind\":2,\"typeName\":\"() =\\u003e void\"},{\"kind\":4}]},\"optional\":true}]}],\"utilityKeys\":[\"mode\",\"skipped\"],\"types\":[{\"kind\":20,\"name\":\"mode\",\"type\":{\"kind\":12,\"types\":[{\"kind\":10,\"literal\":\"none\"},{\"kind\":10,\"literal\":\"e2e\"},{\"kind\":10,\"literal\":\"finish\"},{\"kind\":10,\"literal\":\"errors\"}],\"typeName\":\"RequestLoggingMode\"},\"optional\":false},{\"kind\":20,\"name\":\"skipped\",\"type\":{\"kind\":8},\"optional\":false}]},\"optional\":false,\"default\":false},{\"name\":\"_statusCode\",\"type\":{\"$tsfType\":3},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":4}},{\"name\":\"shouldLogAbort\",\"parameters\":[{\"name\":\"state\",\"type\":{\"kind\":18,\"typeName\":\"Pick\",\"utilityType\":\"Pick\",\"typeArguments\":[{\"kind\":18,\"typeName\":\"RequestLoggingState\",\"types\":[{\"kind\":20,\"name\":\"request\",\"type\":{\"kind\":16,\"typeName\":\"HttpRequest\",\"classType\":{\"$tsfImport\":[1,\"./request\",\"HttpRequest\"]}},\"optional\":false},{\"kind\":20,\"name\":\"logger\",\"type\":{\"kind\":16,\"typeName\":\"ScopedLogger\",\"classType\":{\"$tsfImport\":[1,\"../services/logger\",\"ScopedLogger\"]}},\"optional\":false},{\"kind\":20,\"name\":\"mode\",\"type\":{\"kind\":12,\"types\":[{\"kind\":10,\"literal\":\"none\"},{\"kind\":10,\"literal\":\"e2e\"},{\"kind\":10,\"literal\":\"finish\"},{\"kind\":10,\"literal\":\"errors\"}],\"typeName\":\"RequestLoggingMode\"},\"optional\":false},{\"kind\":20,\"name\":\"startedAt\",\"type\":{\"kind\":7},\"optional\":false},{\"kind\":20,\"name\":\"skipped\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"aborted\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"finished\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"hooked\",\"type\":{\"kind\":8},\"optional\":false},{\"kind\":20,\"name\":\"onClose\",\"type\":{\"kind\":12,\"types\":[{\"kind\":2,\"typeName\":\"() =\\u003e void\"},{\"kind\":4}]},\"optional\":true},{\"kind\":20,\"name\":\"onFinish\",\"type\":{\"kind\":12,\"types\":[{\"kind\":2,\"typeName\":\"() =\\u003e void\"},{\"kind\":4}]},\"optional\":true}]}],\"utilityKeys\":[\"mode\",\"skipped\"],\"types\":[{\"kind\":20,\"name\":\"mode\",\"type\":{\"kind\":12,\"types\":[{\"kind\":10,\"literal\":\"none\"},{\"kind\":10,\"literal\":\"e2e\"},{\"kind\":10,\"literal\":\"finish\"},{\"kind\":10,\"literal\":\"errors\"}],\"typeName\":\"RequestLoggingMode\"},\"optional\":false},{\"kind\":20,\"name\":\"skipped\",\"type\":{\"kind\":8},\"optional\":false}]},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":4}}],\"hasConstructor\":true,\"constructorParameters\":[{\"name\":\"config\",\"type\":{\"kind\":16,\"typeName\":\"BaseAppConfig\",\"classType\":{\"$tsfImport\":[1,\"../app/config\",\"BaseAppConfig\"]}},\"optional\":false,\"default\":false},{\"name\":\"logger\",\"type\":{\"kind\":16,\"typeName\":\"ScopedLogger\",\"classType\":{\"$tsfImport\":[1,\"../services/logger\",\"ScopedLogger\"]}},\"optional\":false,\"default\":false},{\"name\":\"options\",\"type\":{\"kind\":18,\"typeName\":\"HttpRequestLoggingOptions\",\"types\":[{\"kind\":20,\"name\":\"excludePaths\",\"type\":{\"kind\":12,\"types\":[{\"kind\":14,\"type\":{\"kind\":12,\"types\":[{\"kind\":6},{\"kind\":16,\"typeName\":\"RegExp\",\"classType\":{\"$tsf\":2}}]}},{\"kind\":4}]},\"optional\":true}]},\"optional\":true,\"default\":true}]}]", [() => HttpRequestLogger, require, () => (typeof RegExp !== "undefined" ? RegExp : (typeof exports !== "undefined" ? exports.RegExp : undefined))], __tsf_metadata_type);
}
exports.HttpRequestLogger = HttpRequestLogger;
_HttpRequestLoggerMetadata_1.classType = HttpRequestLogger;
HttpRequestLogger.__tsfType = _HttpRequestLoggerMetadata_1;
function matchesPath(requestPath, excludedPath) {
    if (typeof excludedPath === 'string')
        return requestPath === excludedPath;
    const pattern = excludedPath.global || excludedPath.sticky ? new RegExp(excludedPath.source, excludedPath.flags) : excludedPath;
    return pattern.test(requestPath);
}
function getDefaultRequestLoggingMode() {
    return (0, const_1.isTestEnvironment)() ? 'errors' : 'e2e';
}
exports.__tsfTypeAliases = _a.decodeCompactMetadataV1("[1,{\"HttpRequestLoggingOptions\":{\"kind\":18,\"typeName\":\"HttpRequestLoggingOptions\",\"types\":[{\"kind\":20,\"name\":\"excludePaths\",\"type\":{\"kind\":12,\"types\":[{\"kind\":14,\"type\":{\"kind\":12,\"types\":[{\"kind\":6},{\"kind\":16,\"typeName\":\"RegExp\",\"classType\":{\"$tsf\":0}}]}},{\"kind\":4}]},\"optional\":true}]}}]", [() => (typeof RegExp !== "undefined" ? RegExp : (typeof exports !== "undefined" ? exports.RegExp : undefined))], __tsf_metadata_type);
//# sourceMappingURL=request-logging.js.map