@superblocksteam/sdk 1.4.1 → 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 +21 -14
- package/dist/client.js +198 -79
- package/dist/flag.d.ts +2 -0
- package/dist/flag.js +8 -0
- package/dist/sdk.d.ts +8 -7
- package/dist/sdk.js +16 -8
- 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 +258 -83
- package/src/flag.ts +5 -0
- package/src/sdk.ts +48 -14
- 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,111 @@
|
|
|
1
|
+
export interface UserMeDto {
|
|
2
|
+
user: User;
|
|
3
|
+
organizations: Organization[];
|
|
4
|
+
agents: Agent[];
|
|
5
|
+
flagBootstrap: FlagBootstrap;
|
|
6
|
+
}
|
|
7
|
+
export interface FlagBootstrap {
|
|
8
|
+
"ui.enable-resource-signing"?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export type User = {
|
|
11
|
+
id: string;
|
|
12
|
+
email: string;
|
|
13
|
+
currentOrganizationId: string;
|
|
14
|
+
organizationIds: string[];
|
|
15
|
+
username: string;
|
|
16
|
+
name: string;
|
|
17
|
+
anonymousId: string;
|
|
18
|
+
isAnonymous: boolean;
|
|
19
|
+
isAdmin: boolean;
|
|
20
|
+
metadata: Record<string, unknown>;
|
|
21
|
+
};
|
|
22
|
+
export interface Organization {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
displayName: string;
|
|
26
|
+
agents?: Agent[];
|
|
27
|
+
apiKey: string;
|
|
28
|
+
agentType: AgentType;
|
|
29
|
+
minExternalAgentVersion: string;
|
|
30
|
+
profiles?: Profile[];
|
|
31
|
+
}
|
|
32
|
+
export type Agent = {
|
|
33
|
+
id: string;
|
|
34
|
+
key: string;
|
|
35
|
+
environment: string;
|
|
36
|
+
status: AgentStatus;
|
|
37
|
+
version: string;
|
|
38
|
+
versionExternal: string;
|
|
39
|
+
url: string;
|
|
40
|
+
type: AgentType;
|
|
41
|
+
updated: Date;
|
|
42
|
+
created: Date;
|
|
43
|
+
tags: AgentTags;
|
|
44
|
+
verificationKeyIds?: null | string[];
|
|
45
|
+
signingKeyId?: null | string;
|
|
46
|
+
};
|
|
47
|
+
export declare enum AgentStatus {
|
|
48
|
+
ACTIVE = "Active",
|
|
49
|
+
DISCONNECTED = "Disconnected",
|
|
50
|
+
BROWSER_UNREACHABLE = "Browser Unreachable",
|
|
51
|
+
PENDING_REGISTRATION = "Pending Registration",
|
|
52
|
+
STALE = "Stale"
|
|
53
|
+
}
|
|
54
|
+
export declare enum AgentType {
|
|
55
|
+
MULTITENANT = 0,
|
|
56
|
+
DEDICATED = 1,
|
|
57
|
+
ONPREMISE = 2
|
|
58
|
+
}
|
|
59
|
+
export type AgentTags = Record<string, string[]>;
|
|
60
|
+
export declare class Profile {
|
|
61
|
+
id: string;
|
|
62
|
+
key: string;
|
|
63
|
+
displayName: string;
|
|
64
|
+
description: string;
|
|
65
|
+
type: ProfileType;
|
|
66
|
+
constructor({ id, key, displayName, description, type, }: {
|
|
67
|
+
id: string;
|
|
68
|
+
key: string;
|
|
69
|
+
displayName: string;
|
|
70
|
+
description: string;
|
|
71
|
+
type: ProfileType;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
export declare enum ProfileType {
|
|
75
|
+
RESERVED = "RESERVED",
|
|
76
|
+
CUSTOM = "CUSTOM"
|
|
77
|
+
}
|
|
78
|
+
export type Api = {
|
|
79
|
+
metadata: {
|
|
80
|
+
name: string;
|
|
81
|
+
id: string;
|
|
82
|
+
organization: string;
|
|
83
|
+
timestamps?: {
|
|
84
|
+
created: string;
|
|
85
|
+
updated: string;
|
|
86
|
+
deactivated: boolean;
|
|
87
|
+
};
|
|
88
|
+
creator?: {
|
|
89
|
+
id: string;
|
|
90
|
+
name: string;
|
|
91
|
+
};
|
|
92
|
+
folder?: string;
|
|
93
|
+
};
|
|
94
|
+
blocks?: any[];
|
|
95
|
+
trigger: any;
|
|
96
|
+
signature?: Signature;
|
|
97
|
+
};
|
|
98
|
+
/** A signature, as produced by the agent. */
|
|
99
|
+
export interface Signature {
|
|
100
|
+
/** The id of the key used to sign the data. */
|
|
101
|
+
keyId: string;
|
|
102
|
+
/** The actual signature, in base64. */
|
|
103
|
+
data: string;
|
|
104
|
+
}
|
|
105
|
+
export interface RemoteCommitDto {
|
|
106
|
+
commitId: string;
|
|
107
|
+
remoteCommitId: string;
|
|
108
|
+
remoteCommitDate: Date;
|
|
109
|
+
branchName: string;
|
|
110
|
+
repositoryId: string;
|
|
111
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProfileType = exports.Profile = exports.AgentType = exports.AgentStatus = void 0;
|
|
4
|
+
var AgentStatus;
|
|
5
|
+
(function (AgentStatus) {
|
|
6
|
+
AgentStatus["ACTIVE"] = "Active";
|
|
7
|
+
AgentStatus["DISCONNECTED"] = "Disconnected";
|
|
8
|
+
AgentStatus["BROWSER_UNREACHABLE"] = "Browser Unreachable";
|
|
9
|
+
// TODO: remove PENDING_REGISTRATION after the DB migration
|
|
10
|
+
AgentStatus["PENDING_REGISTRATION"] = "Pending Registration";
|
|
11
|
+
AgentStatus["STALE"] = "Stale";
|
|
12
|
+
})(AgentStatus || (exports.AgentStatus = AgentStatus = {}));
|
|
13
|
+
var AgentType;
|
|
14
|
+
(function (AgentType) {
|
|
15
|
+
AgentType[AgentType["MULTITENANT"] = 0] = "MULTITENANT";
|
|
16
|
+
AgentType[AgentType["DEDICATED"] = 1] = "DEDICATED";
|
|
17
|
+
AgentType[AgentType["ONPREMISE"] = 2] = "ONPREMISE";
|
|
18
|
+
})(AgentType || (exports.AgentType = AgentType = {}));
|
|
19
|
+
class Profile {
|
|
20
|
+
constructor({ id, key, displayName, description, type, }) {
|
|
21
|
+
this.id = id;
|
|
22
|
+
this.key = key;
|
|
23
|
+
this.displayName = displayName;
|
|
24
|
+
this.description = description;
|
|
25
|
+
this.type = type;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.Profile = Profile;
|
|
29
|
+
var ProfileType;
|
|
30
|
+
(function (ProfileType) {
|
|
31
|
+
ProfileType["RESERVED"] = "RESERVED";
|
|
32
|
+
ProfileType["CUSTOM"] = "CUSTOM";
|
|
33
|
+
})(ProfileType || (exports.ProfileType = ProfileType = {}));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./common"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./socket"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./plugin"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./signing"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpenAiPluginId = exports.transcribeAudioToTextTranslateToEnglishTruthyValues = void 0;
|
|
4
|
+
exports.transcribeAudioToTextTranslateToEnglishTruthyValues = [
|
|
5
|
+
"checked",
|
|
6
|
+
"true",
|
|
7
|
+
true,
|
|
8
|
+
];
|
|
9
|
+
exports.OpenAiPluginId = "openai";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Api as ApiPb, Signature } from "./common";
|
|
2
|
+
export type SignatureResponse = {
|
|
3
|
+
signature: Signature;
|
|
4
|
+
};
|
|
5
|
+
export type ApiResource = {
|
|
6
|
+
api: ApiPb;
|
|
7
|
+
};
|
|
8
|
+
export type GenericResource = {
|
|
9
|
+
literal: {
|
|
10
|
+
data: any;
|
|
11
|
+
signature?: Signature;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
interface PageHash {
|
|
15
|
+
/** The version of the page DSL. */
|
|
16
|
+
version: number;
|
|
17
|
+
/** The SHA-256 hash of the page DSL (i.e. `page.layouts[0].dsl`), in base64. */
|
|
18
|
+
hash: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ApplicationSettingsHashes {
|
|
21
|
+
/** The SHA-256 hash of all custom components related properties from settings, in base64. */
|
|
22
|
+
components: string;
|
|
23
|
+
/** The SHA-256 hash of settings without the custom components related properties, in base64. */
|
|
24
|
+
rest: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ApplicationSignatureTree {
|
|
27
|
+
/** The version of the signature tree. */
|
|
28
|
+
v: 1;
|
|
29
|
+
settings: ApplicationSettingsHashes;
|
|
30
|
+
page: PageHash;
|
|
31
|
+
}
|
|
32
|
+
export interface ApplicationSignatureTreeSigned {
|
|
33
|
+
/** The SHA-256 hash of `root`, in base64. */
|
|
34
|
+
signature: Signature;
|
|
35
|
+
root: ApplicationSignatureTree;
|
|
36
|
+
}
|
|
37
|
+
export type AppToSign = {
|
|
38
|
+
rootHash: string;
|
|
39
|
+
};
|
|
40
|
+
export type AppToVerify = {
|
|
41
|
+
rootHash: string;
|
|
42
|
+
signature?: Signature;
|
|
43
|
+
};
|
|
44
|
+
export type ApiToSign = {
|
|
45
|
+
apiPb: ApiPb;
|
|
46
|
+
};
|
|
47
|
+
export type ApiToVerify = {
|
|
48
|
+
apiPb: ApiPb;
|
|
49
|
+
signature?: Signature;
|
|
50
|
+
};
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type MethodHandler<Params, Result, PeerMethods, RequestContext> = (params: Params, peer: ISocketClient<PeerMethods>, ctx: RequestContext) => Promise<Result>;
|
|
2
|
+
export type MiddlewareHandler<Params, PeerMethods, RequestContext> = (params: Params, peerAuthorization: string | undefined, peer: ISocketClient<PeerMethods>, ctx: RequestContext) => Promise<void>;
|
|
3
|
+
export type MethodHandlers<Methods, PeerMethods, RequestContext> = {
|
|
4
|
+
[Key in keyof Methods]: Methods[Key] extends (params: infer Params) => Promise<infer Result> ? [
|
|
5
|
+
...middlewareHandlers: MiddlewareHandler<Params, PeerMethods, RequestContext>[],
|
|
6
|
+
handler: MethodHandler<Params, Result, PeerMethods, RequestContext>
|
|
7
|
+
] : Methods[Key] extends Record<string, unknown> ? MethodHandlers<Methods[Key], PeerMethods, RequestContext> : never;
|
|
8
|
+
};
|
|
9
|
+
type ISocketClientMethodCall<Methods> = {
|
|
10
|
+
[Key in keyof Methods]: Methods[Key] extends (params: infer P) => Promise<infer R> ? (params: P) => Promise<R> : Methods[Key] extends Record<string, unknown> ? ISocketClientMethodCall<Methods[Key]> : never;
|
|
11
|
+
};
|
|
12
|
+
export type ISocketClient<Methods> = {
|
|
13
|
+
close: () => void;
|
|
14
|
+
call: ISocketClientMethodCall<Methods>;
|
|
15
|
+
};
|
|
16
|
+
export type MethodSchema<Params, Response> = (params: Params) => Promise<Response>;
|
|
17
|
+
export {};
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Agent, AgentType, Api } from "./types";
|
|
2
|
+
export declare function getAgentUrls(agents: Agent[], agentType: AgentType): string[];
|
|
3
|
+
export declare const sanitizeV2RequestBody: (apiBody: Record<string, unknown>) => Record<string, unknown>;
|
|
4
|
+
export declare const getSanitizedApi: (api: Api) => any;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSanitizedApi = exports.sanitizeV2RequestBody = exports.getAgentUrls = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
function getAgentUrls(agents, agentType) {
|
|
6
|
+
const filtered = agents.filter((a) => a.type === agentType && a.status === types_1.AgentStatus.ACTIVE);
|
|
7
|
+
return filtered.map((f) => f.url);
|
|
8
|
+
}
|
|
9
|
+
exports.getAgentUrls = getAgentUrls;
|
|
10
|
+
const sanitizeV2RequestBody = (apiBody) => {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
const traverseJSON = (obj) => {
|
|
13
|
+
for (const key in obj) {
|
|
14
|
+
if (key === "step" && obj.step[types_1.OpenAiPluginId]) {
|
|
15
|
+
const value = obj.step[types_1.OpenAiPluginId].transcribeAudioToTextTranslateToEnglish;
|
|
16
|
+
obj.step[types_1.OpenAiPluginId].transcribeAudioToTextTranslateToEnglish =
|
|
17
|
+
types_1.transcribeAudioToTextTranslateToEnglishTruthyValues.includes(value);
|
|
18
|
+
}
|
|
19
|
+
else if (typeof obj[key] === "object") {
|
|
20
|
+
(0, exports.sanitizeV2RequestBody)(obj[key]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
traverseJSON(apiBody);
|
|
25
|
+
return apiBody;
|
|
26
|
+
};
|
|
27
|
+
exports.sanitizeV2RequestBody = sanitizeV2RequestBody;
|
|
28
|
+
const getSanitizedApi = (api) => {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
const sanitizedBlocks = (_b = ((_a = api.blocks) !== null && _a !== void 0 ? _a : [])) === null || _b === void 0 ? void 0 : _b.map((block) => (0, exports.sanitizeV2RequestBody)(block));
|
|
31
|
+
return {
|
|
32
|
+
...api,
|
|
33
|
+
blocks: sanitizedBlocks,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
exports.getSanitizedApi = getSanitizedApi;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superblocksteam/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Superblocks JS SDK",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "Superblocks Community Software License",
|
|
24
24
|
"devDependencies": {
|
|
25
|
+
"@types/ws": "^8.5.10",
|
|
25
26
|
"@typescript-eslint/eslint-plugin": "^5.60.1",
|
|
26
27
|
"@typescript-eslint/parser": "^5.60.1",
|
|
27
28
|
"eslint": "^8.48.0",
|
|
@@ -30,8 +31,9 @@
|
|
|
30
31
|
"typescript": "^5.1.3"
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"@superblocksteam/util": "1.
|
|
34
|
-
"axios": "^1.3.5"
|
|
34
|
+
"@superblocksteam/util": "1.5.0",
|
|
35
|
+
"axios": "^1.3.5",
|
|
36
|
+
"isomorphic-ws": "^5.0.0"
|
|
35
37
|
},
|
|
36
38
|
"homepage": "https://www.superblocks.com",
|
|
37
39
|
"engines": {
|