@caido/sdk-frontend 0.40.0 → 0.40.1-beta.1

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.40.0",
3
+ "version": "0.40.1-beta.1",
4
4
  "description": "Typing for the Caido Frontend SDK",
5
5
  "author": "Caido Labs Inc. <dev@caido.io>",
6
6
  "license": "MIT",
@@ -9,5 +9,7 @@
9
9
  "module": "./src/index.js",
10
10
  "files": [
11
11
  "src/*"
12
- ]
12
+ ],
13
+ "peerDependencies": {},
14
+ "peerDependenciesMeta": {}
13
15
  }
@@ -82,6 +82,10 @@ export type Scalars = {
82
82
  input: JSONValue;
83
83
  output: JSONValue;
84
84
  };
85
+ JsonRaw: {
86
+ input: string;
87
+ output: string;
88
+ };
85
89
  Port: {
86
90
  input: number;
87
91
  output: number;
@@ -785,6 +789,11 @@ export type CreatedInterceptMessagePayload = {
785
789
  messageEdge: InterceptMessageEdge;
786
790
  snapshot: Scalars["Snapshot"]["output"];
787
791
  };
792
+ export type CreatedPluginEventPayload = {
793
+ eventArgs: Array<Scalars["JsonRaw"]["output"]>;
794
+ eventName: Scalars["String"]["output"];
795
+ pluginId: Scalars["ID"]["output"];
796
+ };
788
797
  export type CreatedPluginPackagePayload = {
789
798
  package: PluginPackage;
790
799
  };
@@ -2627,7 +2636,7 @@ export type StartExportRequestsTaskPayload = {
2627
2636
  task?: Maybe<DataExportTask>;
2628
2637
  };
2629
2638
  export type StartExportRequestsTaskPayloadError = OtherUserError | PermissionDeniedUserError;
2630
- export type StartReplayTaskError = OtherUserError | TaskInProgressUserError;
2639
+ export type StartReplayTaskError = OtherUserError | PermissionDeniedUserError | TaskInProgressUserError;
2631
2640
  export type StartReplayTaskInput = {
2632
2641
  connection: ConnectionInfoInput;
2633
2642
  raw: Scalars["Blob"]["input"];
@@ -2758,6 +2767,7 @@ export type SubscriptionRoot = {
2758
2767
  createdFinding: CreatedFindingPayload;
2759
2768
  createdInterceptEntry: CreatedInterceptEntryPayload;
2760
2769
  createdInterceptMessage: CreatedInterceptMessagePayload;
2770
+ createdPluginEvent: CreatedPluginEventPayload;
2761
2771
  createdPluginPackage: CreatedPluginPackagePayload;
2762
2772
  createdProject: CreatedProjectPayload;
2763
2773
  createdReplaySession: CreatedReplaySessionPayload;
@@ -8217,6 +8227,10 @@ export type StartReplayTaskMutation = {
8217
8227
  error?: {
8218
8228
  __typename: "OtherUserError";
8219
8229
  code: string;
8230
+ } | {
8231
+ __typename: "PermissionDeniedUserError";
8232
+ code: string;
8233
+ permissionDeniedReason: PermissionDeniedErrorReason;
8220
8234
  } | {
8221
8235
  __typename: "TaskInProgressUserError";
8222
8236
  taskId: string;
@@ -12803,6 +12817,16 @@ export type UpdatedPluginSubscription = {
12803
12817
  };
12804
12818
  };
12805
12819
  };
12820
+ export type CreatedPluginEventSubscriptionVariables = Exact<{
12821
+ [key: string]: never;
12822
+ }>;
12823
+ export type CreatedPluginEventSubscription = {
12824
+ createdPluginEvent: {
12825
+ pluginId: string;
12826
+ eventArgs: Array<string>;
12827
+ eventName: string;
12828
+ };
12829
+ };
12806
12830
  export type CreatedProjectSubscriptionVariables = Exact<{
12807
12831
  [key: string]: never;
12808
12832
  }>;
@@ -13707,7 +13731,7 @@ export declare const SetActiveReplaySessionEntryDocument = "\n mutation setAc
13707
13731
  export declare const DeleteReplaySessionsDocument = "\n mutation deleteReplaySessions($ids: [ID!]!) {\n deleteReplaySessions(ids: $ids) {\n deletedIds\n }\n}\n ";
13708
13732
  export declare const CreateReplaySessionDocument = "\n mutation createReplaySession($input: CreateReplaySessionInput!) {\n createReplaySession(input: $input) {\n session {\n ...replaySessionMeta\n collection {\n ...replaySessionCollectionMeta\n }\n }\n }\n}\n \n fragment replaySessionMeta on ReplaySession {\n __typename\n id\n name\n activeEntry {\n ...replayEntryMeta\n }\n collection {\n id\n }\n entries {\n nodes {\n ...replayEntryMeta\n }\n pageInfo {\n ...pageInfoFull\n }\n count {\n ...countFull\n }\n }\n}\n \n\n fragment replayEntryMeta on ReplayEntry {\n __typename\n id\n error\n connection {\n ...connectionInfoFull\n }\n session {\n id\n }\n request {\n ...requestMeta\n }\n}\n \n\n fragment connectionInfoFull on ConnectionInfo {\n __typename\n host\n port\n isTls\n}\n \n\n fragment requestMeta on Request {\n __typename\n id\n host\n port\n path\n query\n method\n edited\n isTls\n length\n alteration\n metadata {\n ...requestMetadataFull\n }\n fileExtension\n source\n createdAt\n response {\n ...responseMeta\n }\n}\n \n\n fragment requestMetadataFull on RequestMetadata {\n __typename\n id\n color\n}\n \n\n fragment responseMeta on Response {\n __typename\n id\n statusCode\n roundtripTime\n length\n createdAt\n alteration\n edited\n}\n \n\n fragment pageInfoFull on PageInfo {\n __typename\n hasPreviousPage\n hasNextPage\n startCursor\n endCursor\n}\n \n\n fragment countFull on Count {\n __typename\n value\n snapshot\n}\n \n\n fragment replaySessionCollectionMeta on ReplaySessionCollection {\n __typename\n id\n name\n sessions {\n ...replaySessionMeta\n }\n}\n ";
13709
13733
  export declare const MoveReplaySessionDocument = "\n mutation moveReplaySession($id: ID!, $collectionId: ID!) {\n moveReplaySession(collectionId: $collectionId, id: $id) {\n session {\n ...replaySessionMeta\n }\n }\n}\n \n fragment replaySessionMeta on ReplaySession {\n __typename\n id\n name\n activeEntry {\n ...replayEntryMeta\n }\n collection {\n id\n }\n entries {\n nodes {\n ...replayEntryMeta\n }\n pageInfo {\n ...pageInfoFull\n }\n count {\n ...countFull\n }\n }\n}\n \n\n fragment replayEntryMeta on ReplayEntry {\n __typename\n id\n error\n connection {\n ...connectionInfoFull\n }\n session {\n id\n }\n request {\n ...requestMeta\n }\n}\n \n\n fragment connectionInfoFull on ConnectionInfo {\n __typename\n host\n port\n isTls\n}\n \n\n fragment requestMeta on Request {\n __typename\n id\n host\n port\n path\n query\n method\n edited\n isTls\n length\n alteration\n metadata {\n ...requestMetadataFull\n }\n fileExtension\n source\n createdAt\n response {\n ...responseMeta\n }\n}\n \n\n fragment requestMetadataFull on RequestMetadata {\n __typename\n id\n color\n}\n \n\n fragment responseMeta on Response {\n __typename\n id\n statusCode\n roundtripTime\n length\n createdAt\n alteration\n edited\n}\n \n\n fragment pageInfoFull on PageInfo {\n __typename\n hasPreviousPage\n hasNextPage\n startCursor\n endCursor\n}\n \n\n fragment countFull on Count {\n __typename\n value\n snapshot\n}\n ";
13710
- export declare const StartReplayTaskDocument = "\n mutation startReplayTask($sessionId: ID!, $input: StartReplayTaskInput!) {\n startReplayTask(sessionId: $sessionId, input: $input) {\n task {\n ...replayTaskMeta\n }\n error {\n ... on TaskInProgressUserError {\n ...taskInProgressUserErrorFull\n }\n ... on OtherUserError {\n ...otherUserErrorFull\n }\n }\n }\n}\n \n fragment replayTaskMeta on ReplayTask {\n ...taskMeta\n replayEntry {\n ...replayEntryMeta\n }\n}\n \n\n fragment taskMeta on Task {\n __typename\n id\n createdAt\n}\n \n\n fragment replayEntryMeta on ReplayEntry {\n __typename\n id\n error\n connection {\n ...connectionInfoFull\n }\n session {\n id\n }\n request {\n ...requestMeta\n }\n}\n \n\n fragment connectionInfoFull on ConnectionInfo {\n __typename\n host\n port\n isTls\n}\n \n\n fragment requestMeta on Request {\n __typename\n id\n host\n port\n path\n query\n method\n edited\n isTls\n length\n alteration\n metadata {\n ...requestMetadataFull\n }\n fileExtension\n source\n createdAt\n response {\n ...responseMeta\n }\n}\n \n\n fragment requestMetadataFull on RequestMetadata {\n __typename\n id\n color\n}\n \n\n fragment responseMeta on Response {\n __typename\n id\n statusCode\n roundtripTime\n length\n createdAt\n alteration\n edited\n}\n \n\n fragment taskInProgressUserErrorFull on TaskInProgressUserError {\n ...userErrorFull\n taskId\n}\n \n\n fragment userErrorFull on UserError {\n __typename\n code\n}\n \n\n fragment otherUserErrorFull on OtherUserError {\n ...userErrorFull\n}\n ";
13734
+ export declare const StartReplayTaskDocument = "\n mutation startReplayTask($sessionId: ID!, $input: StartReplayTaskInput!) {\n startReplayTask(sessionId: $sessionId, input: $input) {\n task {\n ...replayTaskMeta\n }\n error {\n ... on TaskInProgressUserError {\n ...taskInProgressUserErrorFull\n }\n ... on PermissionDeniedUserError {\n ...permissionDeniedUserErrorFull\n }\n ... on OtherUserError {\n ...otherUserErrorFull\n }\n }\n }\n}\n \n fragment replayTaskMeta on ReplayTask {\n ...taskMeta\n replayEntry {\n ...replayEntryMeta\n }\n}\n \n\n fragment taskMeta on Task {\n __typename\n id\n createdAt\n}\n \n\n fragment replayEntryMeta on ReplayEntry {\n __typename\n id\n error\n connection {\n ...connectionInfoFull\n }\n session {\n id\n }\n request {\n ...requestMeta\n }\n}\n \n\n fragment connectionInfoFull on ConnectionInfo {\n __typename\n host\n port\n isTls\n}\n \n\n fragment requestMeta on Request {\n __typename\n id\n host\n port\n path\n query\n method\n edited\n isTls\n length\n alteration\n metadata {\n ...requestMetadataFull\n }\n fileExtension\n source\n createdAt\n response {\n ...responseMeta\n }\n}\n \n\n fragment requestMetadataFull on RequestMetadata {\n __typename\n id\n color\n}\n \n\n fragment responseMeta on Response {\n __typename\n id\n statusCode\n roundtripTime\n length\n createdAt\n alteration\n edited\n}\n \n\n fragment taskInProgressUserErrorFull on TaskInProgressUserError {\n ...userErrorFull\n taskId\n}\n \n\n fragment userErrorFull on UserError {\n __typename\n code\n}\n \n\n fragment permissionDeniedUserErrorFull on PermissionDeniedUserError {\n ...userErrorFull\n permissionDeniedReason: reason\n}\n \n\n fragment otherUserErrorFull on OtherUserError {\n ...userErrorFull\n}\n ";
13711
13735
  export declare const UpdateRequestMetadataDocument = "\n mutation updateRequestMetadata($id: ID!, $input: UpdateRequestMetadataInput!) {\n updateRequestMetadata(id: $id, input: $input) {\n snapshot\n metadata {\n ...requestMetadataFull\n }\n }\n}\n \n fragment requestMetadataFull on RequestMetadata {\n __typename\n id\n color\n}\n ";
13712
13736
  export declare const StartExportRequestsTaskDocument = "\n mutation startExportRequestsTask($input: StartExportRequestsTaskInput!) {\n startExportRequestsTask(input: $input) {\n task {\n ...dataExportTaskMeta\n }\n error {\n ... on OtherUserError {\n ...otherUserErrorFull\n }\n ... on PermissionDeniedUserError {\n ...permissionDeniedUserErrorFull\n }\n }\n }\n}\n \n fragment dataExportTaskMeta on DataExportTask {\n ...dataExportTaskMetaFields\n}\n \n\n fragment dataExportTaskMetaFields on DataExportTask {\n __typename\n id\n export {\n ...dataExportMeta\n }\n}\n \n\n fragment dataExportMeta on DataExport {\n ...dataExportMetaFields\n}\n \n\n fragment dataExportMetaFields on DataExport {\n __typename\n id\n name\n path\n size\n status\n format\n error\n createdAt\n}\n \n\n fragment otherUserErrorFull on OtherUserError {\n ...userErrorFull\n}\n \n\n fragment userErrorFull on UserError {\n __typename\n code\n}\n \n\n fragment permissionDeniedUserErrorFull on PermissionDeniedUserError {\n ...userErrorFull\n permissionDeniedReason: reason\n}\n ";
13713
13737
  export declare const RenderRequestDocument = "\n mutation renderRequest($id: ID!, $input: RenderRequestInput!) {\n renderRequest(id: $id, input: $input) {\n render\n error {\n ... on RenderFailedUserError {\n ...renderFailedUserErrorFull\n }\n ... on OtherUserError {\n ...otherUserErrorFull\n }\n }\n }\n}\n \n fragment renderFailedUserErrorFull on RenderFailedUserError {\n ...userErrorFull\n reason\n}\n \n\n fragment userErrorFull on UserError {\n __typename\n code\n}\n \n\n fragment otherUserErrorFull on OtherUserError {\n ...userErrorFull\n}\n ";
@@ -13849,6 +13873,7 @@ export declare const UpdatedInterceptOptionsDocument = "\n subscription updat
13849
13873
  export declare const CreatedPluginPackageDocument = "\n subscription createdPluginPackage {\n createdPluginPackage {\n package {\n ...pluginPackageFull\n }\n }\n}\n \n fragment pluginPackageFull on PluginPackage {\n ...pluginPackageMeta\n plugins {\n ... on PluginFrontend {\n ...pluginFrontendFull\n }\n ... on PluginBackend {\n ...pluginBackendFull\n }\n }\n}\n \n\n fragment pluginPackageMeta on PluginPackage {\n id\n name\n description\n author {\n ...pluginAuthorFull\n }\n version\n installedAt\n manifestId\n}\n \n\n fragment pluginAuthorFull on PluginAuthor {\n name\n email\n url\n}\n \n\n fragment pluginFrontendFull on PluginFrontend {\n ...pluginMeta\n entrypoint\n style\n data\n backend {\n ...pluginBackendMeta\n }\n}\n \n\n fragment pluginMeta on Plugin {\n __typename\n id\n name\n enabled\n manifestId\n package {\n id\n }\n}\n \n\n fragment pluginBackendMeta on PluginBackend {\n __typename\n id\n}\n \n\n fragment pluginBackendFull on PluginBackend {\n ...pluginMeta\n runtime\n state {\n error\n running\n }\n}\n ";
13850
13874
  export declare const DeletedPluginPackageDocument = "\n subscription deletedPluginPackage {\n deletedPluginPackage {\n deletedPackageId\n }\n}\n ";
13851
13875
  export declare const UpdatedPluginDocument = "\n subscription updatedPlugin {\n updatedPlugin {\n plugin {\n ... on PluginFrontend {\n ...pluginFrontendFull\n }\n ... on PluginBackend {\n ...pluginBackendFull\n }\n }\n }\n}\n \n fragment pluginFrontendFull on PluginFrontend {\n ...pluginMeta\n entrypoint\n style\n data\n backend {\n ...pluginBackendMeta\n }\n}\n \n\n fragment pluginMeta on Plugin {\n __typename\n id\n name\n enabled\n manifestId\n package {\n id\n }\n}\n \n\n fragment pluginBackendMeta on PluginBackend {\n __typename\n id\n}\n \n\n fragment pluginBackendFull on PluginBackend {\n ...pluginMeta\n runtime\n state {\n error\n running\n }\n}\n ";
13876
+ export declare const CreatedPluginEventDocument = "\n subscription createdPluginEvent {\n createdPluginEvent {\n pluginId\n eventArgs\n eventName\n }\n}\n ";
13852
13877
  export declare const CreatedProjectDocument = "\n subscription createdProject {\n createdProject {\n project {\n ...projectFull\n }\n }\n}\n \n fragment projectFull on Project {\n __typename\n id\n name\n path\n version\n status\n size\n createdAt\n updatedAt\n backups {\n id\n }\n}\n ";
13853
13878
  export declare const UpdatedProjectDocument = "\n subscription updatedProject {\n updatedProject {\n project {\n ...projectFull\n }\n }\n}\n \n fragment projectFull on Project {\n __typename\n id\n name\n path\n version\n status\n size\n createdAt\n updatedAt\n backups {\n id\n }\n}\n ";
13854
13879
  export declare const DeletedProjectDocument = "\n subscription deletedProject {\n deletedProject {\n deletedProjectId\n }\n}\n ";
@@ -14078,6 +14103,7 @@ export declare function getSdk<C>(requester: Requester<C>): {
14078
14103
  createdPluginPackage(variables?: CreatedPluginPackageSubscriptionVariables, options?: C): AsyncIterable<CreatedPluginPackageSubscription>;
14079
14104
  deletedPluginPackage(variables?: DeletedPluginPackageSubscriptionVariables, options?: C): AsyncIterable<DeletedPluginPackageSubscription>;
14080
14105
  updatedPlugin(variables?: UpdatedPluginSubscriptionVariables, options?: C): AsyncIterable<UpdatedPluginSubscription>;
14106
+ createdPluginEvent(variables?: CreatedPluginEventSubscriptionVariables, options?: C): AsyncIterable<CreatedPluginEventSubscription>;
14081
14107
  createdProject(variables?: CreatedProjectSubscriptionVariables, options?: C): AsyncIterable<CreatedProjectSubscription>;
14082
14108
  updatedProject(variables?: UpdatedProjectSubscriptionVariables, options?: C): AsyncIterable<UpdatedProjectSubscription>;
14083
14109
  deletedProject(variables?: DeletedProjectSubscriptionVariables, options?: C): AsyncIterable<DeletedProjectSubscription>;
@@ -1,4 +1,20 @@
1
- export type BackendAPI = Record<string, (...args: any[]) => any>;
2
- export type ToBackendRPC<T extends BackendAPI> = {
3
- [K in keyof T]: (...args: Parameters<T[K]>) => ReturnType<T[K]> extends Promise<infer U> ? Promise<U> : Promise<ReturnType<T[K]>>;
1
+ import type { PromisifiedReturnType } from "./utils";
2
+ export type BackendEndpoints = {
3
+ [key: string]: (...args: any[]) => any;
4
+ };
5
+ export type BackendEvents = {
6
+ [key: string]: (...args: any[]) => void;
7
+ };
8
+ export type ToBackendRPC<T extends BackendEndpoints, E extends BackendEvents> = {
9
+ [K in keyof T]: (...args: Parameters<T[K]>) => PromisifiedReturnType<T[K]>;
10
+ } & {
11
+ /**
12
+ * Subscribe to a backend event.
13
+ * @param event The event to subscribe to.
14
+ * @param callback The callback to call when the event is emitted.
15
+ * @returns An object with a `stop` method that can be called to stop listening to the event.
16
+ */
17
+ onEvent: <K extends keyof E>(event: K, callback: E[K]) => {
18
+ stop: () => void;
19
+ };
4
20
  };
@@ -1,17 +1,19 @@
1
- export type Commands = {
2
- register: (id: string, options: CommandOptions) => void;
3
- };
4
- type CommandOptions = {
5
- name: string;
6
- run: (context: CommandContext) => void;
7
- group?: string;
8
- when?: (context: CommandContext) => boolean;
9
- };
1
+ export type CommandContext = CommandContextBase | CommandContextRequestRow | CommandContextRequest | CommandContextResponse;
2
+ /**
3
+ * The base context for a command.
4
+ * This context is used for commands that are not executed in a specific context, such as via shortcuts and the command palette.
5
+ */
10
6
  type CommandContextBase = {
11
7
  type: "BaseContext";
12
8
  };
9
+ /**
10
+ * The context for a command that is executed on a row in the request table.
11
+ */
13
12
  type CommandContextRequestRow = {
14
13
  type: "RequestRowContext";
14
+ /**
15
+ * The requests that are selected in the request table.
16
+ */
15
17
  requests: {
16
18
  id: string;
17
19
  host: string;
@@ -21,8 +23,14 @@ type CommandContextRequestRow = {
21
23
  isTls: boolean;
22
24
  }[];
23
25
  };
26
+ /**
27
+ * The context for a command that is executed on a request pane.
28
+ */
24
29
  type CommandContextRequest = {
25
30
  type: "RequestContext";
31
+ /**
32
+ * The request that is currently open in the request pane.
33
+ */
26
34
  request: {
27
35
  host: string;
28
36
  port: number;
@@ -31,10 +39,19 @@ type CommandContextRequest = {
31
39
  isTls: boolean;
32
40
  raw: string;
33
41
  };
42
+ /**
43
+ * The currently selected text in the request pane.
44
+ */
34
45
  selection: string;
35
46
  };
47
+ /**
48
+ * The context for a command that is executed on a response pane.
49
+ */
36
50
  type CommandContextResponse = {
37
51
  type: "ResponseContext";
52
+ /**
53
+ * The request that is associated with the response.
54
+ */
38
55
  request: {
39
56
  id: string;
40
57
  host: string;
@@ -43,13 +60,18 @@ type CommandContextResponse = {
43
60
  query: string;
44
61
  isTls: boolean;
45
62
  };
63
+ /**
64
+ * The response that is currently open in the response pane.
65
+ */
46
66
  response: {
47
67
  id: string;
48
68
  raw: string;
49
69
  statusCode: number;
50
70
  roundtripTime: number;
51
71
  };
72
+ /**
73
+ * The currently selected text in the response pane.
74
+ */
52
75
  selection: string;
53
76
  };
54
- export type CommandContext = CommandContextBase | CommandContextRequestRow | CommandContextRequest | CommandContextResponse;
55
77
  export {};
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Generic editor interface.
3
+ */
4
+ export type Editor = {
5
+ /**
6
+ * Get the currently selected text of the editor.
7
+ */
8
+ getSelectedText: () => string;
9
+ /**
10
+ * Replace the currently selected text of the editor.
11
+ * @param text The text to replace the selection with.
12
+ */
13
+ replaceSelectedText: (text: string) => void;
14
+ /**
15
+ * Check whether the editor is read-only.
16
+ * @returns Whether the editor is read-only.
17
+ */
18
+ isReadOnly: () => boolean;
19
+ /**
20
+ * Focus the editor.
21
+ */
22
+ focus: () => void;
23
+ };
@@ -1,18 +1,29 @@
1
- export type Findings = {
2
- createFinding: (requestId: string, options: CreateFindingsOptions) => Promise<Finding | undefined>;
3
- };
4
- type Finding = {
1
+ /**
2
+ * Represents a finding.
3
+ */
4
+ export type Finding = {
5
+ /**
6
+ * The ID of the finding.
7
+ */
5
8
  id: string;
9
+ /**
10
+ * The title of the finding.
11
+ */
6
12
  title: string;
13
+ /**
14
+ * The description of the finding.
15
+ */
7
16
  description?: string;
17
+ /**
18
+ * The reporter of the finding.
19
+ */
8
20
  reporter: string;
21
+ /**
22
+ * The host of the request attached to this finding
23
+ */
9
24
  host: string;
25
+ /**
26
+ * The path of the request attached to this finding
27
+ */
10
28
  path: string;
11
29
  };
12
- type CreateFindingsOptions = {
13
- title: string;
14
- description?: string;
15
- reporter: string;
16
- dedupeKey?: string;
17
- };
18
- export {};
@@ -1,40 +1,261 @@
1
1
  import type { Sdk } from "./__generated__/graphql-sdk";
2
- import type { BackendAPI, ToBackendRPC } from "./backend";
3
- import type { Commands } from "./commands";
4
- import type { Findings } from "./findings";
5
- import type { Menu } from "./menu";
6
- import type { Navigation } from "./navigation";
7
- import type { Scopes } from "./scopes";
8
- import type { Storage } from "./storage";
9
- import type { UI } from "./ui";
10
- import type { Window } from "./window";
2
+ import type { BackendEndpoints, BackendEvents, ToBackendRPC } from "./backend";
3
+ import type { CommandContext } from "./commands";
4
+ import type { Editor } 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";
11
10
  export type { CommandContext } from "./commands";
12
- export type API<T extends BackendAPI = Record<string, never>> = {
13
- ui: UI;
14
- backend: ToBackendRPC<T>;
15
- scopes: Scopes;
16
- findings: Findings;
17
- commands: Commands;
18
- menu: Menu;
19
- navigation: Navigation;
20
- window: Window;
21
- storage: Storage;
11
+ export type { MenuItem } from "./menu";
12
+ export type API<T extends BackendEndpoints = Record<string, never>, E extends BackendEvents = Record<string, never>> = {
13
+ graphql: Sdk;
14
+ backend: ToBackendRPC<T, E>;
15
+ /**
16
+ * Utilities to create UI components.
17
+ */
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
+ /**
64
+ * Utilities to interact with scopes
65
+ */
66
+ scopes: {
67
+ /**
68
+ * Get all scopes.
69
+ * @returns A list of scopes.
70
+ */
71
+ getScopes: () => Scope[];
72
+ /**
73
+ * Create a scope.
74
+ * @param options Options for the scope.
75
+ * @param options.name The name of the scope.
76
+ * @param options.allowlist The list of included items in the scope.
77
+ * @param options.denylist The list of excluded items in the scope.
78
+ * @returns The created scope.
79
+ */
80
+ createScope: (options: {
81
+ name: string;
82
+ allowlist: string[];
83
+ denylist: string[];
84
+ }) => Promise<Scope | undefined>;
85
+ /**
86
+ * Update a scope.
87
+ * @param id The id of the scope to update.
88
+ * @param options Options for the scope.
89
+ * @param options.name The name of the scope.
90
+ * @param options.allowlist The list of included items in the scope.
91
+ * @param options.denylist The list of excluded items in the scope.
92
+ * @returns The updated scope.
93
+ */
94
+ updateScope: (id: string, options: {
95
+ name?: string;
96
+ allowlist?: string[];
97
+ denylist?: string[];
98
+ }) => Promise<Scope | undefined>;
99
+ /**
100
+ * Delete a scope.
101
+ * @param id The id of the scope to delete.
102
+ * @returns Whether the scope was deleted.
103
+ */
104
+ deleteScope: (id: string) => Promise<boolean>;
105
+ };
106
+ /**
107
+ * Utilities to interact with findings
108
+ */
109
+ findings: {
110
+ /**
111
+ * Create a finding.
112
+ * @param requestId The id of the request the finding is associated with.
113
+ * @param options Options for the finding.
114
+ * @param options.title The title of the finding.
115
+ * @param options.description The description of the finding.
116
+ * @param options.reporter The reporter of the finding.
117
+ * @param options.dedupeKey The dedupe key of the finding.
118
+ * @returns The created finding.
119
+ */
120
+ createFinding: (requestId: string, options: {
121
+ title: string;
122
+ description?: string;
123
+ reporter: string;
124
+ dedupeKey?: string;
125
+ }) => Promise<Finding | undefined>;
126
+ };
127
+ /**
128
+ * Utilities to interact with commands
129
+ */
130
+ commands: {
131
+ /**
132
+ * Register a command.
133
+ * @param id The id of the command.
134
+ * @param options Options for the command.
135
+ * @param options.name The name of the command.
136
+ * @param options.run The function to run when the command is executed.
137
+ * @param options.group The group this command belongs to.
138
+ * @param options.when A function to determine if the command is available.
139
+ */
140
+ register: (id: string, options: {
141
+ name: string;
142
+ run: (context: CommandContext) => void;
143
+ group?: string;
144
+ when?: (context: CommandContext) => boolean;
145
+ }) => void;
146
+ };
147
+ /**
148
+ * Utilities to insert menu items and context-menus throughout the UI.
149
+ */
150
+ menu: {
151
+ /**
152
+ * Register a menu item.
153
+ * @param item The menu item to register.
154
+ */
155
+ registerItem: (item: MenuItem) => void;
156
+ };
157
+ /**
158
+ * Utilities to interact with navigation.
159
+ */
160
+ navigation: {
161
+ /**
162
+ * Navigate to a path.
163
+ * @param path The path to navigate to.
164
+ */
165
+ goTo: (path: string) => void;
166
+ /**
167
+ * Add a page to the navigation.
168
+ * @param path The path of the page.
169
+ * @param options Options for the page.
170
+ * @param options.body The body of the page.
171
+ * @param options.topbar The topbar of the page.
172
+ */
173
+ addPage: (path: string, options: {
174
+ body: HTMLElement;
175
+ topbar?: HTMLElement;
176
+ }) => void;
177
+ };
178
+ /**
179
+ * Utilities to interact with the active page.
180
+ */
181
+ window: {
182
+ /**
183
+ * Get the active editor.
184
+ * @returns The active editor.
185
+ */
186
+ getActiveEditor: () => Editor | undefined;
187
+ /**
188
+ * Show a toast message.
189
+ * @param message The message to show.
190
+ * @param options Options for the toast message.
191
+ * @param options.variant The variant of the toast message.
192
+ * @param options.duration The duration of the toast message in milliseconds.
193
+ */
194
+ showToast: (message: string, options?: {
195
+ variant?: "success" | "error" | "warning" | "info";
196
+ duration?: number;
197
+ }) => void;
198
+ };
199
+ /**
200
+ * Utilities to interact with frontend-plugin storage.
201
+ */
202
+ storage: {
203
+ /**
204
+ * Get the storage.
205
+ * @returns The storage.
206
+ */
207
+ get: () => JSONValue;
208
+ /**
209
+ * Set the storage.
210
+ * @param value The value to set the storage to
211
+ * @returns A promise that resolves when the storage has been set.
212
+ */
213
+ set: <T>(value: JSONCompatible<T>) => Promise<void>;
214
+ /**
215
+ * Subscribe to storage changes.
216
+ * @param callback The callback to call when the storage changes.
217
+ */
218
+ onChange: (callback: (value: JSONValue) => void) => void;
219
+ };
220
+ /**
221
+ * Utilities to interact with shortcuts.
222
+ */
22
223
  shortcuts: {
224
+ /**
225
+ * Register a shortcut.
226
+ * @param commandId The id of the command to run when the shortcut is triggered.
227
+ * @param keys The keys of the shortcut.
228
+ */
23
229
  register: (commandId: string, keys: string[]) => void;
24
230
  };
231
+ /**
232
+ * Utilities to interact with the command palette.
233
+ */
25
234
  commandPalette: {
235
+ /**
236
+ * Register a command.
237
+ * @param commandId The id of the command to register.
238
+ */
26
239
  register: (commandId: string) => void;
27
240
  };
241
+ /**
242
+ * Utilities to interact with the sidebar.
243
+ */
28
244
  sidebar: {
29
- registerItem: (name: string, path: string, options?: SidebarItemOptions) => SidebarItem;
245
+ /**
246
+ * Register a sidebar item.
247
+ * @param name The name of the sidebar item.
248
+ * @param path The path that the user will be navigated to when the sidebar item is clicked.
249
+ * @param options Options for the sidebar item.
250
+ * @param options.icon The icon of the sidebar item.
251
+ * @param options.group The group the sidebar item belongs to.
252
+ * @param options.isExternal Whether the path points to an external URL.
253
+ * @returns The created sidebar item.
254
+ */
255
+ registerItem: (name: string, path: string, options?: {
256
+ icon?: string;
257
+ group?: string;
258
+ isExternal?: boolean;
259
+ }) => SidebarItem;
30
260
  };
31
- graphql: Sdk;
32
- };
33
- type SidebarItemOptions = {
34
- icon?: string;
35
- group?: string;
36
- isExternal?: boolean;
37
- };
38
- type SidebarItem = {
39
- setCount: (count: number) => void;
40
261
  };
@@ -1,26 +1,62 @@
1
- export type Menu = {
2
- registerItem: (item: MenuItem) => void;
3
- };
4
- type MenuItem = RequestRowMenuItem | SettingsMenuItem | RequestMenuItem | ResponseMenuItem;
1
+ export type MenuItem = RequestRowMenuItem | SettingsMenuItem | RequestMenuItem | ResponseMenuItem;
2
+ /**
3
+ * A context-menu item that appears when right-clicking a request row.
4
+ */
5
5
  type RequestRowMenuItem = {
6
6
  type: "RequestRow";
7
+ /**
8
+ * The command ID to execute when the menu item is clicked.
9
+ */
7
10
  commandId: string;
11
+ /**
12
+ * The icon to display to the left of the menu item.
13
+ */
8
14
  leadingIcon?: string;
9
15
  };
16
+ /**
17
+ * A context-menu item that appears when right-clicking a request pane.
18
+ */
10
19
  type RequestMenuItem = {
11
20
  type: "Request";
21
+ /**
22
+ * The command ID to execute when the menu item is clicked.
23
+ */
12
24
  commandId: string;
25
+ /**
26
+ * The icon to display to the left of the menu item.
27
+ */
13
28
  leadingIcon?: string;
14
29
  };
30
+ /**
31
+ * A context-menu item that appears when right-clicking a response pane.
32
+ */
15
33
  type ResponseMenuItem = {
16
34
  type: "Response";
35
+ /**
36
+ * The command ID to execute when the menu item is
37
+ */
17
38
  commandId: string;
39
+ /**
40
+ * The icon to display to the left of the menu item.
41
+ */
18
42
  leadingIcon?: string;
19
43
  };
44
+ /**
45
+ * A menu item that appears in the settings menu.
46
+ */
20
47
  type SettingsMenuItem = {
21
48
  type: "Settings";
49
+ /**
50
+ * The label of the menu item.
51
+ */
22
52
  label: string;
53
+ /**
54
+ * The path that the user will be navigated to when the menu item is clicked
55
+ */
23
56
  path: string;
57
+ /**
58
+ * The icon to display to the left of the menu item.
59
+ */
24
60
  leadingIcon?: string;
25
61
  };
26
62
  export {};
@@ -1,23 +1,21 @@
1
- export type Scopes = {
2
- getScopes: () => Scope[];
3
- createScope: (options: CreateScopeOptions) => Promise<Scope | undefined>;
4
- updateScope: (id: string, options: UpdateScopeOptions) => Promise<Scope | undefined>;
5
- deleteScope: (id: string) => Promise<boolean>;
6
- };
7
- type Scope = {
1
+ /**
2
+ * Represents a scope.
3
+ */
4
+ export type Scope = {
5
+ /**
6
+ * The unique ID of the scope.
7
+ */
8
8
  id: string;
9
+ /**
10
+ * The name of the scope.
11
+ */
9
12
  name: string;
13
+ /**
14
+ * The list of included items.
15
+ */
10
16
  allowlist: string[];
17
+ /**
18
+ * The list of excluded items.
19
+ */
11
20
  denylist: string[];
12
21
  };
13
- type CreateScopeOptions = {
14
- name: string;
15
- allowlist: string[];
16
- denylist: string[];
17
- };
18
- type UpdateScopeOptions = {
19
- name?: string;
20
- allowlist?: string[];
21
- denylist?: string[];
22
- };
23
- export {};
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Represents a sidebar item.
3
+ */
4
+ export type SidebarItem = {
5
+ /**
6
+ * Set the value of a notification badge next to the sidebar item.
7
+ * @param count - The number to display in the badge. A value of 0 will hide the badge.
8
+ */
9
+ setCount: (count: number) => void;
10
+ };
@@ -6,4 +6,5 @@ type NotAssignableToJson = bigint | symbol | Function;
6
6
  export type JSONCompatible<T> = unknown extends T ? never : {
7
7
  [P in keyof T]: T[P] extends JSONValue ? T[P] : T[P] extends NotAssignableToJson ? never : JSONCompatible<T[P]>;
8
8
  };
9
+ export type PromisifiedReturnType<T extends (...args: unknown[]) => unknown> = ReturnType<T> extends Promise<infer U> ? Promise<U> : Promise<ReturnType<T>>;
9
10
  export {};