@caido-utils/backend 1.2.0 → 1.3.0
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/dist/filter/index.d.ts +6 -0
- package/dist/filter/index.js +29 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const TIME_FILTERS = {
|
|
2
|
+
recent: 15 * 60 * 1e3,
|
|
3
|
+
"1hr": 60 * 60 * 1e3,
|
|
4
|
+
"6hr": 6 * 60 * 60 * 1e3,
|
|
5
|
+
"12hr": 12 * 60 * 60 * 1e3,
|
|
6
|
+
"24hr": 24 * 60 * 60 * 1e3
|
|
7
|
+
};
|
|
8
|
+
function formatDateTime(date) {
|
|
9
|
+
const y = date.getFullYear();
|
|
10
|
+
const mo = String(date.getMonth() + 1).padStart(2, "0");
|
|
11
|
+
const d = String(date.getDate()).padStart(2, "0");
|
|
12
|
+
const h = String(date.getHours()).padStart(2, "0");
|
|
13
|
+
const mi = String(date.getMinutes()).padStart(2, "0");
|
|
14
|
+
const s = String(date.getSeconds()).padStart(2, "0");
|
|
15
|
+
return `${y}-${mo}-${d} ${h}:${mi}:${s}`;
|
|
16
|
+
}
|
|
17
|
+
export function resolveFilterQuery(query) {
|
|
18
|
+
return query.replace(/filter:(\w+)/g, (_, value) => {
|
|
19
|
+
const ms = TIME_FILTERS[value];
|
|
20
|
+
if (ms !== void 0) {
|
|
21
|
+
const cutoff = new Date(Date.now() - ms);
|
|
22
|
+
return `req.created_at.gt:"${formatDateTime(cutoff)}"`;
|
|
23
|
+
}
|
|
24
|
+
if (value === "inscope") {
|
|
25
|
+
return "preset:inscope";
|
|
26
|
+
}
|
|
27
|
+
return "";
|
|
28
|
+
}).replace(/\s{2,}/g, " ").trim();
|
|
29
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED