@caido/sdk-backend 0.1.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/LICENSE +21 -0
- package/README.md +29 -0
- package/package.json +11 -0
- package/src/index.d.ts +3 -0
- package/src/types/common.d.ts +196 -0
- package/src/types/runtime.d.ts +147 -0
- package/src/types/typing.d.ts +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Caido
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img width="1000" alt="image" src="https://user-images.githubusercontent.com/6225588/211916659-567751d1-0225-402b-9141-4145c18b0834.png">
|
|
3
|
+
|
|
4
|
+
<br />
|
|
5
|
+
<br />
|
|
6
|
+
<a href="https://caido.io/">Website</a>
|
|
7
|
+
<span> • </span>
|
|
8
|
+
<a href="https://dashboard.caido.io/">Dashboard</a>
|
|
9
|
+
<span> • </span>
|
|
10
|
+
<a href="https://docs.caido.io/" target="_blank">Docs</a>
|
|
11
|
+
<span> • </span>
|
|
12
|
+
<a href="https://links.caido.io/roadmap">Roadmap</a>
|
|
13
|
+
<span> • </span>
|
|
14
|
+
<a href="https://github.com/caido/caido/tree/main/brand">Branding</a>
|
|
15
|
+
<span> • </span>
|
|
16
|
+
<a href="https://links.caido.io/www-discord" target="_blank">Discord</a>
|
|
17
|
+
<br />
|
|
18
|
+
<hr />
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
## 👋 Backend SDK
|
|
22
|
+
|
|
23
|
+
[](https://www.npmjs.com/package/@caido/sdk-backend)
|
|
24
|
+
|
|
25
|
+
This is repository for the Caido backend SDK. Head over to the [starter kit](https://github.com/caido/starterkit-plugin) to view it in action.
|
|
26
|
+
|
|
27
|
+
## 💚 Community
|
|
28
|
+
|
|
29
|
+
Come join our [Discord](https://links.caido.io/www-discord) community and connect with other Caido users! We'd love to have you as part of the conversation and help with any questions you may have.
|
package/package.json
ADDED
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
declare module "caido:common" {
|
|
2
|
+
/**
|
|
3
|
+
* The body of a Request or Response.
|
|
4
|
+
*
|
|
5
|
+
* Calling `to<FORMAT>` will try to convert the body to the desired format.
|
|
6
|
+
*/
|
|
7
|
+
export class Body {
|
|
8
|
+
constructor(data: string | Array<number> | Uint8Array);
|
|
9
|
+
/**
|
|
10
|
+
* Parse the body as a string.
|
|
11
|
+
*
|
|
12
|
+
* Unprintable characters will be replaced with `�`.
|
|
13
|
+
*/
|
|
14
|
+
toText(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Try to parse the body as JSON.
|
|
17
|
+
*
|
|
18
|
+
* @throws {SyntaxError} If the body is not valid JSON.
|
|
19
|
+
*/
|
|
20
|
+
toJson(): any;
|
|
21
|
+
/**
|
|
22
|
+
* Get the raw body as an array of bytes.
|
|
23
|
+
*/
|
|
24
|
+
toRaw(): Uint8Array;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A saved immutable Request.
|
|
29
|
+
*
|
|
30
|
+
* To modify, use `toSpec` to get a `RequestSpec` object.
|
|
31
|
+
*/
|
|
32
|
+
export type Request = {
|
|
33
|
+
getId(): ID;
|
|
34
|
+
getHost(): string;
|
|
35
|
+
getPort(): number;
|
|
36
|
+
getTls(): boolean;
|
|
37
|
+
getMethod(): string;
|
|
38
|
+
getPath(): string;
|
|
39
|
+
getQuery(): string;
|
|
40
|
+
getHeaders(): Record<string, Array<string>>;
|
|
41
|
+
getHeader(name: string): Array<string> | undefined;
|
|
42
|
+
getBody(): Body | undefined;
|
|
43
|
+
toSpec(): RequestSpec;
|
|
44
|
+
toSpecRaw(): RequestSpecRaw;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type SetBodyOptions = {
|
|
48
|
+
/**
|
|
49
|
+
* Should update the Content-export type header.
|
|
50
|
+
*
|
|
51
|
+
* @default true
|
|
52
|
+
*/
|
|
53
|
+
updateContentLength: boolean;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A mutable Request not yet sent.
|
|
58
|
+
*/
|
|
59
|
+
export class RequestSpec {
|
|
60
|
+
constructor(url: string);
|
|
61
|
+
getHost(): string;
|
|
62
|
+
setHost(host: string): void;
|
|
63
|
+
getPort(): number;
|
|
64
|
+
setPort(port: number): void;
|
|
65
|
+
getTls(): boolean;
|
|
66
|
+
setTls(tls: boolean): void;
|
|
67
|
+
getMethod(): string;
|
|
68
|
+
setMethod(method: string): void;
|
|
69
|
+
getPath(): string;
|
|
70
|
+
setPath(path: string): void;
|
|
71
|
+
getQuery(): string;
|
|
72
|
+
setQuery(query: string): void;
|
|
73
|
+
getHeaders(): Record<string, Array<string>>;
|
|
74
|
+
getHeader(name: string): Array<string> | undefined;
|
|
75
|
+
setHeader(name: string, value: string): void;
|
|
76
|
+
removeHeader(name: string): void;
|
|
77
|
+
getBody(): Body | undefined;
|
|
78
|
+
setBody(body: Body | Bytes, options?: SetBodyOptions): void;
|
|
79
|
+
setRaw(raw: Bytes): RequestSpecRaw;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A mutable raw Request not yet sent.
|
|
84
|
+
*/
|
|
85
|
+
export class RequestSpecRaw {
|
|
86
|
+
constructor(url: string);
|
|
87
|
+
getHost(): string;
|
|
88
|
+
setHost(host: string): void;
|
|
89
|
+
getPort(): number;
|
|
90
|
+
setPort(port: number): void;
|
|
91
|
+
getTls(): boolean;
|
|
92
|
+
setTls(tls: boolean): void;
|
|
93
|
+
getRaw(): Uint8Array;
|
|
94
|
+
setRaw(raw: Bytes): void;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* An immutable saved Response.
|
|
99
|
+
*/
|
|
100
|
+
export type Response = {
|
|
101
|
+
getId(): ID;
|
|
102
|
+
getCode(): number;
|
|
103
|
+
getHeaders(): Record<string, Array<string>>;
|
|
104
|
+
getHeader(name: string): Array<string> | undefined;
|
|
105
|
+
getBody(): Body | undefined;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* An immutable saved Request and Response pair.
|
|
110
|
+
*/
|
|
111
|
+
export type RequestResponse = {
|
|
112
|
+
request: Request;
|
|
113
|
+
response: Response;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The SDK for the Requests service.
|
|
118
|
+
*/
|
|
119
|
+
export type RequestsSDK = {
|
|
120
|
+
/**
|
|
121
|
+
* Sends a request.
|
|
122
|
+
*
|
|
123
|
+
* This respects the upstream proxy settings.
|
|
124
|
+
*
|
|
125
|
+
* @throws {Error} If the request cannot be sent.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* const spec = new RequestSpec("https://example.com");
|
|
129
|
+
* sdk.requests.send(request)
|
|
130
|
+
* .then((res) => {
|
|
131
|
+
* console.log(res.request.getId());
|
|
132
|
+
* console.log(res.response.getCode());
|
|
133
|
+
* })
|
|
134
|
+
* .catch((err) => {
|
|
135
|
+
* console.error(err);
|
|
136
|
+
* });
|
|
137
|
+
*/
|
|
138
|
+
send(request: RequestSpec | RequestSpecRaw): Promise<RequestResponse>;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Checks if a request is in scope.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* if (sdk.requests.inScope(request)) {
|
|
145
|
+
* console.log("In scope");
|
|
146
|
+
* }
|
|
147
|
+
*/
|
|
148
|
+
inScope(request: Request | RequestSpec): boolean;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* A saved immutable Finding.
|
|
153
|
+
*
|
|
154
|
+
* To modify, use `toSpec` to get a `FindingSpec` object.
|
|
155
|
+
*/
|
|
156
|
+
export type Finding = {
|
|
157
|
+
getId(): ID;
|
|
158
|
+
getTitle(): string;
|
|
159
|
+
getDescription(): string | undefined;
|
|
160
|
+
getReporter(): string;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* A mutable Finding not yet created.
|
|
165
|
+
*/
|
|
166
|
+
export type FindingSpec = {
|
|
167
|
+
title: string;
|
|
168
|
+
description?: string | undefined;
|
|
169
|
+
reporter: string;
|
|
170
|
+
request: Request;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The SDK for the Findings service.
|
|
175
|
+
*/
|
|
176
|
+
export type FindingsSDK = {
|
|
177
|
+
/**
|
|
178
|
+
* Creates a new Finding.
|
|
179
|
+
*
|
|
180
|
+
* @throws {Error} If the request cannot be saved.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* sdk.findings.create({
|
|
184
|
+
* title: "Title",
|
|
185
|
+
* description: "Description",
|
|
186
|
+
* reporter: "Reporter",
|
|
187
|
+
* request,
|
|
188
|
+
* });
|
|
189
|
+
*/
|
|
190
|
+
create(spec: FindingSpec): Promise<Finding>;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
export type ID = string;
|
|
194
|
+
export type Bytes = string | Array<number> | Uint8Array;
|
|
195
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
196
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
/**
|
|
3
|
+
* Console interface for logging.
|
|
4
|
+
*
|
|
5
|
+
* Currently logs are only available in the backend logs.
|
|
6
|
+
* See https://docs.caido.io/report_bug.html#1-backend-logs
|
|
7
|
+
*/
|
|
8
|
+
type Console = {
|
|
9
|
+
debug(message: any): void;
|
|
10
|
+
log(message: any): void;
|
|
11
|
+
warn(message: any): void;
|
|
12
|
+
error(message: any): void;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The URLSearchParams interface defines utility methods to work with the query string of a URL.
|
|
17
|
+
*/
|
|
18
|
+
class URLSearchParams implements Iterable<[string, string]> {
|
|
19
|
+
constructor(
|
|
20
|
+
init?:
|
|
21
|
+
| URLSearchParams
|
|
22
|
+
| string
|
|
23
|
+
| { readonly [name: string]: string }
|
|
24
|
+
| Iterable<readonly [name: string, value: string]>
|
|
25
|
+
| ReadonlyArray<readonly [name: string, value: string]>,
|
|
26
|
+
);
|
|
27
|
+
/**
|
|
28
|
+
* Append a new name-value pair to the query string.
|
|
29
|
+
*/
|
|
30
|
+
append(name: string, value: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* If `value` is provided, removes all name-value pairs
|
|
33
|
+
* where name is `name` and value is `value`.
|
|
34
|
+
*
|
|
35
|
+
* If `value` is not provided, removes all name-value pairs whose name is `name`.
|
|
36
|
+
*/
|
|
37
|
+
delete(name: string, value?: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Returns an ES6 `Iterator` over each of the name-value pairs in the query.
|
|
40
|
+
* Each item of the iterator is a JavaScript `Array`. The first item of the `Array` is the `name`, the second item of the `Array` is the `value`.
|
|
41
|
+
*
|
|
42
|
+
* Alias for `urlSearchParams[@@iterator]()`.
|
|
43
|
+
*/
|
|
44
|
+
entries(): IterableIterator<[string, string]>;
|
|
45
|
+
/**
|
|
46
|
+
* Iterates over each name-value pair in the query and invokes the given function.
|
|
47
|
+
*
|
|
48
|
+
* ```js
|
|
49
|
+
* const myURL = new URL('https://example.org/?a=b&c=d');
|
|
50
|
+
* myURL.searchParams.forEach((value, name) => {
|
|
51
|
+
* console.log(name, value);
|
|
52
|
+
* });
|
|
53
|
+
* // Prints:
|
|
54
|
+
* // a b
|
|
55
|
+
* // c d
|
|
56
|
+
* ```
|
|
57
|
+
* @param fn Invoked for each name-value pair in the query
|
|
58
|
+
*/
|
|
59
|
+
forEach(fn: (value: string, name: string) => void): void;
|
|
60
|
+
/**
|
|
61
|
+
* Returns the value of the first name-value pair whose name is `name`. If there
|
|
62
|
+
* are no such pairs, `null` is returned.
|
|
63
|
+
* @return or `null` if there is no name-value pair with the given `name`.
|
|
64
|
+
*/
|
|
65
|
+
get(name: string): string | null;
|
|
66
|
+
/**
|
|
67
|
+
* Returns the values of all name-value pairs whose name is `name`. If there are
|
|
68
|
+
* no such pairs, an empty array is returned.
|
|
69
|
+
*/
|
|
70
|
+
getAll(name: string): string[];
|
|
71
|
+
/**
|
|
72
|
+
* Checks if the `URLSearchParams` object contains key-value pair(s) based on `name` and an optional `value` argument.
|
|
73
|
+
*
|
|
74
|
+
* If `value` is provided, returns `true` when name-value pair with
|
|
75
|
+
* same `name` and `value` exists.
|
|
76
|
+
*
|
|
77
|
+
* If `value` is not provided, returns `true` if there is at least one name-value
|
|
78
|
+
* pair whose name is `name`.
|
|
79
|
+
*/
|
|
80
|
+
has(name: string, value?: string): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Returns an ES6 `Iterator` over the names of each name-value pair.
|
|
83
|
+
*
|
|
84
|
+
* ```js
|
|
85
|
+
* const params = new URLSearchParams('foo=bar&foo=baz');
|
|
86
|
+
* for (const name of params.keys()) {
|
|
87
|
+
* console.log(name);
|
|
88
|
+
* }
|
|
89
|
+
* // Prints:
|
|
90
|
+
* // foo
|
|
91
|
+
* // foo
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
keys(): IterableIterator<string>;
|
|
95
|
+
/**
|
|
96
|
+
* Sets the value in the `URLSearchParams` object associated with `name` to `value`. If there are any pre-existing name-value pairs whose names are `name`,
|
|
97
|
+
* set the first such pair's value to `value` and remove all others. If not,
|
|
98
|
+
* append the name-value pair to the query string.
|
|
99
|
+
*
|
|
100
|
+
* ```js
|
|
101
|
+
* const params = new URLSearchParams();
|
|
102
|
+
* params.append('foo', 'bar');
|
|
103
|
+
* params.append('foo', 'baz');
|
|
104
|
+
* params.append('abc', 'def');
|
|
105
|
+
* console.log(params.toString());
|
|
106
|
+
* // Prints foo=bar&foo=baz&abc=def
|
|
107
|
+
*
|
|
108
|
+
* params.set('foo', 'def');
|
|
109
|
+
* params.set('xyz', 'opq');
|
|
110
|
+
* console.log(params.toString());
|
|
111
|
+
* // Prints foo=def&abc=def&xyz=opq
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
set(name: string, value: string): void;
|
|
115
|
+
/**
|
|
116
|
+
* The total number of parameter entries.
|
|
117
|
+
*/
|
|
118
|
+
readonly size: number;
|
|
119
|
+
/**
|
|
120
|
+
* Sort all existing name-value pairs in-place by their names. Sorting is done
|
|
121
|
+
* with a [stable sorting algorithm](https://en.wikipedia.org/wiki/Sorting_algorithm#Stability), so relative order between name-value pairs
|
|
122
|
+
* with the same name is preserved.
|
|
123
|
+
*
|
|
124
|
+
* This method can be used, in particular, to increase cache hits.
|
|
125
|
+
*
|
|
126
|
+
* ```js
|
|
127
|
+
* const params = new URLSearchParams('query[]=abc&type=search&query[]=123');
|
|
128
|
+
* params.sort();
|
|
129
|
+
* console.log(params.toString());
|
|
130
|
+
* // Prints query%5B%5D=abc&query%5B%5D=123&type=search
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
sort(): void;
|
|
134
|
+
/**
|
|
135
|
+
* Returns the search parameters serialized as a string, with characters
|
|
136
|
+
* percent-encoded where necessary.
|
|
137
|
+
*/
|
|
138
|
+
toString(): string;
|
|
139
|
+
/**
|
|
140
|
+
* Returns an ES6 `Iterator` over the values of each name-value pair.
|
|
141
|
+
*/
|
|
142
|
+
values(): IterableIterator<string>;
|
|
143
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { MaybePromise, FindingsSDK, RequestsSDK } from "caido:common";
|
|
2
|
+
|
|
3
|
+
declare module "@caido/sdk-backend" {
|
|
4
|
+
export * from "caido:common";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The SDK for the API RPC service.
|
|
8
|
+
*/
|
|
9
|
+
export type APISDK = {
|
|
10
|
+
/**
|
|
11
|
+
* Registers a new backend function for the RPC.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* sdk.api.register("multiply", (a: number, b: number) => {
|
|
15
|
+
* return a * b;
|
|
16
|
+
* });
|
|
17
|
+
*/
|
|
18
|
+
register(
|
|
19
|
+
name: string,
|
|
20
|
+
callback: (...args: unknown[]) => MaybePromise<unknown>,
|
|
21
|
+
): void;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The SDK object available to all scripts.
|
|
26
|
+
*/
|
|
27
|
+
export type SDK = {
|
|
28
|
+
/**
|
|
29
|
+
* The console.
|
|
30
|
+
*
|
|
31
|
+
* This is currently the same as the global `console`.
|
|
32
|
+
*/
|
|
33
|
+
console: Console;
|
|
34
|
+
/**
|
|
35
|
+
* The SDK for the Findings service.
|
|
36
|
+
*/
|
|
37
|
+
findings: FindingsSDK;
|
|
38
|
+
/**
|
|
39
|
+
* The SDK for the Requests services
|
|
40
|
+
*/
|
|
41
|
+
requests: RequestsSDK;
|
|
42
|
+
/**
|
|
43
|
+
* The SDK for the API RPC service.
|
|
44
|
+
*/
|
|
45
|
+
api: APISDK;
|
|
46
|
+
};
|
|
47
|
+
}
|