@superblocksteam/sdk 1.4.2 → 1.5.0
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/.eslintrc.json +3 -0
- package/dist/client.d.ts +5 -4
- package/dist/client.js +140 -44
- package/dist/flag.d.ts +2 -0
- package/dist/flag.js +8 -0
- package/dist/sdk.d.ts +5 -5
- package/dist/socket/handlers.d.ts +105 -0
- package/dist/socket/handlers.js +85 -0
- package/dist/socket/index.d.ts +27 -0
- package/dist/socket/index.js +69 -0
- package/dist/socket/signing.d.ts +13 -0
- package/dist/socket/signing.js +81 -0
- package/dist/socket/socket.d.ts +16 -0
- package/dist/socket/socket.js +157 -0
- package/dist/types/common.d.ts +111 -0
- package/dist/types/common.js +33 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +7 -0
- package/dist/types/plugin.d.ts +2 -0
- package/dist/types/plugin.js +9 -0
- package/dist/types/signing.d.ts +51 -0
- package/dist/types/signing.js +2 -0
- package/dist/types/socket.d.ts +17 -0
- package/dist/types/socket.js +2 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +36 -0
- package/package.json +5 -3
- package/src/client.ts +159 -52
- package/src/flag.ts +5 -0
- package/src/sdk.ts +8 -8
- package/src/socket/handlers.ts +228 -0
- package/src/socket/index.ts +164 -0
- package/src/socket/signing.ts +113 -0
- package/src/socket/socket.ts +253 -0
- package/src/types/common.ts +138 -0
- package/src/types/index.ts +4 -0
- package/src/types/plugin.ts +7 -0
- package/src/types/signing.ts +61 -0
- package/src/types/socket.ts +48 -0
- package/src/utils.ts +45 -0
- package/tsconfig.json +3 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Api as ApiPb, Signature } from "./common";
|
|
2
|
+
|
|
3
|
+
export type SignatureResponse = {
|
|
4
|
+
signature: Signature;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type ApiResource = {
|
|
8
|
+
api: ApiPb;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type GenericResource = {
|
|
12
|
+
literal: {
|
|
13
|
+
data: any;
|
|
14
|
+
signature?: Signature;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
interface PageHash {
|
|
19
|
+
/** The version of the page DSL. */
|
|
20
|
+
version: number;
|
|
21
|
+
/** The SHA-256 hash of the page DSL (i.e. `page.layouts[0].dsl`), in base64. */
|
|
22
|
+
hash: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ApplicationSettingsHashes {
|
|
26
|
+
/** The SHA-256 hash of all custom components related properties from settings, in base64. */
|
|
27
|
+
components: string;
|
|
28
|
+
/** The SHA-256 hash of settings without the custom components related properties, in base64. */
|
|
29
|
+
rest: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ApplicationSignatureTree {
|
|
33
|
+
/** The version of the signature tree. */
|
|
34
|
+
v: 1;
|
|
35
|
+
settings: ApplicationSettingsHashes;
|
|
36
|
+
page: PageHash;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ApplicationSignatureTreeSigned {
|
|
40
|
+
/** The SHA-256 hash of `root`, in base64. */
|
|
41
|
+
signature: Signature;
|
|
42
|
+
root: ApplicationSignatureTree;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type AppToSign = {
|
|
46
|
+
rootHash: string;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type AppToVerify = {
|
|
50
|
+
rootHash: string;
|
|
51
|
+
signature?: Signature;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type ApiToSign = {
|
|
55
|
+
apiPb: ApiPb;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type ApiToVerify = {
|
|
59
|
+
apiPb: ApiPb;
|
|
60
|
+
signature?: Signature;
|
|
61
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export type MethodHandler<Params, Result, PeerMethods, RequestContext> = (
|
|
2
|
+
params: Params,
|
|
3
|
+
peer: ISocketClient<PeerMethods>,
|
|
4
|
+
ctx: RequestContext
|
|
5
|
+
) => Promise<Result>;
|
|
6
|
+
|
|
7
|
+
export type MiddlewareHandler<Params, PeerMethods, RequestContext> = (
|
|
8
|
+
params: Params,
|
|
9
|
+
peerAuthorization: string | undefined,
|
|
10
|
+
peer: ISocketClient<PeerMethods>,
|
|
11
|
+
ctx: RequestContext
|
|
12
|
+
) => Promise<void>;
|
|
13
|
+
|
|
14
|
+
export type MethodHandlers<Methods, PeerMethods, RequestContext> = {
|
|
15
|
+
[Key in keyof Methods]: Methods[Key] extends (
|
|
16
|
+
params: infer Params
|
|
17
|
+
) => Promise<infer Result>
|
|
18
|
+
? [
|
|
19
|
+
...middlewareHandlers: MiddlewareHandler<
|
|
20
|
+
Params,
|
|
21
|
+
PeerMethods,
|
|
22
|
+
RequestContext
|
|
23
|
+
>[],
|
|
24
|
+
handler: MethodHandler<Params, Result, PeerMethods, RequestContext>
|
|
25
|
+
]
|
|
26
|
+
: Methods[Key] extends Record<string, unknown>
|
|
27
|
+
? MethodHandlers<Methods[Key], PeerMethods, RequestContext>
|
|
28
|
+
: never;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type ISocketClientMethodCall<Methods> = {
|
|
32
|
+
[Key in keyof Methods]: Methods[Key] extends (
|
|
33
|
+
params: infer P
|
|
34
|
+
) => Promise<infer R>
|
|
35
|
+
? (params: P) => Promise<R>
|
|
36
|
+
: Methods[Key] extends Record<string, unknown>
|
|
37
|
+
? ISocketClientMethodCall<Methods[Key]>
|
|
38
|
+
: never;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type ISocketClient<Methods> = {
|
|
42
|
+
close: () => void;
|
|
43
|
+
call: ISocketClientMethodCall<Methods>;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type MethodSchema<Params, Response> = (
|
|
47
|
+
params: Params
|
|
48
|
+
) => Promise<Response>;
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Agent,
|
|
3
|
+
AgentStatus,
|
|
4
|
+
AgentType,
|
|
5
|
+
Api,
|
|
6
|
+
OpenAiPluginId,
|
|
7
|
+
transcribeAudioToTextTranslateToEnglishTruthyValues,
|
|
8
|
+
} from "./types";
|
|
9
|
+
|
|
10
|
+
export function getAgentUrls(agents: Agent[], agentType: AgentType): string[] {
|
|
11
|
+
const filtered = agents.filter(
|
|
12
|
+
(a) => a.type === agentType && a.status === AgentStatus.ACTIVE
|
|
13
|
+
);
|
|
14
|
+
return filtered.map((f) => f.url);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const sanitizeV2RequestBody = (
|
|
18
|
+
apiBody: Record<string, unknown>
|
|
19
|
+
): Record<string, unknown> => {
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
const traverseJSON = (obj: any) => {
|
|
22
|
+
for (const key in obj) {
|
|
23
|
+
if (key === "step" && obj.step[OpenAiPluginId]) {
|
|
24
|
+
const value =
|
|
25
|
+
obj.step[OpenAiPluginId].transcribeAudioToTextTranslateToEnglish;
|
|
26
|
+
obj.step[OpenAiPluginId].transcribeAudioToTextTranslateToEnglish =
|
|
27
|
+
transcribeAudioToTextTranslateToEnglishTruthyValues.includes(value);
|
|
28
|
+
} else if (typeof obj[key] === "object") {
|
|
29
|
+
sanitizeV2RequestBody(obj[key]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
traverseJSON(apiBody);
|
|
34
|
+
return apiBody;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const getSanitizedApi = (api: Api): any => {
|
|
38
|
+
const sanitizedBlocks = (api.blocks ?? [])?.map(
|
|
39
|
+
(block: Record<string, unknown>) => sanitizeV2RequestBody(block)
|
|
40
|
+
);
|
|
41
|
+
return {
|
|
42
|
+
...api,
|
|
43
|
+
blocks: sanitizedBlocks,
|
|
44
|
+
};
|
|
45
|
+
};
|