@caido/sdk-frontend 0.56.1-beta.0 → 0.56.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,11 +1,17 @@
|
|
|
1
|
-
import { type BackendEndpoints, type BackendEvents } from "../types/backend";
|
|
1
|
+
import { type BackendEndpoints, type BackendEvents, type BackendSpec } from "../types/backend";
|
|
2
2
|
import type { PromisifiedReturnType } from "../types/utils";
|
|
3
|
+
type ResolvedAPI<T> = T extends {
|
|
4
|
+
api: infer A;
|
|
5
|
+
} ? A : T;
|
|
6
|
+
type ResolvedEvents<T, E> = T extends {
|
|
7
|
+
events: infer A;
|
|
8
|
+
} ? A : E;
|
|
3
9
|
/**
|
|
4
10
|
* Utilities to interact with the backend plugin.
|
|
5
11
|
* @category Backend
|
|
6
12
|
*/
|
|
7
|
-
export type BackendSDK<T extends BackendEndpoints, E extends BackendEvents> = {
|
|
8
|
-
[K in keyof T]: (...args: Parameters<T[K]>) => PromisifiedReturnType<T[K]>;
|
|
13
|
+
export type BackendSDK<T extends BackendEndpoints | BackendSpec, E extends BackendEvents> = {
|
|
14
|
+
[K in keyof ResolvedAPI<T>]: (...args: Parameters<ResolvedAPI<T>[K]>) => PromisifiedReturnType<ResolvedAPI<T>[K]>;
|
|
9
15
|
} & {
|
|
10
16
|
/**
|
|
11
17
|
* Subscribe to a backend event.
|
|
@@ -13,7 +19,8 @@ export type BackendSDK<T extends BackendEndpoints, E extends BackendEvents> = {
|
|
|
13
19
|
* @param callback The callback to call when the event is emitted.
|
|
14
20
|
* @returns An object with a `stop` method that can be called to stop listening to the event.
|
|
15
21
|
*/
|
|
16
|
-
onEvent: <K extends keyof E
|
|
22
|
+
onEvent: <K extends keyof ResolvedEvents<T, E>>(event: K, callback: ResolvedEvents<T, E>[K]) => {
|
|
17
23
|
stop: () => void;
|
|
18
24
|
};
|
|
19
25
|
};
|
|
26
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Sdk as GraphqlSDK } from "../__generated__/graphql-sdk";
|
|
2
2
|
import type { _AnalyticsSDK } from "../private/analytics";
|
|
3
|
-
import { type BackendEndpoints, type BackendEvents } from "../types/backend";
|
|
3
|
+
import { type BackendEndpoints, type BackendEvents, type BackendSpec } from "../types/backend";
|
|
4
4
|
import type { AiSDK } from "./ai";
|
|
5
5
|
import type { AssetsSDK } from "./assets";
|
|
6
6
|
import type { AutomateSDK } from "./automate";
|
|
@@ -36,7 +36,7 @@ import type { WorkflowSDK } from "./workflows";
|
|
|
36
36
|
* Utilities for frontend plugins.
|
|
37
37
|
* @category SDK
|
|
38
38
|
*/
|
|
39
|
-
export type API<T extends BackendEndpoints = Record<string, never>, E extends BackendEvents = Record<string, never>> = {
|
|
39
|
+
export type API<T extends BackendEndpoints | BackendSpec = Record<string, never>, E extends BackendEvents = Record<string, never>> = {
|
|
40
40
|
/**
|
|
41
41
|
* Utilities to interact with the GraphQL API.
|
|
42
42
|
*/
|
|
@@ -12,3 +12,11 @@ export type BackendEndpoints = {
|
|
|
12
12
|
export type BackendEvents = {
|
|
13
13
|
[key: string]: (...args: any[]) => void;
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* A specification for the backend plugin.
|
|
17
|
+
* @category Backend
|
|
18
|
+
*/
|
|
19
|
+
export type BackendSpec = {
|
|
20
|
+
api: BackendEndpoints;
|
|
21
|
+
events: BackendEvents;
|
|
22
|
+
};
|