@caido/sdk-backend 0.1.1 → 0.1.3

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-backend",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Typing for the Caido Backend SDK",
5
5
  "author": "Caido Labs Inc. <dev@caido.io>",
6
6
  "license": "MIT",
package/src/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
+ ///<reference path="types/runtime.d.ts" />
2
+ ///<reference path="types/common.d.ts" />
3
+ ///<reference path="types/typing.d.ts" />
1
4
  export * from "caido:common";
2
- export * from "./types/typing";
5
+ export * from "caido:sdk";
@@ -1,43 +1,58 @@
1
- import { MaybePromise, FindingsSDK, RequestsSDK } from "caido:common";
1
+ declare module "caido:sdk" {
2
+ import { MaybePromise, FindingsSDK, RequestsSDK } from "caido:common";
2
3
 
3
- /**
4
- * The SDK for the API RPC service.
5
- */
6
- export type APISDK = {
7
- /**
8
- * Registers a new backend function for the RPC.
9
- *
10
- * @example
11
- * sdk.api.register("multiply", (a: number, b: number) => {
12
- * return a * b;
13
- * });
14
- */
15
- register(
16
- name: string,
17
- callback: (...args: unknown[]) => MaybePromise<unknown>,
18
- ): void;
19
- };
4
+ export type DefineAPI<
5
+ API extends Record<string, (...args: any[]) => MaybePromise<any>>,
6
+ > = {
7
+ [K in keyof API]: DefineCallback<API[K]>;
8
+ };
9
+
10
+ export type DefineCallback<F> = F extends (
11
+ sdk: SDK,
12
+ ...args: infer A
13
+ ) => infer R
14
+ ? (...args: A) => R
15
+ : "Your callback must respect the format (sdk: SDK, ...args: unknown[]) => MaybePromise<unknown>";
20
16
 
21
- /**
22
- * The SDK object available to all scripts.
23
- */
24
- export type SDK = {
25
- /**
26
- * The console.
27
- *
28
- * This is currently the same as the global `console`.
29
- */
30
- console: Console;
31
- /**
32
- * The SDK for the Findings service.
33
- */
34
- findings: FindingsSDK;
35
17
  /**
36
- * The SDK for the Requests services
18
+ * The SDK for the API RPC service.
37
19
  */
38
- requests: RequestsSDK;
20
+ export type APISDK = {
21
+ /**
22
+ * Registers a new backend function for the RPC.
23
+ *
24
+ * @example
25
+ * sdk.api.register("multiply", (a: number, b: number) => {
26
+ * return a * b;
27
+ * });
28
+ */
29
+ register(
30
+ name: string,
31
+ callback: (sdk: SDK, ...args: any[]) => MaybePromise<any>,
32
+ ): void;
33
+ };
34
+
39
35
  /**
40
- * The SDK for the API RPC service.
36
+ * The SDK object available to all scripts.
41
37
  */
42
- api: APISDK;
43
- };
38
+ export type SDK = {
39
+ /**
40
+ * The console.
41
+ *
42
+ * This is currently the same as the global `console`.
43
+ */
44
+ console: Console;
45
+ /**
46
+ * The SDK for the Findings service.
47
+ */
48
+ findings: FindingsSDK;
49
+ /**
50
+ * The SDK for the Requests services
51
+ */
52
+ requests: RequestsSDK;
53
+ /**
54
+ * The SDK for the API RPC service.
55
+ */
56
+ api: APISDK;
57
+ };
58
+ }