@caido/sdk-frontend 0.41.1-beta.3 → 0.41.1-beta.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caido/sdk-frontend",
3
- "version": "0.41.1-beta.3",
3
+ "version": "0.41.1-beta.5",
4
4
  "description": "Typing for the Caido Frontend SDK",
5
5
  "author": "Caido Labs Inc. <dev@caido.io>",
6
6
  "license": "MIT",
@@ -1,11 +1,23 @@
1
1
  import type { PromisifiedReturnType } from "./utils";
2
+ /**
3
+ * Endpoints provided by the backend plugin.
4
+ * @category Backend
5
+ */
2
6
  export type BackendEndpoints = {
3
7
  [key: string]: (...args: any[]) => any;
4
8
  };
9
+ /**
10
+ * Events emitted by the backend plugin.
11
+ * @category Backend
12
+ */
5
13
  export type BackendEvents = {
6
14
  [key: string]: (...args: any[]) => void;
7
15
  };
8
- export type ToBackendRPC<T extends BackendEndpoints, E extends BackendEvents> = {
16
+ /**
17
+ * Utilities to interact with the backend plugin.
18
+ * @category Backend
19
+ */
20
+ export type BackendSDK<T extends BackendEndpoints, E extends BackendEvents> = {
9
21
  [K in keyof T]: (...args: Parameters<T[K]>) => PromisifiedReturnType<T[K]>;
10
22
  } & {
11
23
  /**
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Utilities to interact with the command palette.
3
+ * @category Command Palette
4
+ */
5
+ export type CommandPaletteSDK = {
6
+ /**
7
+ * Register a command.
8
+ * @param commandId The id of the command to register.
9
+ */
10
+ register: (commandId: string) => void;
11
+ };
@@ -1,13 +1,50 @@
1
+ import type { CommandID, ID } from "./utils";
2
+ /**
3
+ * Utilities to interact with commands
4
+ * @category Commands
5
+ */
6
+ export type CommandsSDK = {
7
+ /**
8
+ * Register a command.
9
+ * @param id The id of the command.
10
+ * @param options Options for the command.
11
+ * @param options.name The name of the command.
12
+ * @param options.run The function to run when the command is executed.
13
+ * @param options.group The group this command belongs to.
14
+ * @param options.when A function to determine if the command is available.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * sdk.commands.register("hello", {
19
+ * name: "Print to console.",
20
+ * run: () => console.log("Hello world!"),
21
+ * group: "Custom Commands",
22
+ * });
23
+ * ```
24
+ */
25
+ register: (id: CommandID, options: {
26
+ name: string;
27
+ run: (context: CommandContext) => void;
28
+ group?: string;
29
+ when?: (context: CommandContext) => boolean;
30
+ }) => void;
31
+ };
32
+ /**
33
+ * Represents the context in which a command is executed.
34
+ * @category Commands
35
+ */
1
36
  export type CommandContext = CommandContextBase | CommandContextRequestRow | CommandContextRequest | CommandContextResponse;
2
37
  /**
3
38
  * The base context for a command.
4
39
  * This context is used for commands that are not executed in a specific context, such as via shortcuts and the command palette.
40
+ * @category Commands
5
41
  */
6
42
  type CommandContextBase = {
7
43
  type: "BaseContext";
8
44
  };
9
45
  /**
10
46
  * The context for a command that is executed on a row in the request table.
47
+ * @category Commands
11
48
  */
12
49
  type CommandContextRequestRow = {
13
50
  type: "RequestRowContext";
@@ -15,7 +52,7 @@ type CommandContextRequestRow = {
15
52
  * The requests that are selected in the request table.
16
53
  */
17
54
  requests: {
18
- id: string;
55
+ id: ID;
19
56
  host: string;
20
57
  port: number;
21
58
  path: string;
@@ -25,6 +62,7 @@ type CommandContextRequestRow = {
25
62
  };
26
63
  /**
27
64
  * The context for a command that is executed on a request pane.
65
+ * @category Commands
28
66
  */
29
67
  type CommandContextRequest = {
30
68
  type: "RequestContext";
@@ -46,6 +84,7 @@ type CommandContextRequest = {
46
84
  };
47
85
  /**
48
86
  * The context for a command that is executed on a response pane.
87
+ * @category Commands
49
88
  */
50
89
  type CommandContextResponse = {
51
90
  type: "ResponseContext";
@@ -53,7 +92,7 @@ type CommandContextResponse = {
53
92
  * The request that is associated with the response.
54
93
  */
55
94
  request: {
56
- id: string;
95
+ id: ID;
57
96
  host: string;
58
97
  port: number;
59
98
  path: string;
@@ -64,7 +103,7 @@ type CommandContextResponse = {
64
103
  * The response that is currently open in the response pane.
65
104
  */
66
105
  response: {
67
- id: string;
106
+ id: ID;
68
107
  raw: string;
69
108
  statusCode: number;
70
109
  roundtripTime: number;
@@ -21,12 +21,35 @@ export type Editor = {
21
21
  * Focus the editor.
22
22
  */
23
23
  focus: () => void;
24
+ /**
25
+ * Get the editor view.
26
+ * @returns The CodeMirror {@link https://codemirror.net/docs/ref/#view.EditorView EditorView}.
27
+ */
28
+ getEditorView: () => EditorView;
24
29
  };
25
30
  export type HTTPRequestEditor = {
31
+ /**
32
+ * Get the editor element.
33
+ * Append this to your DOM to display the editor.
34
+ * @returns The editor element.
35
+ */
26
36
  getElement: () => HTMLElement;
37
+ /**
38
+ * Get the editor view.
39
+ * @returns The CodeMirror {@link https://codemirror.net/docs/ref/#view.EditorView EditorView}.
40
+ */
27
41
  getEditorView: () => EditorView;
28
42
  };
29
43
  export type HTTPResponseEditor = {
44
+ /**
45
+ * Get the editor element.
46
+ * Append this to your DOM to display the editor.
47
+ * @returns The editor element.
48
+ */
30
49
  getElement: () => HTMLElement;
50
+ /**
51
+ * Get the editor view.
52
+ * @returns The CodeMirror {@link https://codemirror.net/docs/ref/#view.EditorView EditorView}.
53
+ */
31
54
  getEditorView: () => EditorView;
32
55
  };
@@ -1,11 +1,35 @@
1
+ import type { ID } from "./utils";
1
2
  /**
2
- * Represents a finding.
3
+ * Utilities to interact with findings
4
+ * @category Findings
3
5
  */
4
- export type Finding = {
6
+ export type FindingsSDK = {
7
+ /**
8
+ * Create a {@link Finding}.
9
+ * @param requestId The id of the request the finding is associated with.
10
+ * @param options Options for the finding.
11
+ * @param options.title The title of the finding.
12
+ * @param options.description The description of the finding.
13
+ * @param options.reporter The reporter of the finding.
14
+ * @param options.dedupeKey If a finding with the same deduplication key already exists, it will not create a new finding.
15
+ * @returns The created finding.
16
+ */
17
+ createFinding: (requestId: ID, options: {
18
+ title: string;
19
+ description?: string;
20
+ reporter: string;
21
+ dedupeKey?: string;
22
+ }) => Promise<Finding | undefined>;
23
+ };
24
+ /**
25
+ * Represents a {@link https://docs.caido.io/reference/features/logging/findings|Finding}.
26
+ * @category Findings
27
+ */
28
+ type Finding = {
5
29
  /**
6
30
  * The ID of the finding.
7
31
  */
8
- id: string;
32
+ id: ID;
9
33
  /**
10
34
  * The title of the finding.
11
35
  */
@@ -27,3 +51,4 @@ export type Finding = {
27
51
  */
28
52
  path: string;
29
53
  };
54
+ export {};
@@ -1,271 +1,73 @@
1
- import type { Sdk } from "./__generated__/graphql-sdk";
2
- import type { BackendEndpoints, BackendEvents, ToBackendRPC } from "./backend";
3
- import type { CommandContext } from "./commands";
4
- import type { Editor, HTTPRequestEditor, HTTPResponseEditor } from "./editor";
5
- import type { Finding } from "./findings";
6
- import type { MenuItem } from "./menu";
7
- import type { Scope } from "./scopes";
8
- import type { SidebarItem } from "./sidebar";
9
- import type { JSONCompatible, JSONValue } from "./utils";
1
+ import type { Sdk as GraphqlSDK } from "./__generated__/graphql-sdk";
2
+ import type { BackendEndpoints, BackendEvents, BackendSDK } from "./backend";
3
+ import type { CommandPaletteSDK } from "./command_palette";
4
+ import type { CommandsSDK } from "./commands";
5
+ import type { FindingsSDK } from "./findings";
6
+ import type { MenuSDK } from "./menu";
7
+ import type { NavigationSDK } from "./navigation";
8
+ import type { ScopesSDK } from "./scopes";
9
+ import type { ShortcutsSDK } from "./shortcuts";
10
+ import type { SidebarSDK } from "./sidebar";
11
+ import type { StorageSDK } from "./storage";
12
+ import type { UISDK } from "./ui";
13
+ import type { WindowSDK } from "./window";
10
14
  export type { CommandContext } from "./commands";
11
15
  export type { MenuItem } from "./menu";
16
+ /**
17
+ * Utilities for frontend plugins.
18
+ * @category SDK
19
+ */
12
20
  export type API<T extends BackendEndpoints = Record<string, never>, E extends BackendEvents = Record<string, never>> = {
13
- graphql: Sdk;
14
- backend: ToBackendRPC<T, E>;
21
+ /**
22
+ * Utilities to interact with the GraphQL API.
23
+ */
24
+ graphql: GraphqlSDK;
25
+ /**
26
+ * Utilities to interact with the backend plugin.
27
+ */
28
+ backend: BackendSDK<T, E>;
15
29
  /**
16
30
  * Utilities to create UI components.
17
31
  */
18
- ui: {
19
- /**
20
- * Create a button.
21
- * @param options Options for the button.
22
- * @param options.variant The variant of the button.
23
- * @param options.label The label of the button.
24
- * @param options.leadingIcon The leading icon of the button.
25
- * @param options.trailingIcon The trailing icon of the button.
26
- * @param options.size The size of the button.
27
- * @returns The button element.
28
- */
29
- button: (options?: {
30
- variant?: "primary" | "secondary" | "tertiary";
31
- label?: string;
32
- leadingIcon?: string;
33
- trailingIcon?: string;
34
- size?: "small" | "medium" | "large";
35
- }) => HTMLElement;
36
- /**
37
- * Create a card.
38
- * @param options Options for the card.
39
- * @param options.header The header of the card.
40
- * @param options.body The body of the card.
41
- * @param options.footer The footer of the card.
42
- * @returns The card element.
43
- */
44
- card: (options?: {
45
- header?: HTMLElement;
46
- body?: HTMLElement;
47
- footer?: HTMLElement;
48
- }) => HTMLElement;
49
- /**
50
- * Create a well.
51
- * @param options Options for the well.
52
- * @param options.header The header of the well.
53
- * @param options.body The body of the well.
54
- * @param options.footer The footer of the well.
55
- * @returns The well element.
56
- */
57
- well: (options?: {
58
- header?: HTMLElement;
59
- body?: HTMLElement;
60
- footer?: HTMLElement;
61
- }) => HTMLElement;
62
- /**
63
- * Create an HTTP request editor
64
- * @returns The HTTP request editor.
65
- */
66
- httpRequestEditor: () => HTTPRequestEditor;
67
- /**
68
- * Create an HTTP response editor
69
- * @returns The HTTP response editor.
70
- */
71
- httpResponseEditor: () => HTTPResponseEditor;
72
- };
32
+ ui: UISDK;
73
33
  /**
74
34
  * Utilities to interact with scopes
75
35
  */
76
- scopes: {
77
- /**
78
- * Get all scopes.
79
- * @returns A list of scopes.
80
- */
81
- getScopes: () => Scope[];
82
- /**
83
- * Create a scope.
84
- * @param options Options for the scope.
85
- * @param options.name The name of the scope.
86
- * @param options.allowlist The list of included items in the scope.
87
- * @param options.denylist The list of excluded items in the scope.
88
- * @returns The created scope.
89
- */
90
- createScope: (options: {
91
- name: string;
92
- allowlist: string[];
93
- denylist: string[];
94
- }) => Promise<Scope | undefined>;
95
- /**
96
- * Update a scope.
97
- * @param id The id of the scope to update.
98
- * @param options Options for the scope.
99
- * @param options.name The name of the scope.
100
- * @param options.allowlist The list of included items in the scope.
101
- * @param options.denylist The list of excluded items in the scope.
102
- * @returns The updated scope.
103
- */
104
- updateScope: (id: string, options: {
105
- name?: string;
106
- allowlist?: string[];
107
- denylist?: string[];
108
- }) => Promise<Scope | undefined>;
109
- /**
110
- * Delete a scope.
111
- * @param id The id of the scope to delete.
112
- * @returns Whether the scope was deleted.
113
- */
114
- deleteScope: (id: string) => Promise<boolean>;
115
- };
36
+ scopes: ScopesSDK;
116
37
  /**
117
38
  * Utilities to interact with findings
118
39
  */
119
- findings: {
120
- /**
121
- * Create a finding.
122
- * @param requestId The id of the request the finding is associated with.
123
- * @param options Options for the finding.
124
- * @param options.title The title of the finding.
125
- * @param options.description The description of the finding.
126
- * @param options.reporter The reporter of the finding.
127
- * @param options.dedupeKey The dedupe key of the finding.
128
- * @returns The created finding.
129
- */
130
- createFinding: (requestId: string, options: {
131
- title: string;
132
- description?: string;
133
- reporter: string;
134
- dedupeKey?: string;
135
- }) => Promise<Finding | undefined>;
136
- };
40
+ findings: FindingsSDK;
137
41
  /**
138
42
  * Utilities to interact with commands
139
43
  */
140
- commands: {
141
- /**
142
- * Register a command.
143
- * @param id The id of the command.
144
- * @param options Options for the command.
145
- * @param options.name The name of the command.
146
- * @param options.run The function to run when the command is executed.
147
- * @param options.group The group this command belongs to.
148
- * @param options.when A function to determine if the command is available.
149
- */
150
- register: (id: string, options: {
151
- name: string;
152
- run: (context: CommandContext) => void;
153
- group?: string;
154
- when?: (context: CommandContext) => boolean;
155
- }) => void;
156
- };
44
+ commands: CommandsSDK;
157
45
  /**
158
46
  * Utilities to insert menu items and context-menus throughout the UI.
159
47
  */
160
- menu: {
161
- /**
162
- * Register a menu item.
163
- * @param item The menu item to register.
164
- */
165
- registerItem: (item: MenuItem) => void;
166
- };
48
+ menu: MenuSDK;
167
49
  /**
168
50
  * Utilities to interact with navigation.
169
51
  */
170
- navigation: {
171
- /**
172
- * Navigate to a path.
173
- * @param path The path to navigate to.
174
- */
175
- goTo: (path: string) => void;
176
- /**
177
- * Add a page to the navigation.
178
- * @param path The path of the page.
179
- * @param options Options for the page.
180
- * @param options.body The body of the page.
181
- * @param options.topbar The topbar of the page.
182
- */
183
- addPage: (path: string, options: {
184
- body: HTMLElement;
185
- topbar?: HTMLElement;
186
- }) => void;
187
- };
52
+ navigation: NavigationSDK;
188
53
  /**
189
54
  * Utilities to interact with the active page.
190
55
  */
191
- window: {
192
- /**
193
- * Get the active editor.
194
- * @returns The active editor.
195
- */
196
- getActiveEditor: () => Editor | undefined;
197
- /**
198
- * Show a toast message.
199
- * @param message The message to show.
200
- * @param options Options for the toast message.
201
- * @param options.variant The variant of the toast message.
202
- * @param options.duration The duration of the toast message in milliseconds.
203
- */
204
- showToast: (message: string, options?: {
205
- variant?: "success" | "error" | "warning" | "info";
206
- duration?: number;
207
- }) => void;
208
- };
56
+ window: WindowSDK;
209
57
  /**
210
58
  * Utilities to interact with frontend-plugin storage.
211
59
  */
212
- storage: {
213
- /**
214
- * Get the storage.
215
- * @returns The storage.
216
- */
217
- get: () => JSONValue;
218
- /**
219
- * Set the storage.
220
- * @param value The value to set the storage to
221
- * @returns A promise that resolves when the storage has been set.
222
- */
223
- set: <T>(value: JSONCompatible<T>) => Promise<void>;
224
- /**
225
- * Subscribe to storage changes.
226
- * @param callback The callback to call when the storage changes.
227
- */
228
- onChange: (callback: (value: JSONValue) => void) => void;
229
- };
60
+ storage: StorageSDK;
230
61
  /**
231
62
  * Utilities to interact with shortcuts.
232
63
  */
233
- shortcuts: {
234
- /**
235
- * Register a shortcut.
236
- * @param commandId The id of the command to run when the shortcut is triggered.
237
- * @param keys The keys of the shortcut.
238
- */
239
- register: (commandId: string, keys: string[]) => void;
240
- };
64
+ shortcuts: ShortcutsSDK;
241
65
  /**
242
66
  * Utilities to interact with the command palette.
243
67
  */
244
- commandPalette: {
245
- /**
246
- * Register a command.
247
- * @param commandId The id of the command to register.
248
- */
249
- register: (commandId: string) => void;
250
- };
68
+ commandPalette: CommandPaletteSDK;
251
69
  /**
252
70
  * Utilities to interact with the sidebar.
253
71
  */
254
- sidebar: {
255
- /**
256
- * Register a sidebar item.
257
- * @param name The name of the sidebar item.
258
- * @param path The path that the user will be navigated to when the sidebar item is clicked.
259
- * @param options Options for the sidebar item.
260
- * @param options.icon The icon of the sidebar item.
261
- * @param options.group The group the sidebar item belongs to.
262
- * @param options.isExternal Whether the path points to an external URL.
263
- * @returns The created sidebar item.
264
- */
265
- registerItem: (name: string, path: string, options?: {
266
- icon?: string;
267
- group?: string;
268
- isExternal?: boolean;
269
- }) => SidebarItem;
270
- };
72
+ sidebar: SidebarSDK;
271
73
  };
@@ -1,13 +1,39 @@
1
+ import type { CommandID, Icon } from "./utils";
2
+ /**
3
+ * Utilities to insert menu items and context-menus throughout the UI.
4
+ * @category Menu
5
+ */
6
+ export type MenuSDK = {
7
+ /**
8
+ * Register a menu item.
9
+ * @param item The menu item to register.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * sdk.menu.registerItem({
14
+ * type: "Request",
15
+ * commandId: "hello",
16
+ * leadingIcon: "fas fa-hand",
17
+ * });
18
+ * ```
19
+ */
20
+ registerItem: (item: MenuItem) => void;
21
+ };
22
+ /**
23
+ * A content-menu item.
24
+ * @category Menu
25
+ */
1
26
  export type MenuItem = RequestRowMenuItem | SettingsMenuItem | RequestMenuItem | ResponseMenuItem;
2
27
  /**
3
28
  * A context-menu item that appears when right-clicking a request row.
29
+ * @category Menu
4
30
  */
5
31
  type RequestRowMenuItem = {
6
32
  type: "RequestRow";
7
33
  /**
8
34
  * The command ID to execute when the menu item is clicked.
9
35
  */
10
- commandId: string;
36
+ commandId: CommandID;
11
37
  /**
12
38
  * The icon to display to the left of the menu item.
13
39
  */
@@ -15,13 +41,14 @@ type RequestRowMenuItem = {
15
41
  };
16
42
  /**
17
43
  * A context-menu item that appears when right-clicking a request pane.
44
+ * @category Menu
18
45
  */
19
46
  type RequestMenuItem = {
20
47
  type: "Request";
21
48
  /**
22
49
  * The command ID to execute when the menu item is clicked.
23
50
  */
24
- commandId: string;
51
+ commandId: CommandID;
25
52
  /**
26
53
  * The icon to display to the left of the menu item.
27
54
  */
@@ -29,13 +56,14 @@ type RequestMenuItem = {
29
56
  };
30
57
  /**
31
58
  * A context-menu item that appears when right-clicking a response pane.
59
+ * @category Menu
32
60
  */
33
61
  type ResponseMenuItem = {
34
62
  type: "Response";
35
63
  /**
36
64
  * The command ID to execute when the menu item is
37
65
  */
38
- commandId: string;
66
+ commandId: CommandID;
39
67
  /**
40
68
  * The icon to display to the left of the menu item.
41
69
  */
@@ -43,6 +71,7 @@ type ResponseMenuItem = {
43
71
  };
44
72
  /**
45
73
  * A menu item that appears in the settings menu.
74
+ * @category Menu
46
75
  */
47
76
  type SettingsMenuItem = {
48
77
  type: "Settings";
@@ -52,11 +81,12 @@ type SettingsMenuItem = {
52
81
  label: string;
53
82
  /**
54
83
  * The path that the user will be navigated to when the menu item is clicked
84
+ * The path must start with "/settings/".
55
85
  */
56
86
  path: string;
57
87
  /**
58
- * The icon to display to the left of the menu item.
88
+ * The {@link Icon} to display to the left of the menu item.
59
89
  */
60
- leadingIcon?: string;
90
+ leadingIcon?: Icon;
61
91
  };
62
92
  export {};
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Utilities to interact with navigation.
3
+ * @category Navigation
4
+ */
5
+ export type NavigationSDK = {
6
+ /**
7
+ * Navigate to a path.
8
+ * @param path The path to navigate to.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * sdk.navigation.goTo("/my-plugin-page");
13
+ * ```
14
+ */
15
+ goTo: (path: string) => void;
16
+ /**
17
+ * Add a page to the navigation.
18
+ * @param path The path of the page.
19
+ * @param options Options for the page.
20
+ * @param options.body The body of the page.
21
+ * @param options.topbar The topbar of the page.
22
+ */
23
+ addPage: (path: string, options: {
24
+ body: HTMLElement;
25
+ topbar?: HTMLElement;
26
+ }) => void;
27
+ };
@@ -1,11 +1,66 @@
1
+ import type { ID } from "./utils";
2
+ /**
3
+ * Utilities to interact with scopes
4
+ * @category Scopes
5
+ */
6
+ export type ScopesSDK = {
7
+ /**
8
+ * Get all scopes.
9
+ * @returns A list of scopes.
10
+ */
11
+ getScopes: () => Scope[];
12
+ /**
13
+ * Create a scope.
14
+ * @param options Options for the scope.
15
+ * @param options.name The name of the scope.
16
+ * @param options.allowlist The list of included items in the scope.
17
+ * @param options.denylist The list of excluded items in the scope.
18
+ * @returns The created scope.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const newScope = await sdk.scopes.createScope({
23
+ * name: "Example",
24
+ * allowlist: ["*example.com", "*github.com"],
25
+ * denylist: ["*caido.io"],
26
+ * });
27
+ * ```
28
+ */
29
+ createScope: (options: {
30
+ name: string;
31
+ allowlist: string[];
32
+ denylist: string[];
33
+ }) => Promise<Scope | undefined>;
34
+ /**
35
+ * Update a scope.
36
+ * @param id The id of the scope to update.
37
+ * @param options Options for the scope.
38
+ * @param options.name The name of the scope.
39
+ * @param options.allowlist The list of included items in the scope.
40
+ * @param options.denylist The list of excluded items in the scope.
41
+ * @returns The updated scope.
42
+ */
43
+ updateScope: (id: ID, options: {
44
+ name?: string;
45
+ allowlist?: string[];
46
+ denylist?: string[];
47
+ }) => Promise<Scope | undefined>;
48
+ /**
49
+ * Delete a scope.
50
+ * @param id The id of the scope to delete.
51
+ * @returns Whether the scope was deleted.
52
+ */
53
+ deleteScope: (id: ID) => Promise<boolean>;
54
+ };
1
55
  /**
2
56
  * Represents a scope.
57
+ * @category Scopes
3
58
  */
4
- export type Scope = {
59
+ type Scope = {
5
60
  /**
6
61
  * The unique ID of the scope.
7
62
  */
8
- id: string;
63
+ id: ID;
9
64
  /**
10
65
  * The name of the scope.
11
66
  */
@@ -19,3 +74,4 @@ export type Scope = {
19
74
  */
20
75
  denylist: string[];
21
76
  };
77
+ export {};
@@ -0,0 +1,13 @@
1
+ import type { CommandID } from "./utils";
2
+ /**
3
+ * Utilities to interact with shortcuts.
4
+ * @category Shortcuts
5
+ */
6
+ export type ShortcutsSDK = {
7
+ /**
8
+ * Register a shortcut.
9
+ * @param commandId The id of the command to run when the shortcut is triggered.
10
+ * @param keys The keys of the shortcut.
11
+ */
12
+ register: (commandId: CommandID, keys: string[]) => void;
13
+ };
@@ -1,10 +1,41 @@
1
+ import type { Icon } from "./utils";
2
+ /**
3
+ * Utilities to interact with the sidebar.
4
+ * @category Sidebar
5
+ */
6
+ export type SidebarSDK = {
7
+ /**
8
+ * Register a sidebar item.
9
+ * @param name The name of the sidebar item.
10
+ * @param path The path that the user will be navigated to when the sidebar item is clicked.
11
+ * @param options Options for the sidebar item.
12
+ * @param options.icon The {@link Icon} of the sidebar item.
13
+ * @param options.group The group the sidebar item belongs to.
14
+ * @param options.isExternal Whether the path points to an external URL.
15
+ * @returns The created sidebar item.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * sdk.sidebar.registerItem("My Plugin", "/my-plugin-page", {
20
+ * icon: "fas fa-rocket",
21
+ * });
22
+ * ```
23
+ */
24
+ registerItem: (name: string, path: string, options?: {
25
+ icon?: Icon;
26
+ group?: string;
27
+ isExternal?: boolean;
28
+ }) => SidebarItem;
29
+ };
1
30
  /**
2
31
  * Represents a sidebar item.
32
+ * @category Sidebar
3
33
  */
4
- export type SidebarItem = {
34
+ type SidebarItem = {
5
35
  /**
6
36
  * Set the value of a notification badge next to the sidebar item.
7
37
  * @param count - The number to display in the badge. A value of 0 will hide the badge.
8
38
  */
9
39
  setCount: (count: number) => void;
10
40
  };
41
+ export {};
@@ -0,0 +1,23 @@
1
+ import type { JSONCompatible, JSONValue } from "./utils";
2
+ /**
3
+ * Utilities to interact with frontend-plugin storage.
4
+ * @category Storage
5
+ */
6
+ export type StorageSDK = {
7
+ /**
8
+ * Get the storage.
9
+ * @returns The storage.
10
+ */
11
+ get: () => JSONValue;
12
+ /**
13
+ * Set the storage.
14
+ * @param value The value to set the storage to
15
+ * @returns A promise that resolves when the storage has been set.
16
+ */
17
+ set: <T>(value: JSONCompatible<T>) => Promise<void>;
18
+ /**
19
+ * Subscribe to storage changes.
20
+ * @param callback The callback to call when the storage changes.
21
+ */
22
+ onChange: (callback: (value: JSONValue) => void) => void;
23
+ };
@@ -0,0 +1,71 @@
1
+ import type { HTTPRequestEditor, HTTPResponseEditor } from "./editor";
2
+ import type { Icon } from "./utils";
3
+ /**
4
+ * Utilities to create UI components.
5
+ * @category UI
6
+ */
7
+ export type UISDK = {
8
+ /**
9
+ * Create a button.
10
+ * @param options Options for the button.
11
+ * @param options.variant The variant of the button.
12
+ * @param options.label The label of the button.
13
+ * @param options.leadingIcon The leading icon of the button.
14
+ * @param options.trailingIcon The trailing icon of the button.
15
+ * @param options.size The size of the button.
16
+ * @returns The button element.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const deleteButton = sdk.ui.button({
21
+ * variant: "primary",
22
+ * label: "Delete",
23
+ * trailingIcon: "fas fa-trash-can",
24
+ * size: "small",
25
+ * });
26
+ * ```
27
+ */
28
+ button: (options?: {
29
+ variant?: "primary" | "secondary" | "tertiary";
30
+ label?: string;
31
+ leadingIcon?: Icon;
32
+ trailingIcon?: Icon;
33
+ size?: "small" | "medium" | "large";
34
+ }) => HTMLElement;
35
+ /**
36
+ * Create a card.
37
+ * @param options Options for the card.
38
+ * @param options.header The header of the card.
39
+ * @param options.body The body of the card.
40
+ * @param options.footer The footer of the card.
41
+ * @returns The card element.
42
+ */
43
+ card: (options?: {
44
+ header?: HTMLElement;
45
+ body?: HTMLElement;
46
+ footer?: HTMLElement;
47
+ }) => HTMLElement;
48
+ /**
49
+ * Create a well.
50
+ * @param options Options for the well.
51
+ * @param options.header The header of the well.
52
+ * @param options.body The body of the well.
53
+ * @param options.footer The footer of the well.
54
+ * @returns The well element.
55
+ */
56
+ well: (options?: {
57
+ header?: HTMLElement;
58
+ body?: HTMLElement;
59
+ footer?: HTMLElement;
60
+ }) => HTMLElement;
61
+ /**
62
+ * Create an HTTP request editor
63
+ * @returns The HTTP request editor.
64
+ */
65
+ httpRequestEditor: () => HTTPRequestEditor;
66
+ /**
67
+ * Create an HTTP response editor
68
+ * @returns The HTTP response editor.
69
+ */
70
+ httpResponseEditor: () => HTTPResponseEditor;
71
+ };
@@ -1,4 +1,24 @@
1
1
  type JSONPrimitive = string | number | boolean | null | undefined;
2
+ /**
3
+ * A unique Caido identifier per type.
4
+ */
5
+ export type ID = string & {
6
+ __id?: never;
7
+ };
8
+ /**
9
+ * A unique command identifier.
10
+ * @example "my-super-command"
11
+ */
12
+ export type CommandID = string & {
13
+ __commandId?: never;
14
+ };
15
+ /**
16
+ * A {@link https://fontawesome.com/icons|FontAwesome} icon class.
17
+ * @example "fas fa-rocket"
18
+ */
19
+ export type Icon = string & {
20
+ __icon?: never;
21
+ };
2
22
  export type JSONValue = JSONPrimitive | JSONValue[] | {
3
23
  [key: string]: JSONValue;
4
24
  };
@@ -0,0 +1,23 @@
1
+ import type { Editor } from "./editor";
2
+ /**
3
+ * Utilities to interact with the active page.
4
+ * @category Window
5
+ */
6
+ export type WindowSDK = {
7
+ /**
8
+ * Get the active editor.
9
+ * @returns The active editor.
10
+ */
11
+ getActiveEditor: () => Editor | undefined;
12
+ /**
13
+ * Show a toast message.
14
+ * @param message The message to show.
15
+ * @param options Options for the toast message.
16
+ * @param options.variant The variant of the toast message.
17
+ * @param options.duration The duration of the toast message in milliseconds.
18
+ */
19
+ showToast: (message: string, options?: {
20
+ variant?: "success" | "error" | "warning" | "info";
21
+ duration?: number;
22
+ }) => void;
23
+ };