@caido/sdk-frontend 0.55.4-beta.7 → 0.55.4-beta.8

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.55.4-beta.7",
3
+ "version": "0.55.4-beta.8",
4
4
  "description": "Typing for the Caido Frontend SDK",
5
5
  "author": "Caido Labs Inc. <dev@caido.io>",
6
6
  "repository": "https://github.com/caido/sdk-js/",
@@ -1,19 +1,31 @@
1
1
  import { type BackendEndpoints, type BackendEvents } from "../types/backend";
2
2
  import type { PromisifiedReturnType } from "../types/utils";
3
+
4
+ type ResolvedAPI<T> = T extends { api: infer A } ? A : T;
5
+ type ResolvedEvents<T, Events> = T extends { events: infer A } ? A : Events;
6
+
3
7
  /**
4
8
  * Utilities to interact with the backend plugin.
5
9
  * @category Backend
6
10
  */
7
- export type BackendSDK<T extends BackendEndpoints, E extends BackendEvents> = {
8
- [K in keyof T]: (...args: Parameters<T[K]>) => PromisifiedReturnType<T[K]>;
11
+ export type BackendSDK<
12
+ T extends ResolvedAPI<BackendEndpoints>,
13
+ E extends BackendEvents,
14
+ > = {
15
+ [K in keyof ResolvedAPI<T>]: (
16
+ ...args: Parameters<ResolvedAPI<T>[K]>
17
+ ) => PromisifiedReturnType<ResolvedAPI<T>[K]>;
9
18
  } & {
10
- /**
11
- * Subscribe to a backend event.
12
- * @param event The event to subscribe to.
13
- * @param callback The callback to call when the event is emitted.
14
- * @returns An object with a `stop` method that can be called to stop listening to the event.
15
- */
16
- onEvent: <K extends keyof E>(event: K, callback: E[K]) => {
17
- stop: () => void;
18
- };
19
+ /**
20
+ * Subscribe to a backend event.
21
+ * @param event The event to subscribe to.
22
+ * @param callback The callback to call when the event is emitted.
23
+ * @returns An object with a `stop` method that can be called to stop listening to the event.
24
+ */
25
+ onEvent: <K extends keyof ResolvedEvents<T, E>>(
26
+ event: K,
27
+ callback: ResolvedEvents<T, E>[K],
28
+ ) => {
29
+ stop: () => void;
30
+ };
19
31
  };