@caido-utils/backend 0.3.0 → 0.5.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/index.d.ts CHANGED
@@ -2,4 +2,7 @@ export { Fetch, type FetchOptions } from "./fetcher";
2
2
  export { createSignal, pausePool, resumePool, runPool, stopPool } from "./pool";
3
3
  export type { PoolCallbacks, PoolConfig, PoolSignal } from "./pool";
4
4
  export { spawnCommand } from "./process";
5
+ export { getProjectId } from "./project";
6
+ export { queryRequests } from "./requests";
7
+ export type { QueryRequestsOptions } from "./requests";
5
8
  export { fileExists, readFile, storeFile } from "./storage";
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  export { Fetch } from "./fetcher.js";
2
2
  export { createSignal, pausePool, resumePool, runPool, stopPool } from "./pool.js";
3
3
  export { spawnCommand } from "./process.js";
4
+ export { getProjectId } from "./project.js";
5
+ export { queryRequests } from "./requests.js";
4
6
  export { fileExists, readFile, storeFile } from "./storage.js";
@@ -0,0 +1,2 @@
1
+ import type { SDK } from "caido:plugin";
2
+ export declare function getProjectId(sdk: SDK): Promise<string>;
@@ -0,0 +1,8 @@
1
+ export async function getProjectId(sdk) {
2
+ const project = await sdk.projects.getCurrent();
3
+ const projectId = project?.getId().toString();
4
+ if (projectId === void 0) {
5
+ throw new Error("Project not found");
6
+ }
7
+ return projectId;
8
+ }
@@ -0,0 +1,12 @@
1
+ import type { SDK } from "caido:plugin";
2
+ import type { RequestsConnectionItem } from "caido:utils";
3
+ export type QueryRequestsOptions = {
4
+ filter?: string;
5
+ pageSize?: number;
6
+ onPage?: (items: RequestsConnectionItem[]) => void;
7
+ };
8
+ /**
9
+ * Paginated query over all requests matching a filter.
10
+ * Yields items in ascending order by creation date.
11
+ */
12
+ export declare function queryRequests(sdk: SDK, options?: QueryRequestsOptions): Promise<RequestsConnectionItem[]>;
@@ -0,0 +1,25 @@
1
+ export async function queryRequests(sdk, options) {
2
+ const pageSize = options?.pageSize ?? 1e3;
3
+ const results = [];
4
+ let cursor = void 0;
5
+ while (true) {
6
+ let query = sdk.requests.query().first(pageSize).ascending("req", "created_at");
7
+ if (options?.filter) {
8
+ query = query.filter(options.filter);
9
+ }
10
+ if (cursor !== void 0) {
11
+ query = query.after(cursor);
12
+ }
13
+ const page = await query.execute();
14
+ if (page.items.length > 0) {
15
+ results.push(...page.items);
16
+ options?.onPage?.(page.items);
17
+ }
18
+ if (page.pageInfo.hasNextPage) {
19
+ cursor = page.pageInfo.endCursor;
20
+ } else {
21
+ break;
22
+ }
23
+ }
24
+ return results;
25
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caido-utils/backend",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"