Skip to content

Commit

Permalink
Update SDK Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
caidobot committed Dec 19, 2024
1 parent 6f4596d commit a4ddedc
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 65 deletions.
101 changes: 66 additions & 35 deletions src/reference/sdks/backend/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# @caido/sdk-backend

This is the reference for the backend SDK used by backend plugins.
[SDK](#events) is the main interface that provides access to various services and functionalities.
[SDK](#sdk-api-events) is the main interface that provides access to various services and functionalities.

## SDK

Expand Down Expand Up @@ -190,7 +190,7 @@ This callback is called asynchronously and cannot modify requests.

| Parameter | Type |
| ------ | ------ |
| `callback` | (`sdk`: [`SDK`](index.md#sdkapi-events)\<`API`, `Events`\>, `request`: [`Request`](index.md#request-2)) => [`MaybePromise`](index.md#maybepromiset-1)\<`void`\> |
| `callback` | (`sdk`: [`SDK`](index.md#sdkapi-events)\<`API`, `Events`\>, `request`: [`Request`](index.md#request-1)) => [`MaybePromise`](index.md#maybepromiset-1)\<`void`\> |

###### Returns

Expand All @@ -214,7 +214,7 @@ This callback is called asynchronously and cannot modify responses.

| Parameter | Type |
| ------ | ------ |
| `callback` | (`sdk`: [`SDK`](index.md#sdkapi-events)\<`API`, `Events`\>, `request`: [`Request`](index.md#request-2), `response`: [`Response`](index.md#response-3)) => [`MaybePromise`](index.md#maybepromiset-1)\<`void`\> |
| `callback` | (`sdk`: [`SDK`](index.md#sdkapi-events)\<`API`, `Events`\>, `request`: [`Request`](index.md#request-1), `response`: [`Response`](index.md#response-3)) => [`MaybePromise`](index.md#maybepromiset-1)\<`void`\> |

###### Returns

Expand Down Expand Up @@ -260,7 +260,7 @@ sdk.events.onProjectChange((sdk, project) => {

### Body

The body of a [Request](index.md#request-2) or [Response](index.md#response-3).
The body of a [Request](index.md#request-1) or [Response](index.md#response-3).

Calling `to<FORMAT>` will try to convert the body to the desired format.

Expand Down Expand Up @@ -330,12 +330,12 @@ A mutable Request that has not yet been sent.

> **new RequestSpec**(`url`: `string`): [`RequestSpec`](index.md#requestspec)
Build a new [RequestSpec](index.md#requestspec) from a URL string. Only the host, port and scheme will be parsed.
Build a new [RequestSpec](index.md#requestspec) from a URL string.
We try to infer as much information as possible from the URL, including the scheme, host, path and query.

You can convert a saved immutable [Request](index.md#request-2) object into a [RequestSpec](index.md#requestspec) object by using the `toSpec()` method.
You can convert a saved immutable [Request](index.md#request-1) object into a [RequestSpec](index.md#requestspec) object by using the `toSpec()` method.

By default:

- Method is `GET`.
- Path is `/`.

Expand Down Expand Up @@ -791,7 +791,7 @@ A mutable raw Request that has not yet been sent.
Build a new [RequestSpecRaw](index.md#requestspecraw) from a URL string. Only the host, port and scheme will be parsed.

You can convert a saved immutable [Request](index.md#request-2) object into a [RequestSpecRaw](index.md#requestspecraw) object by using the `toSpecRaw()` method.
You can convert a saved immutable [Request](index.md#request-1) object into a [RequestSpecRaw](index.md#requestspecraw) object by using the `toSpecRaw()` method.

You MUST use `setRaw` to set the raw bytes of the request.

Expand Down Expand Up @@ -1129,7 +1129,7 @@ An immutable saved Request and Response pair.

##### request

> **request**: [`Request`](index.md#request-2)
> **request**: [`Request`](index.md#request-1)
##### response

Expand All @@ -1147,7 +1147,7 @@ An immutable saved Request and optional Response pair.

##### request

> **request**: [`Request`](index.md#request-2)
> **request**: [`Request`](index.md#request-1)
##### response?

Expand Down Expand Up @@ -1187,7 +1187,7 @@ An item in a connection of requests.
##### request

> **request**: [`Request`](index.md#request-2)
> **request**: [`Request`](index.md#request-1)
##### response?

Expand Down Expand Up @@ -1383,7 +1383,7 @@ Checks if a request is in scope.

| Parameter | Type |
| ------ | ------ |
| `request` | [`Request`](index.md#request-2) \| [`RequestSpec`](index.md#requestspec) |
| `request` | [`Request`](index.md#request-1) \| [`RequestSpec`](index.md#requestspec) |

###### Returns

Expand All @@ -1406,7 +1406,7 @@ Checks if a request/response matches an HTTPQL filter.
| Parameter | Type | Description |
| ------ | ------ | ------ |
| `filter` | `string` | HTTPQL filter |
| `request` | [`Request`](index.md#request-2) | The [Request](index.md#request-2) to match against |
| `request` | [`Request`](index.md#request-1) | The [Request](index.md#request-1) to match against |
| `response`? | [`Response`](index.md#response-3) | The [Response](index.md#response-3) to match against |

###### Returns
Expand Down Expand Up @@ -1618,6 +1618,20 @@ true

## Findings

### DedupeKey

> **DedupeKey**: `string` & `object`
A deduplication key.

#### Type declaration

##### \_\_dedupeKey?

> `optional` **\_\_dedupeKey**: `never`
***

### Finding

> **Finding**: `object`
Expand All @@ -1626,6 +1640,14 @@ A saved immutable Finding.

#### Type declaration

##### getDedupeKey()

The deduplication key of the finding.

###### Returns

`undefined` \| [`DedupeKey`](index.md#dedupekey)

##### getDescription()

The description of the finding.
Expand Down Expand Up @@ -1670,7 +1692,7 @@ A mutable Finding not yet created.

##### dedupeKey?

> `optional` **dedupeKey**: `string`
> `optional` **dedupeKey**: [`DedupeKey`](index.md#dedupekey)
Deduplication key for findings.
If a finding with the same dedupe key already exists, it will not be created.
Expand All @@ -1690,9 +1712,9 @@ It will be used to group findings.

##### request

> **request**: [`Request`](index.md#request-2)
> **request**: [`Request`](index.md#request-1)
The associated [Request](index.md#request-2).
The associated [Request](index.md#request-1).

##### title

Expand Down Expand Up @@ -1735,17 +1757,41 @@ await sdk.findings.create({
title: "Title",
description: "Description",
reporter: "Reporter",
dedupe: `${request.getHost()}-${request.getPath()}`,
dedupeKey: `${request.getHost()}-${request.getPath()}`,
request,
});
```

##### exists()

Check if a [Finding](index.md#finding) exists.
Similar to `get`, but returns a boolean.

###### Parameters

| Parameter | Type |
| ------ | ------ |
| `input` | [`GetFindingInput`](index.md#getfindinginput) |

###### Returns

`Promise`\<`boolean`\>

###### Example

```js
await sdk.findings.exists("my-dedupe-key");
```

##### get()

Try to get a [Finding](index.md#finding) for a request.

Since a request can have multiple findings, this will return the first one found.
You can also filter by reporter to get a specific finding.

Finally, you can use a deduplication key to get a specific finding.

###### Parameters

| Parameter | Type |
Expand All @@ -1769,24 +1815,10 @@ await sdk.findings.get({

### GetFindingInput

> **GetFindingInput**: `object`
> **GetFindingInput**: [`DedupeKey`](index.md#dedupekey) \| `object`
Input to get a [Finding](index.md#finding).

#### Type declaration

##### reporter?

> `optional` **reporter**: `string`
The name of the reporter.

##### request

> **request**: [`Request`](index.md#request-2)
The associated [Request](index.md#request-2).

## Replay

### ReplayCollection
Expand Down Expand Up @@ -2111,7 +2143,7 @@ Option to return raw value

### RequestSource

> **RequestSource**: [`ID`](index.md#id) \| [`Request`](index.md#request-2) \| [`RequestSpec`](index.md#requestspec) \| [`RequestSpecRaw`](index.md#requestspecraw)
> **RequestSource**: [`ID`](index.md#id) \| [`Request`](index.md#request-1) \| [`RequestSpec`](index.md#requestspec) \| [`RequestSpecRaw`](index.md#requestspecraw)
The source of a request.

Expand Down Expand Up @@ -2156,7 +2188,6 @@ Each connection will be spawned in a worker thread.
const db = await open({ filename: "path/to/database.sqlite" });
await db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT);");
await db.exec("INSERT INTO test (name) VALUES ('foo');");
```

#### Constructors

Expand Down Expand Up @@ -2295,7 +2326,7 @@ The prepared statement [parameters are bound](https://www.sqlite.org/c3ref/bind_
Console interface for logging.

Currently logs are only available in the backend logs.
See [https://docs.caido.io/report_bug.html#1-backend-logs](https://docs.caido.io/report_bug.html#1-backend-logs)
See https://docs.caido.io/report_bug.html#1-backend-logs

#### Type declaration

Expand Down
Loading

0 comments on commit a4ddedc

Please sign in to comment.