@antelopejs/dms-api 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/README.md +61 -0
- package/dist/automation/get-api-health.d.ts +10 -0
- package/dist/automation/get-api-health.js +53 -0
- package/dist/automation/get-api-health.js.map +1 -0
- package/dist/automation/index.d.ts +2 -0
- package/dist/automation/index.js +19 -0
- package/dist/automation/index.js.map +1 -0
- package/dist/automation/query-request-logs.d.ts +18 -0
- package/dist/automation/query-request-logs.js +50 -0
- package/dist/automation/query-request-logs.js.map +1 -0
- package/dist/automation/route-unhealthy.d.ts +9 -0
- package/dist/automation/route-unhealthy.js +102 -0
- package/dist/automation/route-unhealthy.js.map +1 -0
- package/dist/automation/scope.d.ts +2 -0
- package/dist/automation/scope.js +18 -0
- package/dist/automation/scope.js.map +1 -0
- package/dist/config.d.ts +12 -0
- package/dist/config.js +38 -0
- package/dist/config.js.map +1 -0
- package/dist/db/index.d.ts +2 -0
- package/dist/db/index.js +19 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/models/api_settings.model.d.ts +23 -0
- package/dist/db/models/api_settings.model.js +13 -0
- package/dist/db/models/api_settings.model.js.map +1 -0
- package/dist/db/models/index.d.ts +4 -0
- package/dist/db/models/index.js +21 -0
- package/dist/db/models/index.js.map +1 -0
- package/dist/db/models/request_log.model.d.ts +47 -0
- package/dist/db/models/request_log.model.js +127 -0
- package/dist/db/models/request_log.model.js.map +1 -0
- package/dist/db/models/routes.model.d.ts +22 -0
- package/dist/db/models/routes.model.js +9 -0
- package/dist/db/models/routes.model.js.map +1 -0
- package/dist/db/models/routes_statistics.model.d.ts +23 -0
- package/dist/db/models/routes_statistics.model.js +13 -0
- package/dist/db/models/routes_statistics.model.js.map +1 -0
- package/dist/db/tables/api_settings.table.d.ts +10 -0
- package/dist/db/tables/api_settings.table.js +47 -0
- package/dist/db/tables/api_settings.table.js.map +1 -0
- package/dist/db/tables/index.d.ts +4 -0
- package/dist/db/tables/index.js +21 -0
- package/dist/db/tables/index.js.map +1 -0
- package/dist/db/tables/request_log.table.d.ts +29 -0
- package/dist/db/tables/request_log.table.js +107 -0
- package/dist/db/tables/request_log.table.js.map +1 -0
- package/dist/db/tables/routes.table.d.ts +11 -0
- package/dist/db/tables/routes.table.js +50 -0
- package/dist/db/tables/routes.table.js.map +1 -0
- package/dist/db/tables/routes_statistics.table.d.ts +9 -0
- package/dist/db/tables/routes_statistics.table.js +38 -0
- package/dist/db/tables/routes_statistics.table.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/middlewares/index.d.ts +1 -0
- package/dist/middlewares/index.js +18 -0
- package/dist/middlewares/index.js.map +1 -0
- package/dist/middlewares/request-log-capture.d.ts +1 -0
- package/dist/middlewares/request-log-capture.js +6 -0
- package/dist/middlewares/request-log-capture.js.map +1 -0
- package/dist/pages/all.d.ts +4 -0
- package/dist/pages/all.js +21 -0
- package/dist/pages/all.js.map +1 -0
- package/dist/pages/index.d.ts +4 -0
- package/dist/pages/index.js +21 -0
- package/dist/pages/index.js.map +1 -0
- package/dist/pages/logs/page.d.ts +9 -0
- package/dist/pages/logs/page.js +29 -0
- package/dist/pages/logs/page.js.map +1 -0
- package/dist/pages/module.d.ts +1 -0
- package/dist/pages/module.js +12 -0
- package/dist/pages/module.js.map +1 -0
- package/dist/pages/routes/page.d.ts +9 -0
- package/dist/pages/routes/page.js +29 -0
- package/dist/pages/routes/page.js.map +1 -0
- package/dist/pages/settings/form.d.ts +3 -0
- package/dist/pages/settings/form.js +80 -0
- package/dist/pages/settings/form.js.map +1 -0
- package/dist/pages/settings/page.d.ts +9 -0
- package/dist/pages/settings/page.js +26 -0
- package/dist/pages/settings/page.js.map +1 -0
- package/dist/pages/summary/page.d.ts +9 -0
- package/dist/pages/summary/page.js +29 -0
- package/dist/pages/summary/page.js.map +1 -0
- package/dist/routes/index.d.ts +5 -0
- package/dist/routes/index.js +22 -0
- package/dist/routes/index.js.map +1 -0
- package/dist/routes/logs.d.ts +7 -0
- package/dist/routes/logs.js +128 -0
- package/dist/routes/logs.js.map +1 -0
- package/dist/routes/monitoring.d.ts +17 -0
- package/dist/routes/monitoring.js +101 -0
- package/dist/routes/monitoring.js.map +1 -0
- package/dist/routes/routes.d.ts +37 -0
- package/dist/routes/routes.js +153 -0
- package/dist/routes/routes.js.map +1 -0
- package/dist/routes/settings.d.ts +24 -0
- package/dist/routes/settings.js +92 -0
- package/dist/routes/settings.js.map +1 -0
- package/dist/routes/summary.d.ts +32 -0
- package/dist/routes/summary.js +181 -0
- package/dist/routes/summary.js.map +1 -0
- package/dist/services/index.d.ts +11 -0
- package/dist/services/index.js +28 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/introspection/auth.d.ts +4 -0
- package/dist/services/introspection/auth.js +33 -0
- package/dist/services/introspection/auth.js.map +1 -0
- package/dist/services/introspection/errors.d.ts +6 -0
- package/dist/services/introspection/errors.js +50 -0
- package/dist/services/introspection/errors.js.map +1 -0
- package/dist/services/introspection/index.d.ts +53 -0
- package/dist/services/introspection/index.js +141 -0
- package/dist/services/introspection/index.js.map +1 -0
- package/dist/services/introspection/probe.d.ts +18 -0
- package/dist/services/introspection/probe.js +155 -0
- package/dist/services/introspection/probe.js.map +1 -0
- package/dist/services/period.d.ts +11 -0
- package/dist/services/period.js +68 -0
- package/dist/services/period.js.map +1 -0
- package/dist/services/request-log/capture.d.ts +10 -0
- package/dist/services/request-log/capture.js +189 -0
- package/dist/services/request-log/capture.js.map +1 -0
- package/dist/services/request-log/index.d.ts +3 -0
- package/dist/services/request-log/index.js +12 -0
- package/dist/services/request-log/index.js.map +1 -0
- package/dist/services/request-log/prune.d.ts +2 -0
- package/dist/services/request-log/prune.js +10 -0
- package/dist/services/request-log/prune.js.map +1 -0
- package/dist/services/request-log/read.d.ts +6 -0
- package/dist/services/request-log/read.js +26 -0
- package/dist/services/request-log/read.js.map +1 -0
- package/dist/services/request-log/redaction.d.ts +4 -0
- package/dist/services/request-log/redaction.js +53 -0
- package/dist/services/request-log/redaction.js.map +1 -0
- package/dist/services/request-log/util.d.ts +13 -0
- package/dist/services/request-log/util.js +114 -0
- package/dist/services/request-log/util.js.map +1 -0
- package/dist/services/routes-sync.d.ts +5 -0
- package/dist/services/routes-sync.js +63 -0
- package/dist/services/routes-sync.js.map +1 -0
- package/dist/services/scope.d.ts +7 -0
- package/dist/services/scope.js +40 -0
- package/dist/services/scope.js.map +1 -0
- package/dist/services/settings.d.ts +20 -0
- package/dist/services/settings.js +86 -0
- package/dist/services/settings.js.map +1 -0
- package/dist/services/statistics-aggregate.d.ts +67 -0
- package/dist/services/statistics-aggregate.js +340 -0
- package/dist/services/statistics-aggregate.js.map +1 -0
- package/dist/services/statistics-prune.d.ts +2 -0
- package/dist/services/statistics-prune.js +25 -0
- package/dist/services/statistics-prune.js.map +1 -0
- package/dist/services/statistics-read.d.ts +4 -0
- package/dist/services/statistics-read.js +48 -0
- package/dist/services/statistics-read.js.map +1 -0
- package/dist/services/statistics-utils.d.ts +14 -0
- package/dist/services/statistics-utils.js +65 -0
- package/dist/services/statistics-utils.js.map +1 -0
- package/dist/services/statistics-write.d.ts +3 -0
- package/dist/services/statistics-write.js +84 -0
- package/dist/services/statistics-write.js.map +1 -0
- package/dist/services/tree.d.ts +10 -0
- package/dist/services/tree.js +128 -0
- package/dist/services/tree.js.map +1 -0
- package/dist/types/charts.d.ts +9 -0
- package/dist/types/charts.js +3 -0
- package/dist/types/charts.js.map +1 -0
- package/dist/types/constants.d.ts +31 -0
- package/dist/types/constants.js +49 -0
- package/dist/types/constants.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +20 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/statistics.d.ts +17 -0
- package/dist/types/statistics.js +3 -0
- package/dist/types/statistics.js.map +1 -0
- package/frontend-vue/.editorconfig +12 -0
- package/frontend-vue/.prettierrc +12 -0
- package/frontend-vue/.vscode/settings.json +26 -0
- package/frontend-vue/app/components/ConfigurationView.vue +187 -0
- package/frontend-vue/app/components/DocumentationView.vue +224 -0
- package/frontend-vue/app/components/LogDetailDrawer.vue +178 -0
- package/frontend-vue/app/components/LogsView.vue +347 -0
- package/frontend-vue/app/components/RouteDetailTabs.vue +179 -0
- package/frontend-vue/app/components/RouteTree.vue +196 -0
- package/frontend-vue/app/components/RoutesView.vue +82 -0
- package/frontend-vue/app/components/StatsView.vue +268 -0
- package/frontend-vue/app/components/SummaryView.vue +657 -0
- package/frontend-vue/app/components/TesterPanel.vue +499 -0
- package/frontend-vue/app/components/internal/ApiMethodBadge.vue +33 -0
- package/frontend-vue/app/components/internal/ApiStatusBadge.vue +28 -0
- package/frontend-vue/app/components/internal/PeriodSelect.vue +58 -0
- package/frontend-vue/app/components/internal/RouteTreeNode.vue +168 -0
- package/frontend-vue/app/components/internal/StatusBreakdownBars.vue +162 -0
- package/frontend-vue/app/components/internal/StatusDonut.vue +84 -0
- package/frontend-vue/app/components/internal/UnitAreaChart.vue +73 -0
- package/frontend-vue/app/composables/useApiIntrospection.ts +344 -0
- package/frontend-vue/app/composables/useLogDetailDrawer.ts +50 -0
- package/frontend-vue/app/composables/useSelectedPeriod.ts +107 -0
- package/frontend-vue/app/composables/useStatsPeriods.ts +139 -0
- package/frontend-vue/app/custom-layouts/.gitkeep +0 -0
- package/frontend-vue/app/custom-pages/.gitkeep +0 -0
- package/frontend-vue/app/utils/httpMethod.ts +49 -0
- package/frontend-vue/app/utils/statusClass.ts +49 -0
- package/frontend-vue/app/utils/testerRequest.ts +50 -0
- package/frontend-vue/dms.frontend.ts +25 -0
- package/frontend-vue/eslint.config.mjs +16 -0
- package/frontend-vue/i18n/locales/en-GB.json +240 -0
- package/frontend-vue/i18n/locales/fr-FR.json +240 -0
- package/frontend-vue/package.json +35 -0
- package/frontend-vue/pnpm-lock.yaml +5796 -0
- package/frontend-vue/pnpm-workspace.yaml +2 -0
- package/frontend-vue/public/.gitkeep +0 -0
- package/frontend-vue/server/.gitkeep +0 -0
- package/frontend-vue/tests/periods.test.ts +145 -0
- package/frontend-vue/tests/persistence.test.ts +45 -0
- package/frontend-vue/tests/registration.test.ts +28 -0
- package/frontend-vue/tests/testerRequest.test.ts +95 -0
- package/frontend-vue/tsconfig.json +13 -0
- package/frontend-vue/vitest.config.ts +8 -0
- package/package.json +67 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.probeProvider = probeProvider;
|
|
4
|
+
exports.probeProperty = probeProperty;
|
|
5
|
+
const PROVIDER_PATTERNS = [
|
|
6
|
+
{
|
|
7
|
+
source: "param",
|
|
8
|
+
match: /routeParameters\s*(?:\[\s*['"]([^'"]+)['"]\s*\]|\.([A-Za-z_$][\w$]*))/,
|
|
9
|
+
nameGroup: 1,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
source: "query",
|
|
13
|
+
multi: true,
|
|
14
|
+
match: /searchParams\s*\.\s*getAll\s*\(\s*['"]([^'"]+)['"]\s*\)/,
|
|
15
|
+
nameGroup: 1,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
source: "query",
|
|
19
|
+
match: /searchParams\s*\.\s*get\s*\(\s*['"]([^'"]+)['"]\s*\)/,
|
|
20
|
+
nameGroup: 1,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
source: "query",
|
|
24
|
+
match: /searchParams\s*\[\s*['"]([^'"]+)['"]\s*\]/,
|
|
25
|
+
nameGroup: 1,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
source: "header",
|
|
29
|
+
match: /headers\s*(?:\[\s*['"]([^'"]+)['"]\s*\]|\.([A-Za-z_$][\w$]*))/,
|
|
30
|
+
nameGroup: 1,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
source: "body",
|
|
34
|
+
match: /JSON\s*\.\s*parse\b/,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
source: "raw",
|
|
38
|
+
match: /\bcontext\b\s*\.\s*body\b/,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
source: "stream",
|
|
42
|
+
match: /\b(?:rawResponse|writeHead|WriteStream)\b/,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
source: "connection",
|
|
46
|
+
match: /\bconnection\b/,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
source: "result",
|
|
50
|
+
match: /\bcontext\b\s*\.\s*response\b/,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
source: "context",
|
|
54
|
+
match: /^\s*(?:function[^(]*)?\s*\(([A-Za-z_$][\w$]*)\)\s*(?:=>\s*\1|\{\s*return\s+\1\s*;?\s*\})/,
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
function probeProvider(param) {
|
|
58
|
+
if (!param || !param.provider) {
|
|
59
|
+
return {
|
|
60
|
+
source: "unknown",
|
|
61
|
+
name: null,
|
|
62
|
+
multi: false,
|
|
63
|
+
inferredType: "unknown",
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const source = providerSource(param.provider);
|
|
67
|
+
for (const pattern of PROVIDER_PATTERNS) {
|
|
68
|
+
const m = source.match(pattern.match);
|
|
69
|
+
if (!m)
|
|
70
|
+
continue;
|
|
71
|
+
const name = pattern.nameGroup !== undefined
|
|
72
|
+
? (m[pattern.nameGroup] ?? m[pattern.nameGroup + 1] ?? null)
|
|
73
|
+
: null;
|
|
74
|
+
return {
|
|
75
|
+
source: pattern.source,
|
|
76
|
+
name,
|
|
77
|
+
multi: pattern.multi ?? false,
|
|
78
|
+
inferredType: inferType(pattern.source, source),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
source: "unknown",
|
|
83
|
+
name: null,
|
|
84
|
+
multi: false,
|
|
85
|
+
inferredType: "unknown",
|
|
86
|
+
rawProviderSource: source,
|
|
87
|
+
hint: extractHint(source),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function providerSource(fn) {
|
|
91
|
+
try {
|
|
92
|
+
return Function.prototype.toString.call(fn);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return "";
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function inferType(source, providerText) {
|
|
99
|
+
if (source === "raw")
|
|
100
|
+
return "buffer";
|
|
101
|
+
if (source === "stream")
|
|
102
|
+
return "stream";
|
|
103
|
+
if (source === "connection")
|
|
104
|
+
return "object";
|
|
105
|
+
if (source === "context" || source === "result")
|
|
106
|
+
return "object";
|
|
107
|
+
if (/JSON\s*\.\s*parse\b/.test(providerText))
|
|
108
|
+
return "object";
|
|
109
|
+
if (/\bNumber\s*\(/.test(providerText) ||
|
|
110
|
+
/\bparseInt\s*\(/.test(providerText) ||
|
|
111
|
+
/\bparseFloat\s*\(/.test(providerText) ||
|
|
112
|
+
/\+\s*[A-Za-z_$]/.test(providerText)) {
|
|
113
|
+
return "number";
|
|
114
|
+
}
|
|
115
|
+
if (/\bBoolean\s*\(/.test(providerText) ||
|
|
116
|
+
/!!\s*[A-Za-z_$]/.test(providerText) ||
|
|
117
|
+
/===\s*['"]true['"]/.test(providerText)) {
|
|
118
|
+
return "boolean";
|
|
119
|
+
}
|
|
120
|
+
if (source === "body")
|
|
121
|
+
return "object";
|
|
122
|
+
if (source === "param" || source === "query" || source === "header") {
|
|
123
|
+
return "string";
|
|
124
|
+
}
|
|
125
|
+
return "unknown";
|
|
126
|
+
}
|
|
127
|
+
function extractHint(providerText) {
|
|
128
|
+
const contextMatch = providerText.match(/\bcontext\s*\.\s*([A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*)*)/);
|
|
129
|
+
if (contextMatch) {
|
|
130
|
+
return contextMatch[1].replace(/\s+/g, "");
|
|
131
|
+
}
|
|
132
|
+
const bodyMatch = providerText.match(/=>\s*([A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*)*)/);
|
|
133
|
+
if (bodyMatch) {
|
|
134
|
+
return bodyMatch[1].replace(/\s+/g, "");
|
|
135
|
+
}
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
function probeProperty(param) {
|
|
139
|
+
if (!param.provider) {
|
|
140
|
+
return { decorator: "unknown" };
|
|
141
|
+
}
|
|
142
|
+
const source = providerSource(param.provider);
|
|
143
|
+
if (/\bGetModel\b/.test(source)) {
|
|
144
|
+
return { decorator: "Model" };
|
|
145
|
+
}
|
|
146
|
+
if (/\bgetInstance\b|\bcontainer\b/.test(source)) {
|
|
147
|
+
return { decorator: "Injected" };
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
decorator: "unknown",
|
|
151
|
+
rawProviderSource: source,
|
|
152
|
+
hint: extractHint(source),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=probe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"probe.js","sourceRoot":"","sources":["../../../src/services/introspection/probe.ts"],"names":[],"mappings":";;AAyIA,sCAqCC;AAuFD,sCAoBC;AAtOD,MAAM,iBAAiB,GAKlB;IAGH;QACE,MAAM,EAAE,OAAO;QACf,KAAK,EACH,uEAAuE;QACzE,SAAS,EAAE,CAAC;KACb;IAGD;QACE,MAAM,EAAE,OAAO;QACf,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,yDAAyD;QAChE,SAAS,EAAE,CAAC;KACb;IAGD;QACE,MAAM,EAAE,OAAO;QACf,KAAK,EAAE,sDAAsD;QAC7D,SAAS,EAAE,CAAC;KACb;IAED;QACE,MAAM,EAAE,OAAO;QACf,KAAK,EAAE,2CAA2C;QAClD,SAAS,EAAE,CAAC;KACb;IAGD;QACE,MAAM,EAAE,QAAQ;QAChB,KAAK,EAAE,+DAA+D;QACtE,SAAS,EAAE,CAAC;KACb;IAED;QACE,MAAM,EAAE,MAAM;QACd,KAAK,EA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function getMaxStatsDays(): number;
|
|
2
|
+
export declare function getMaxLogDays(): number;
|
|
3
|
+
export declare function getMaxLogMinutes(): number;
|
|
4
|
+
export declare function getMaxLogHours(): number;
|
|
5
|
+
export declare function parsePeriodDays(period?: string): number | undefined;
|
|
6
|
+
export declare function resolvePeriodDays(period: string | undefined, fallback: number): number;
|
|
7
|
+
export interface ParsedPeriod {
|
|
8
|
+
granularity: "minute" | "hour" | "day";
|
|
9
|
+
count: number;
|
|
10
|
+
}
|
|
11
|
+
export declare function parsePeriod(period?: string): ParsedPeriod | undefined;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMaxStatsDays = getMaxStatsDays;
|
|
4
|
+
exports.getMaxLogDays = getMaxLogDays;
|
|
5
|
+
exports.getMaxLogMinutes = getMaxLogMinutes;
|
|
6
|
+
exports.getMaxLogHours = getMaxLogHours;
|
|
7
|
+
exports.parsePeriodDays = parsePeriodDays;
|
|
8
|
+
exports.resolvePeriodDays = resolvePeriodDays;
|
|
9
|
+
exports.parsePeriod = parsePeriod;
|
|
10
|
+
const config_1 = require("@/config");
|
|
11
|
+
const types_1 = require("@/types");
|
|
12
|
+
function getMaxStatsDays() {
|
|
13
|
+
return Math.max(1, Math.round(retention("statisticsLifetime") / types_1.MS_PER_DAY));
|
|
14
|
+
}
|
|
15
|
+
function retention(key) {
|
|
16
|
+
const ms = (0, config_1.getConfig)()[key];
|
|
17
|
+
return Number.isFinite(ms) && ms > 0 ? ms : types_1.STATISTICS_RETENTION_MS;
|
|
18
|
+
}
|
|
19
|
+
function getMaxLogDays() {
|
|
20
|
+
return Math.max(1, Math.round(retention("requestLogRetention") / types_1.MS_PER_DAY));
|
|
21
|
+
}
|
|
22
|
+
function getMaxLogMinutes() {
|
|
23
|
+
return clampWindow(retention("requestLogRetention") / types_1.MS_PER_MINUTE, types_1.MAX_MINUTELY_MINUTES);
|
|
24
|
+
}
|
|
25
|
+
function getMaxLogHours() {
|
|
26
|
+
return clampWindow(retention("requestLogRetention") / types_1.MS_PER_HOUR, types_1.MAX_HOURLY_HOURS);
|
|
27
|
+
}
|
|
28
|
+
function clampWindow(available, ceiling) {
|
|
29
|
+
return Math.max(1, Math.min(ceiling, Math.floor(available)));
|
|
30
|
+
}
|
|
31
|
+
function parsePeriodDays(period) {
|
|
32
|
+
if (!period)
|
|
33
|
+
return undefined;
|
|
34
|
+
const m = period.match(/^(\d+)d$/);
|
|
35
|
+
if (!m)
|
|
36
|
+
return undefined;
|
|
37
|
+
const n = parseInt(m[1], 10);
|
|
38
|
+
if (n <= 0)
|
|
39
|
+
return undefined;
|
|
40
|
+
return Math.min(n, getMaxStatsDays());
|
|
41
|
+
}
|
|
42
|
+
function resolvePeriodDays(period, fallback) {
|
|
43
|
+
return parsePeriodDays(period) ?? Math.min(fallback, getMaxStatsDays());
|
|
44
|
+
}
|
|
45
|
+
function parsePeriod(period) {
|
|
46
|
+
if (!period)
|
|
47
|
+
return undefined;
|
|
48
|
+
const m = period.match(/^(\d+)([mhd])$/);
|
|
49
|
+
if (!m)
|
|
50
|
+
return undefined;
|
|
51
|
+
const count = parseInt(m[1], 10);
|
|
52
|
+
if (count <= 0)
|
|
53
|
+
return undefined;
|
|
54
|
+
if (m[2] === "m") {
|
|
55
|
+
return {
|
|
56
|
+
granularity: "minute",
|
|
57
|
+
count: Math.min(count, getMaxLogMinutes()),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (m[2] === "h") {
|
|
61
|
+
if (count === 1) {
|
|
62
|
+
return { granularity: "minute", count: Math.min(60, getMaxLogMinutes()) };
|
|
63
|
+
}
|
|
64
|
+
return { granularity: "hour", count: Math.min(count, getMaxLogHours()) };
|
|
65
|
+
}
|
|
66
|
+
return { granularity: "day", count: Math.min(count, getMaxStatsDays()) };
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=period.js.map
|
|
@@ -0,0 +1 @@
|
|
|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Q,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,gBAAgB,EAAE,CAAC,EAAE,CAAC;QAC5E,CAAC;QACD,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,cAAc,EAAE,CAAC,EAAE,CAAC;IAC3E,CAAC;IACD,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type RequestContext } from "@antelopejs/interface-api";
|
|
2
|
+
interface CaptureContext extends RequestContext {
|
|
3
|
+
__dmsApiCaptureStart?: bigint;
|
|
4
|
+
}
|
|
5
|
+
declare const RequestLogCapture_base: import("@antelopejs/interface-api").ControllerClass<object>;
|
|
6
|
+
export declare class RequestLogCapture extends RequestLogCapture_base {
|
|
7
|
+
start(context: CaptureContext): void;
|
|
8
|
+
capture(context: CaptureContext): void;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.RequestLogCapture = void 0;
|
|
16
|
+
const interface_api_1 = require("@antelopejs/interface-api");
|
|
17
|
+
const logging_1 = require("@antelopejs/interface-core/logging");
|
|
18
|
+
const interface_database_decorators_1 = require("@antelopejs/interface-database-decorators");
|
|
19
|
+
const config_1 = require("@/config");
|
|
20
|
+
const db_1 = require("@/db");
|
|
21
|
+
const statistics_write_1 = require("@/services/statistics-write");
|
|
22
|
+
const types_1 = require("@/types");
|
|
23
|
+
const util_1 = require("./util");
|
|
24
|
+
class RequestLogCapture extends (0, interface_api_1.Controller)("/") {
|
|
25
|
+
start(context) {
|
|
26
|
+
context.__dmsApiCaptureStart = process.hrtime.bigint();
|
|
27
|
+
}
|
|
28
|
+
capture(context) {
|
|
29
|
+
void persistLog(context).catch((err) => {
|
|
30
|
+
logging_1.Logging.Error("[dms-api] request log capture failed:", err);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.RequestLogCapture = RequestLogCapture;
|
|
35
|
+
__decorate([
|
|
36
|
+
(0, interface_api_1.Prefix)("any", "/", interface_api_1.HandlerPriority.HIGHEST),
|
|
37
|
+
__param(0, (0, interface_api_1.Context)()),
|
|
38
|
+
__metadata("design:type", Function),
|
|
39
|
+
__metadata("design:paramtypes", [Object]),
|
|
40
|
+
__metadata("design:returntype", void 0)
|
|
41
|
+
], RequestLogCapture.prototype, "start", null);
|
|
42
|
+
__decorate([
|
|
43
|
+
(0, interface_api_1.Monitor)("any", "/", interface_api_1.HandlerPriority.LOWEST),
|
|
44
|
+
__param(0, (0, interface_api_1.Context)()),
|
|
45
|
+
__metadata("design:type", Function),
|
|
46
|
+
__metadata("design:paramtypes", [Object]),
|
|
47
|
+
__metadata("design:returntype", void 0)
|
|
48
|
+
], RequestLogCapture.prototype, "capture", null);
|
|
49
|
+
function elapsedMs(start) {
|
|
50
|
+
return start ? Number(process.hrtime.bigint() - start) / types_1.NS_TO_MS : 0;
|
|
51
|
+
}
|
|
52
|
+
function recordRouteStatistics(method, uri, statusCode, responseTimeMs) {
|
|
53
|
+
void (0, statistics_write_1.addRequestStatistics)((0, interface_database_decorators_1.GetModel)(db_1.RouteStatisticsModel), {
|
|
54
|
+
responseTime: responseTimeMs,
|
|
55
|
+
method,
|
|
56
|
+
uri,
|
|
57
|
+
statusCode,
|
|
58
|
+
}).catch((err) => {
|
|
59
|
+
logging_1.Logging.Error("[dms-api] route statistics write failed:", err);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async function captureRequest(context, config) {
|
|
63
|
+
const headers = (0, util_1.pickHeaders)(context.rawRequest.headers, config.requestLogCaptureHeaders);
|
|
64
|
+
let raw;
|
|
65
|
+
try {
|
|
66
|
+
raw = await context.body;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
raw = undefined;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
headers,
|
|
73
|
+
body: (0, util_1.captureBody)(raw, headers["content-type"], config.requestLogMaxBodySize),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function captureResponse(response, config) {
|
|
77
|
+
const rawHeaders = (0, util_1.extractHeaders)(response);
|
|
78
|
+
const contentType = (0, util_1.extractContentType)(response) ?? rawHeaders["content-type"];
|
|
79
|
+
return {
|
|
80
|
+
headers: (0, util_1.pickHeaders)(rawHeaders, config.requestLogCaptureHeaders),
|
|
81
|
+
body: (0, util_1.captureBody)((0, util_1.extractBody)(response), contentType, config.requestLogMaxBodySize),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function assembleLogRecord(input) {
|
|
85
|
+
const { context, matched, request, response } = input;
|
|
86
|
+
const log = {
|
|
87
|
+
timestamp: new Date(),
|
|
88
|
+
method: input.method,
|
|
89
|
+
uri: input.uri,
|
|
90
|
+
rawPath: input.rawPath,
|
|
91
|
+
routeId: matched?.id,
|
|
92
|
+
pathParams: matched?.params ?? {},
|
|
93
|
+
query: (0, util_1.queryToRecord)(context.url),
|
|
94
|
+
requestHeaders: request.headers,
|
|
95
|
+
requestBody: request.body.body,
|
|
96
|
+
requestBodyTruncated: request.body.truncated,
|
|
97
|
+
statusCode: input.statusCode,
|
|
98
|
+
responseTimeMs: input.responseTimeMs,
|
|
99
|
+
responseHeaders: response.headers,
|
|
100
|
+
responseBody: response.body.body,
|
|
101
|
+
responseBodyTruncated: response.body.truncated,
|
|
102
|
+
error: formatError(context.error),
|
|
103
|
+
ip: clientIp(context),
|
|
104
|
+
userAgent: context.rawRequest.headers["user-agent"]?.toString(),
|
|
105
|
+
};
|
|
106
|
+
return log;
|
|
107
|
+
}
|
|
108
|
+
async function persistLog(context) {
|
|
109
|
+
const config = (0, config_1.getConfig)();
|
|
110
|
+
const responseTimeMs = elapsedMs(context.__dmsApiCaptureStart);
|
|
111
|
+
const method = (context.rawRequest.method || "GET").toUpperCase();
|
|
112
|
+
const rawPath = context.url.pathname;
|
|
113
|
+
const matched = matchRoute(method, rawPath);
|
|
114
|
+
const uri = matched?.location ?? rawPath;
|
|
115
|
+
const statusCode = (0, util_1.extractStatusCode)(context.response);
|
|
116
|
+
if (matched?.id) {
|
|
117
|
+
recordRouteStatistics(method, uri, statusCode, responseTimeMs);
|
|
118
|
+
}
|
|
119
|
+
const request = await captureRequest(context, config);
|
|
120
|
+
const response = captureResponse(context.response, config);
|
|
121
|
+
const log = assembleLogRecord({
|
|
122
|
+
context,
|
|
123
|
+
matched,
|
|
124
|
+
method,
|
|
125
|
+
uri,
|
|
126
|
+
rawPath,
|
|
127
|
+
statusCode,
|
|
128
|
+
responseTimeMs,
|
|
129
|
+
request,
|
|
130
|
+
response,
|
|
131
|
+
});
|
|
132
|
+
await (0, interface_database_decorators_1.GetModel)(db_1.RequestLogModel).insert(log);
|
|
133
|
+
}
|
|
134
|
+
function matchRoute(method, rawPath) {
|
|
135
|
+
const lcMethod = method.toLowerCase();
|
|
136
|
+
const pathSegs = rawPath.split("/").filter(Boolean);
|
|
137
|
+
for (const { id, handler } of (0, interface_api_1.getRegisteredRouteHandlers)()) {
|
|
138
|
+
if (handler.mode !== "handler")
|
|
139
|
+
continue;
|
|
140
|
+
if (handler.method !== "any" && handler.method.toLowerCase() !== lcMethod) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const params = matchSegments(handler.location, pathSegs);
|
|
144
|
+
if (params) {
|
|
145
|
+
return { id, location: handler.location, params };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
function matchSegments(pattern, pathSegs) {
|
|
151
|
+
const patSegs = pattern.split("/").filter(Boolean);
|
|
152
|
+
if (patSegs.length !== pathSegs.length)
|
|
153
|
+
return undefined;
|
|
154
|
+
const params = {};
|
|
155
|
+
for (let i = 0; i < patSegs.length; i++) {
|
|
156
|
+
const p = patSegs[i];
|
|
157
|
+
if (p.startsWith(":")) {
|
|
158
|
+
params[p.slice(1)] = pathSegs[i];
|
|
159
|
+
}
|
|
160
|
+
else if (p !== pathSegs[i]) {
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return params;
|
|
165
|
+
}
|
|
166
|
+
function formatError(err) {
|
|
167
|
+
if (!err)
|
|
168
|
+
return undefined;
|
|
169
|
+
if (err instanceof Error) {
|
|
170
|
+
return { message: err.message, stack: err.stack };
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
return { message: String(err) };
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return { message: "unknown error" };
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function clientIp(context) {
|
|
180
|
+
const fwd = context.rawRequest.headers["x-forwarded-for"];
|
|
181
|
+
if (typeof fwd === "string") {
|
|
182
|
+
return fwd.split(",")[0].trim();
|
|
183
|
+
}
|
|
184
|
+
if (Array.isArray(fwd) && fwd.length > 0) {
|
|
185
|
+
return fwd[0];
|
|
186
|
+
}
|
|
187
|
+
return context.rawRequest.socket.remoteAddress ?? undefined;
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=capture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture.js","sourceRoot":"","sources":["../../../src/services/request-log/capture.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6DAQmC;AACnC,gEAA6D;AAC7D,6FAAqE;AACrE,qCAAwD;AACxD,6BAA6D;AAC7D,kEAAmE;AAEnE,mCAAmC;AACnC,iCASgB;AAkBhB,MAAa,iBAAkB,SAAQ,IAAA,0BAAU,EAAC,GAAG,CAAC;IAEpD,KAAK,CAAY,OAAuB;QACtC,OAAO,CAAC,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IACzD,CAAC;IAGD,OAAO,CAAY,OAAuB;QACxC,KAAK,UAAU,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACrC,iBAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,GAAG,CAAC,CAAC;QAC9D,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAZD,8CAYC;AAVC;IADC,IAAA,sBAAM,EAAC,KAAK,EAAE,GAAG,EAAE,+BAAe,CAAC,OAAO,CAAC;IACrC,WAAA,IAAA,uBAAO,GAAE,CAAA;;;;8CAEf;AAGD;IADC,IAAA,uBAAO,EAAC,KAAK,EAAE,GAAG,EAAE,+BAAe,CAAC,MAAM,CAAC;IACnC,WAAA,IAAA,uBAAO,GAAE,CAAA;;;;gDAIjB;AAGH,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG,gBA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KAAK,EAAE,CAAC;QACzB,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC;IACpD,CAAC;IAOD,IAAI,CAAC;QAEH,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;IAClC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;IACtC,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,OAAuB;IACvC,MAAM,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC1D,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAClC,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;IAChB,CAAC;IACD,OAAO,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,aAAa,IAAI,SAAS,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.queryRequestLogsScoped = exports.getRequestLog = exports.getRecentLogsForRoute = exports.pruneRequestLogs = exports.RequestLogCapture = void 0;
|
|
4
|
+
var capture_1 = require("./capture");
|
|
5
|
+
Object.defineProperty(exports, "RequestLogCapture", { enumerable: true, get: function () { return capture_1.RequestLogCapture; } });
|
|
6
|
+
var prune_1 = require("./prune");
|
|
7
|
+
Object.defineProperty(exports, "pruneRequestLogs", { enumerable: true, get: function () { return prune_1.pruneRequestLogs; } });
|
|
8
|
+
var read_1 = require("./read");
|
|
9
|
+
Object.defineProperty(exports, "getRecentLogsForRoute", { enumerable: true, get: function () { return read_1.getRecentLogsForRoute; } });
|
|
10
|
+
Object.defineProperty(exports, "getRequestLog", { enumerable: true, get: function () { return read_1.getRequestLog; } });
|
|
11
|
+
Object.defineProperty(exports, "queryRequestLogsScoped", { enumerable: true, get: function () { return read_1.queryRequestLogsScoped; } });
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/request-log/index.ts"],"names":[],"mappings":";;;AAAA,qCAA8C;AAArC,4GAAA,iBAAiB,OAAA;AAC1B,iCAA2C;AAAlC,yGAAA,gBAAgB,OAAA;AACzB,+BAIgB;AAHd,6GAAA,qBAAqB,OAAA;AACrB,qGAAA,aAAa,OAAA;AACb,8GAAA,sBAAsB,OAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pruneRequestLogs = pruneRequestLogs;
|
|
4
|
+
const config_1 = require("@/config");
|
|
5
|
+
async function pruneRequestLogs(model) {
|
|
6
|
+
const { requestLogRetention } = (0, config_1.getConfig)();
|
|
7
|
+
const cutoff = new Date(Date.now() - requestLogRetention);
|
|
8
|
+
return model.deleteOlderThan(cutoff);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=prune.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prune.js","sourceRoot":"","sources":["../../../src/services/request-log/prune.ts"],"names":[],"mappings":";;AAMA,4CAMC;AAZD,qCAAqC;AAM9B,KAAK,UAAU,gBAAgB,CACpC,KAAsB;IAEtB,MAAM,EAAE,mBAAmB,EAAE,GAAG,IAAA,kBAAS,GAAE,CAAC;IAC5C,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,mBAAmB,CAAC,CAAC;IAC1D,OAAO,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RequestLogModel } from "@/db";
|
|
2
|
+
import type { RequestLogFilters, RequestLogPage } from "@/db/models/request_log.model";
|
|
3
|
+
import type { RequestLog } from "@/db/tables/request_log.table";
|
|
4
|
+
export declare function queryRequestLogsScoped(model: RequestLogModel, filters: RequestLogFilters, keys: Set<string> | null | undefined): Promise<RequestLogPage>;
|
|
5
|
+
export declare function getRequestLog(model: RequestLogModel, id: string): Promise<RequestLog | undefined>;
|
|
6
|
+
export declare function getRecentLogsForRoute(model: RequestLogModel, routeId: string, limit?: number): Promise<RequestLog[]>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.queryRequestLogsScoped = queryRequestLogsScoped;
|
|
4
|
+
exports.getRequestLog = getRequestLog;
|
|
5
|
+
exports.getRecentLogsForRoute = getRecentLogsForRoute;
|
|
6
|
+
const types_1 = require("@/types");
|
|
7
|
+
const UNBOUNDED_SCAN_FLOOR_MS = 30 * types_1.MS_PER_DAY;
|
|
8
|
+
function queryRequestLogsScoped(model, filters, keys) {
|
|
9
|
+
if (!keys)
|
|
10
|
+
return model.query(filters);
|
|
11
|
+
if (keys.size === 0)
|
|
12
|
+
return Promise.resolve({ results: [], nextCursor: null });
|
|
13
|
+
return model.query({
|
|
14
|
+
since: new Date(Date.now() - UNBOUNDED_SCAN_FLOOR_MS),
|
|
15
|
+
...filters,
|
|
16
|
+
routeKeys: [...keys],
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async function getRequestLog(model, id) {
|
|
20
|
+
return model.get(id);
|
|
21
|
+
}
|
|
22
|
+
async function getRecentLogsForRoute(model, routeId, limit = 20) {
|
|
23
|
+
const page = await model.query({ routeId, limit });
|
|
24
|
+
return page.results;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=read.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../../src/services/request-log/read.ts"],"names":[],"mappings":";;AA8BA,wDAsBC;AAED,sCAKC;AAMD,sDAOC;AAlED,mCAAqC;AAQrC,MAAM,uBAAuB,GAAG,EAAE,GAAG,kBAAU,CAAC;AAgBhD,SAAgB,sBAAsB,CACpC,KAAsB,EACtB,OAA0B,EAC1B,IAAoC;IAEpC,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAKvC,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC;QACjB,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5D,OAAO,KAAK,CAAC,KAAK,CAAC;QAMjB,KAAK,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,uBAAuB,CAAC;QACrD,GAAG,OAAO;QACV,SAAS,EAAE,CAAC,GAAG,IAAI,CAAC;KACrB,CAAC,CAAC;AACL,CAAC;AAEM,KAAK,UAAU,aAAa,CACjC,KAAsB,EACtB,EAAU;IAEV,OAAO,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AACvB,CAAC;AAMM,KAAK,UAAU,qBAAqB,CACzC,KAAsB,EACtB,OAAe,EACf,KAAK,GAAG,EAAE;IAEV,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IACnD,OAAO,IAAI,CAAC,OAAO,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function isSensitiveKey(key: string): boolean;
|
|
2
|
+
export declare function redactValue(value: unknown, depth?: number): unknown;
|
|
3
|
+
export declare function redactSearchParams(params: URLSearchParams): URLSearchParams;
|
|
4
|
+
export declare function sanitizeBody(body: unknown, contentType: string): string | undefined;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSensitiveKey = isSensitiveKey;
|
|
4
|
+
exports.redactValue = redactValue;
|
|
5
|
+
exports.redactSearchParams = redactSearchParams;
|
|
6
|
+
exports.sanitizeBody = sanitizeBody;
|
|
7
|
+
const REDACTED = "[REDACTED]";
|
|
8
|
+
const MAX_REDACTION_DEPTH = 32;
|
|
9
|
+
const SENSITIVE_KEY = /password|passwd|secret|token|authorization|cookie|apikey|privatekey|credential|otp|recoverycode|backupcode/;
|
|
10
|
+
function isSensitiveKey(key) {
|
|
11
|
+
return SENSITIVE_KEY.test(key.toLowerCase().replace(/[^a-z0-9]/g, ""));
|
|
12
|
+
}
|
|
13
|
+
function redactValue(value, depth = 0) {
|
|
14
|
+
if (depth >= MAX_REDACTION_DEPTH)
|
|
15
|
+
return REDACTED;
|
|
16
|
+
if (Array.isArray(value)) {
|
|
17
|
+
return value.map((item) => redactValue(item, depth + 1));
|
|
18
|
+
}
|
|
19
|
+
if (value === null || typeof value !== "object")
|
|
20
|
+
return value;
|
|
21
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [
|
|
22
|
+
key,
|
|
23
|
+
isSensitiveKey(key) ? REDACTED : redactValue(item, depth + 1),
|
|
24
|
+
]));
|
|
25
|
+
}
|
|
26
|
+
function redactSearchParams(params) {
|
|
27
|
+
return new URLSearchParams([...params].map(([key, value]) => [
|
|
28
|
+
key,
|
|
29
|
+
isSensitiveKey(key) ? REDACTED : value,
|
|
30
|
+
]));
|
|
31
|
+
}
|
|
32
|
+
function sanitizeBody(body, contentType) {
|
|
33
|
+
const mediaType = contentType.split(";")[0].trim().toLowerCase();
|
|
34
|
+
const text = Buffer.isBuffer(body) ? body.toString("utf8") : body;
|
|
35
|
+
try {
|
|
36
|
+
if (mediaType === "application/x-www-form-urlencoded") {
|
|
37
|
+
if (typeof text !== "string")
|
|
38
|
+
return undefined;
|
|
39
|
+
return redactSearchParams(new URLSearchParams(text)).toString();
|
|
40
|
+
}
|
|
41
|
+
if (mediaType !== "application/json" && !mediaType.endsWith("+json")) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const parsed = typeof text === "string" ? JSON.parse(text) : text;
|
|
45
|
+
if (parsed === null || typeof parsed !== "object")
|
|
46
|
+
return undefined;
|
|
47
|
+
return JSON.stringify(redactValue(parsed));
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=redaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redaction.js","sourceRoot":"","sources":["../../../src/services/request-log/redaction.ts"],"names":[],"mappings":";;AAMA,wCAEC;AAGD,kCAYC;AAGD,gDAOC;AAGD,oCAoBC;AAxDD,MAAM,QAAQ,GAAG,YAAY,CAAC;AAC9B,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,MAAM,aAAa,GACjB,4GAA4G,CAAC;AAG/G,SAAgB,cAAc,CAAC,GAAW;IACxC,OAAO,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,CAAC;AACzE,CAAC;AAGD,SAAgB,WAAW,CAAC,KAAc,EAAE,KAAK,GAAG,CAAC;IACnD,IAAI,KAAK,IAAI,mBAAmB;QAAE,OAAO,QAAQ,CAAC;IAClD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;IAC3D,CAAC;IACD,IAAI,KAAK,KAAK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IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YACrE,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,MAAM,GAAY,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC3E,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ;YAAE,OAAO,SAAS,CAAC;QACpE,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IncomingHttpHeaders } from "node:http";
|
|
2
|
+
export declare function pickHeaders(headers: IncomingHttpHeaders | Record<string, string | string[] | undefined>, allowList: ReadonlyArray<string>): Record<string, string>;
|
|
3
|
+
export declare function contentTypeIsText(contentType?: string): boolean;
|
|
4
|
+
export interface CapturedBody {
|
|
5
|
+
body?: string;
|
|
6
|
+
truncated: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function captureBody(body: unknown, contentType: string | undefined, maxBytes: number): CapturedBody;
|
|
9
|
+
export declare function queryToRecord(url: URL): Record<string, string | string[]>;
|
|
10
|
+
export declare function extractStatusCode(value: unknown): number;
|
|
11
|
+
export declare function extractBody(value: unknown): unknown;
|
|
12
|
+
export declare function extractContentType(value: unknown): string | undefined;
|
|
13
|
+
export declare function extractHeaders(value: unknown): Record<string, string>;
|