@caido-utils/backend 1.1.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.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Resolves custom `filter:` tokens in a query into real HTTPQL.
3
+ * e.g. `filter:1hr` → `req.created_at.gt:"2026-02-17 14:00:00"`
4
+ * `filter:inscope` → `preset:inscope`
5
+ */
6
+ export declare function resolveFilterQuery(query: string): string;
@@ -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
@@ -1,4 +1,5 @@
1
1
  export { sha256 } from "./crypto";
2
+ export { resolveFilterQuery } from "./filter";
2
3
  export { Queue } from "./pool";
3
4
  export type { PoolCallbacks, PoolConfig } from "./pool";
4
5
  export { spawnCommand } from "./process";
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { sha256 } from "./crypto/index.js";
2
+ export { resolveFilterQuery } from "./filter/index.js";
2
3
  export { Queue } from "./pool/index.js";
3
4
  export { spawnCommand } from "./process/index.js";
4
5
  export { getProjectId } from "./project/index.js";
@@ -5,6 +5,7 @@ export type QueryRequestsOptions = {
5
5
  pageSize?: number;
6
6
  excludeStaticAssets?: boolean;
7
7
  deduplicate?: boolean;
8
+ inScope?: boolean;
8
9
  onPage?: (items: RequestsConnectionItem[]) => void;
9
10
  };
10
11
  /**
@@ -85,8 +85,14 @@ export async function queryRequests(sdk, options) {
85
85
  }
86
86
  const page = await query.execute();
87
87
  if (page.items.length > 0) {
88
- results.push(...page.items);
89
- options?.onPage?.(page.items);
88
+ let items = page.items;
89
+ if (options?.inScope) {
90
+ items = items.filter((item) => sdk.requests.inScope(item.request));
91
+ }
92
+ if (items.length > 0) {
93
+ results.push(...items);
94
+ options?.onPage?.(items);
95
+ }
90
96
  }
91
97
  if (page.pageInfo.hasNextPage) {
92
98
  cursor = page.pageInfo.endCursor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caido-utils/backend",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"