@superblocksteam/sdk 1.14.2 → 2.0.3-next.50
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/.mocharc.json +7 -0
- package/.prettierrc +18 -0
- package/dist/cli-replacement/dev.d.mts +19 -0
- package/dist/cli-replacement/dev.d.mts.map +1 -0
- package/dist/cli-replacement/dev.mjs +122 -0
- package/dist/cli-replacement/dev.mjs.map +1 -0
- package/dist/cli-replacement/init.d.ts +14 -0
- package/dist/cli-replacement/init.d.ts.map +1 -0
- package/dist/cli-replacement/init.js +26 -0
- package/dist/cli-replacement/init.js.map +1 -0
- package/dist/client.d.ts +31 -17
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +137 -155
- package/dist/client.js.map +1 -0
- package/dist/dbfs/client.d.ts +6 -0
- package/dist/dbfs/client.d.ts.map +1 -0
- package/dist/dbfs/client.js +117 -0
- package/dist/dbfs/client.js.map +1 -0
- package/dist/dbfs/local.d.ts +15 -0
- package/dist/dbfs/local.d.ts.map +1 -0
- package/dist/dbfs/local.js +126 -0
- package/dist/dbfs/local.js.map +1 -0
- package/dist/dev-utils/custom-build.d.mts +4 -0
- package/dist/dev-utils/custom-build.d.mts.map +1 -0
- package/dist/dev-utils/custom-build.mjs +99 -0
- package/dist/dev-utils/custom-build.mjs.map +1 -0
- package/dist/dev-utils/custom-config.d.mts +2 -0
- package/dist/dev-utils/custom-config.d.mts.map +1 -0
- package/dist/dev-utils/custom-config.mjs +57 -0
- package/dist/dev-utils/custom-config.mjs.map +1 -0
- package/dist/dev-utils/dev-logger.d.mts +8 -0
- package/dist/dev-utils/dev-logger.d.mts.map +1 -0
- package/dist/dev-utils/dev-logger.mjs +25 -0
- package/dist/dev-utils/dev-logger.mjs.map +1 -0
- package/dist/dev-utils/dev-server.d.mts +18 -0
- package/dist/dev-utils/dev-server.d.mts.map +1 -0
- package/dist/dev-utils/dev-server.mjs +265 -0
- package/dist/dev-utils/dev-server.mjs.map +1 -0
- package/dist/dev-utils/dev-tracer.d.ts +3 -0
- package/dist/dev-utils/dev-tracer.d.ts.map +1 -0
- package/dist/dev-utils/dev-tracer.js +28 -0
- package/dist/dev-utils/dev-tracer.js.map +1 -0
- package/dist/dev-utils/vite-plugin-dd-rum.d.mts +10 -0
- package/dist/dev-utils/vite-plugin-dd-rum.d.mts.map +1 -0
- package/dist/dev-utils/vite-plugin-dd-rum.mjs +34 -0
- package/dist/dev-utils/vite-plugin-dd-rum.mjs.map +1 -0
- package/dist/dev-utils/vite-plugin-react-transform.d.mts +7 -0
- package/dist/dev-utils/vite-plugin-react-transform.d.mts.map +1 -0
- package/dist/dev-utils/vite-plugin-react-transform.mjs +110 -0
- package/dist/dev-utils/vite-plugin-react-transform.mjs.map +1 -0
- package/dist/dev-utils/vite-plugin-sb-cdn.d.mts +34 -0
- package/dist/dev-utils/vite-plugin-sb-cdn.d.mts.map +1 -0
- package/dist/dev-utils/vite-plugin-sb-cdn.mjs +720 -0
- package/dist/dev-utils/vite-plugin-sb-cdn.mjs.map +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +4 -9
- package/dist/errors.js.map +1 -0
- package/dist/flag.d.ts +2 -2
- package/dist/flag.d.ts.map +1 -0
- package/dist/flag.js +5 -9
- package/dist/flag.js.map +1 -0
- package/dist/index.d.ts +10 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -20
- package/dist/index.js.map +1 -0
- package/dist/sdk.d.ts +42 -18
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +47 -43
- package/dist/sdk.js.map +1 -0
- package/dist/socket/handlers.d.ts +3 -128
- package/dist/socket/handlers.d.ts.map +1 -0
- package/dist/socket/handlers.js +7 -9
- package/dist/socket/handlers.js.map +1 -0
- package/dist/socket/index.d.ts +4 -3
- package/dist/socket/index.d.ts.map +1 -0
- package/dist/socket/index.js +12 -21
- package/dist/socket/index.js.map +1 -0
- package/dist/socket/signing.d.ts +3 -1
- package/dist/socket/signing.d.ts.map +1 -0
- package/dist/socket/signing.js +8 -17
- package/dist/socket/signing.js.map +1 -0
- package/dist/socket/socket.d.ts +3 -2
- package/dist/socket/socket.d.ts.map +1 -0
- package/dist/socket/socket.js +9 -19
- package/dist/socket/socket.js.map +1 -0
- package/dist/types/common.d.ts +2 -103
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +8 -24
- package/dist/types/common.js.map +1 -0
- package/dist/types/index.d.ts +5 -4
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -20
- package/dist/types/index.js.map +1 -0
- package/dist/types/plugin.d.ts +1 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/plugin.js +3 -5
- package/dist/types/plugin.js.map +1 -0
- package/dist/types/signing.d.ts +2 -1
- package/dist/types/signing.d.ts.map +1 -0
- package/dist/types/signing.js +2 -2
- package/dist/types/signing.js.map +1 -0
- package/dist/types/socket.d.ts +1 -0
- package/dist/types/socket.d.ts.map +1 -0
- package/dist/types/socket.js +2 -5
- package/dist/types/socket.js.map +1 -0
- package/dist/utils.d.ts +3 -1
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +14 -23
- package/dist/utils.js.map +1 -0
- package/dist/version-control.d.mts +59 -0
- package/dist/version-control.d.mts.map +1 -0
- package/dist/version-control.mjs +899 -0
- package/dist/version-control.mjs.map +1 -0
- package/eslint.config.js +85 -0
- package/package.json +72 -32
- package/src/cli-replacement/dev.mts +182 -0
- package/src/cli-replacement/init.ts +47 -0
- package/src/client.ts +114 -38
- package/src/dbfs/client.ts +162 -0
- package/src/dbfs/local.ts +163 -0
- package/src/dev-utils/custom-build.mts +113 -0
- package/src/dev-utils/custom-config.mts +66 -0
- package/src/dev-utils/dev-logger.mts +39 -0
- package/src/dev-utils/dev-server.mts +342 -0
- package/src/dev-utils/dev-tracer.ts +31 -0
- package/src/dev-utils/vite-plugin-dd-rum.mts +47 -0
- package/src/dev-utils/vite-plugin-react-transform.mts +130 -0
- package/src/dev-utils/vite-plugin-sb-cdn.mts +988 -0
- package/src/flag.ts +2 -3
- package/src/index.ts +119 -4
- package/src/sdk.ts +91 -17
- package/src/socket/handlers.ts +9 -147
- package/src/socket/index.ts +6 -9
- package/src/socket/signing.ts +7 -8
- package/src/socket/socket.ts +8 -9
- package/src/types/common.ts +2 -119
- package/src/types/index.ts +4 -4
- package/src/types/signing.ts +1 -1
- package/src/types/socket.ts +1 -1
- package/src/utils.ts +5 -6
- package/src/version-control.mts +1351 -0
- package/test/dev-utils/fixture/index.html +12 -0
- package/test/dev-utils/fixture/main.jsx +22 -0
- package/test/dev-utils/fixture/package-lock.json +25 -0
- package/test/dev-utils/fixture/package.json +9 -0
- package/test/dev-utils/vite-plugin-sb-cdn.test.mts +74 -0
- package/test/tsconfig.json +9 -0
- package/test/version-control.test.mts +1412 -0
- package/tsconfig.json +15 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/.eslintrc.json +0 -55
package/src/flag.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DEFAULT_LINES_FOR_LARGE_STEPS } from "@superblocksteam/util";
|
|
2
|
+
import type { FlagBootstrap } from "./types/index.js";
|
|
2
3
|
|
|
3
4
|
export const signingEnabled = (flags: FlagBootstrap): boolean => {
|
|
4
5
|
return flags["ui.enable-resource-signing"] ?? false;
|
|
5
6
|
};
|
|
6
7
|
|
|
7
|
-
export const DEFAULT_LINES_FOR_LARGE_STEPS = 1;
|
|
8
|
-
|
|
9
8
|
export class FeatureFlags {
|
|
10
9
|
constructor(private flags: FlagBootstrap) {}
|
|
11
10
|
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,119 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export {
|
|
2
|
+
createSocketConnectionIfNeeded,
|
|
3
|
+
fetchApi,
|
|
4
|
+
fetchApiCommits,
|
|
5
|
+
fetchApis,
|
|
6
|
+
fetchApplication,
|
|
7
|
+
fetchApplicationBranches,
|
|
8
|
+
fetchApplicationCommits,
|
|
9
|
+
fetchApplicationWithComponents,
|
|
10
|
+
fetchApplications,
|
|
11
|
+
fetchCurrentUser,
|
|
12
|
+
pushApi,
|
|
13
|
+
pushApplication,
|
|
14
|
+
registerComponents,
|
|
15
|
+
uploadComponents,
|
|
16
|
+
validateGitSetup,
|
|
17
|
+
uploadApplication,
|
|
18
|
+
type ApplicationWrapper,
|
|
19
|
+
type Branch,
|
|
20
|
+
type Branches,
|
|
21
|
+
type CodeModeApplicationWrapper,
|
|
22
|
+
type CommitDto,
|
|
23
|
+
type GetCommitsResponseBody,
|
|
24
|
+
type MultiPageApplicationWrapper,
|
|
25
|
+
type MultiPageApplicationWrapperWithComponents,
|
|
26
|
+
type PushApiWithCommitConfig,
|
|
27
|
+
type PushMultiPageApplicationWithCommitConfig,
|
|
28
|
+
type UploadFile,
|
|
29
|
+
} from "./client.js";
|
|
30
|
+
|
|
31
|
+
export { signingEnabled, FeatureFlags } from "./flag.js";
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
BranchNotCheckedOutError,
|
|
35
|
+
CommitAlreadyExistsError,
|
|
36
|
+
SuperblocksSdk,
|
|
37
|
+
ValidateGitSetupError,
|
|
38
|
+
} from "./sdk.js";
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
AgentStatus,
|
|
42
|
+
AgentType,
|
|
43
|
+
OpenAiPluginId,
|
|
44
|
+
Profile,
|
|
45
|
+
ProfileType,
|
|
46
|
+
SocketErrorException,
|
|
47
|
+
transcribeAudioToTextTranslateToEnglishTruthyValues,
|
|
48
|
+
type Agent,
|
|
49
|
+
type AgentTags,
|
|
50
|
+
type ApiResource,
|
|
51
|
+
type ApiToSign,
|
|
52
|
+
type ApiToVerify,
|
|
53
|
+
type ApiWithPb,
|
|
54
|
+
type AppToSign,
|
|
55
|
+
type AppToVerify,
|
|
56
|
+
type ApplicationSettingsHashes,
|
|
57
|
+
type ApplicationSignatureTree,
|
|
58
|
+
type ApplicationSignatureTreeSigned,
|
|
59
|
+
type FlagBootstrap,
|
|
60
|
+
type GenericMiddleware,
|
|
61
|
+
type GenericResource,
|
|
62
|
+
type ISocketClient,
|
|
63
|
+
type MethodHandler,
|
|
64
|
+
type MethodHandlers,
|
|
65
|
+
type MethodSchema,
|
|
66
|
+
type NonEmptyArray,
|
|
67
|
+
type Organization,
|
|
68
|
+
type Page,
|
|
69
|
+
type RemoteCommitDto,
|
|
70
|
+
type RequestContextBase,
|
|
71
|
+
type SignatureResponse,
|
|
72
|
+
type SocketTimeouts,
|
|
73
|
+
type User,
|
|
74
|
+
type UserMeDto,
|
|
75
|
+
type ViewMode,
|
|
76
|
+
} from "./types/index.js";
|
|
77
|
+
|
|
78
|
+
export {
|
|
79
|
+
DEFAULT_BRANCH,
|
|
80
|
+
DEPLOYED_MODE,
|
|
81
|
+
FileStructureType,
|
|
82
|
+
LATEST_EDITS_MODE,
|
|
83
|
+
MOST_RECENT_COMMIT_MODE,
|
|
84
|
+
MULTI_SELECT_PROMPT_HELP,
|
|
85
|
+
SELECT_PROMPT_HELP,
|
|
86
|
+
addExistingFilePathsForApi,
|
|
87
|
+
atLeastOneSelection,
|
|
88
|
+
deleteResourcesAndUpdateRootConfig,
|
|
89
|
+
extractApiName,
|
|
90
|
+
getApiRepresentation,
|
|
91
|
+
getCurrentGitBranch,
|
|
92
|
+
getCurrentGitBranchIfGit,
|
|
93
|
+
getFileStructureType,
|
|
94
|
+
getHeadCommit,
|
|
95
|
+
getLocalGitRepoState,
|
|
96
|
+
getMode,
|
|
97
|
+
isCI,
|
|
98
|
+
isGitRepoDirty,
|
|
99
|
+
modeFlagToViewMode,
|
|
100
|
+
modeFlagValuesMap,
|
|
101
|
+
readApiFromDisk,
|
|
102
|
+
readApplicationFromDisk,
|
|
103
|
+
readMultiPageApplicationFromDisk,
|
|
104
|
+
removeResourceFromDisk,
|
|
105
|
+
sortByKey,
|
|
106
|
+
validateLocalResource,
|
|
107
|
+
writeAppApi,
|
|
108
|
+
writeApplicationToDisk,
|
|
109
|
+
writeResourceToDisk,
|
|
110
|
+
type ApiRepresentation,
|
|
111
|
+
type ModeFlag,
|
|
112
|
+
} from "./version-control.mjs";
|
|
113
|
+
|
|
114
|
+
export { createDevServer } from "./dev-utils/dev-server.mjs";
|
|
115
|
+
|
|
116
|
+
export { dev, type ApplicationConfig } from "./cli-replacement/dev.mjs";
|
|
117
|
+
export { fetchAndWriteApplication } from "./cli-replacement/init.js";
|
|
118
|
+
|
|
119
|
+
export { ExportViewMode } from "@superblocksteam/shared";
|
package/src/sdk.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ComponentEvent,
|
|
3
|
-
LocalGitRepoState,
|
|
4
|
-
SuperblocksResourceType,
|
|
5
|
-
} from "@superblocksteam/util";
|
|
1
|
+
import { ExportViewMode } from "@superblocksteam/shared";
|
|
6
2
|
import {
|
|
7
3
|
fetchApi,
|
|
8
4
|
fetchApiCommits,
|
|
@@ -14,20 +10,35 @@ import {
|
|
|
14
10
|
fetchApplicationWithComponents,
|
|
15
11
|
fetchCurrentUser,
|
|
16
12
|
pushApi,
|
|
17
|
-
PushApiWithCommitConfig,
|
|
18
13
|
pushApplication,
|
|
19
|
-
PushMultiPageApplicationWithCommitConfig,
|
|
20
14
|
registerComponents,
|
|
21
15
|
uploadComponents,
|
|
22
16
|
validateGitSetup,
|
|
23
17
|
deployApplication,
|
|
24
18
|
deployApi,
|
|
25
|
-
} from "./client";
|
|
26
|
-
import {
|
|
27
|
-
|
|
19
|
+
} from "./client.js";
|
|
20
|
+
import {
|
|
21
|
+
downloadApplicationDirectory,
|
|
22
|
+
uploadLocalApplication,
|
|
23
|
+
printDirectoryEntries,
|
|
24
|
+
printFileContents,
|
|
25
|
+
getApplicationDirectoryHash,
|
|
26
|
+
} from "./dbfs/client.js";
|
|
27
|
+
import { hashLocalDirectory } from "./dbfs/local.js";
|
|
28
|
+
import { FeatureFlags } from "./flag.js";
|
|
29
|
+
import type {
|
|
30
|
+
PushApiWithCommitConfig,
|
|
31
|
+
PushMultiPageApplicationWithCommitConfig,
|
|
32
|
+
} from "./client.js";
|
|
33
|
+
import type { UserMeDto } from "./types/index.js";
|
|
34
|
+
import type {
|
|
35
|
+
ComponentEvent,
|
|
36
|
+
LocalGitRepoState,
|
|
37
|
+
SuperblocksResourceType,
|
|
38
|
+
} from "@superblocksteam/util";
|
|
28
39
|
|
|
29
40
|
// Exporting here instead of index.ts because only sdk.ts is exposed outside in package.json
|
|
30
|
-
export * from "./errors";
|
|
41
|
+
export * from "./errors.js";
|
|
31
42
|
|
|
32
43
|
export class SuperblocksSdk {
|
|
33
44
|
token = "";
|
|
@@ -57,13 +68,13 @@ export class SuperblocksSdk {
|
|
|
57
68
|
applicationId,
|
|
58
69
|
branch,
|
|
59
70
|
headers = {},
|
|
60
|
-
viewMode =
|
|
71
|
+
viewMode = ExportViewMode.EXPORT_LIVE,
|
|
61
72
|
skipSigningVerification = false,
|
|
62
73
|
}: {
|
|
63
74
|
applicationId: string;
|
|
64
75
|
branch?: string;
|
|
65
76
|
headers?: Record<string, string>;
|
|
66
|
-
viewMode?:
|
|
77
|
+
viewMode?: ExportViewMode;
|
|
67
78
|
skipSigningVerification?: boolean;
|
|
68
79
|
}) {
|
|
69
80
|
return fetchApplication({
|
|
@@ -92,14 +103,14 @@ export class SuperblocksSdk {
|
|
|
92
103
|
applicationId,
|
|
93
104
|
branch,
|
|
94
105
|
headers = {},
|
|
95
|
-
viewMode =
|
|
106
|
+
viewMode = ExportViewMode.EXPORT_LIVE,
|
|
96
107
|
commitId,
|
|
97
108
|
skipSigningVerification = false,
|
|
98
109
|
}: {
|
|
99
110
|
applicationId: string;
|
|
100
111
|
branch: string;
|
|
101
112
|
headers?: Record<string, string>;
|
|
102
|
-
viewMode?:
|
|
113
|
+
viewMode?: ExportViewMode;
|
|
103
114
|
commitId?: string;
|
|
104
115
|
skipSigningVerification?: boolean;
|
|
105
116
|
}) {
|
|
@@ -178,12 +189,12 @@ export class SuperblocksSdk {
|
|
|
178
189
|
async fetchApi({
|
|
179
190
|
apiId,
|
|
180
191
|
branch,
|
|
181
|
-
viewMode =
|
|
192
|
+
viewMode = ExportViewMode.EXPORT_LIVE,
|
|
182
193
|
commitId,
|
|
183
194
|
skipSigningVerification = false,
|
|
184
195
|
}: {
|
|
185
196
|
apiId: string;
|
|
186
|
-
viewMode?:
|
|
197
|
+
viewMode?: ExportViewMode;
|
|
187
198
|
branch?: string;
|
|
188
199
|
commitId?: string;
|
|
189
200
|
skipSigningVerification?: boolean;
|
|
@@ -308,6 +319,69 @@ export class SuperblocksSdk {
|
|
|
308
319
|
});
|
|
309
320
|
}
|
|
310
321
|
|
|
322
|
+
async dbfsGetApplication({
|
|
323
|
+
applicationId,
|
|
324
|
+
branch,
|
|
325
|
+
localDirectoryPath,
|
|
326
|
+
}: {
|
|
327
|
+
applicationId: string;
|
|
328
|
+
branch?: string;
|
|
329
|
+
localDirectoryPath: string;
|
|
330
|
+
}) {
|
|
331
|
+
await downloadApplicationDirectory(
|
|
332
|
+
this.token,
|
|
333
|
+
this.superblocksBaseUrl,
|
|
334
|
+
applicationId,
|
|
335
|
+
branch,
|
|
336
|
+
localDirectoryPath,
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
async dbfsPutApplication({
|
|
341
|
+
applicationId,
|
|
342
|
+
branch,
|
|
343
|
+
localDirectoryPath,
|
|
344
|
+
}: {
|
|
345
|
+
applicationId: string;
|
|
346
|
+
branch?: string;
|
|
347
|
+
localDirectoryPath: string;
|
|
348
|
+
}) {
|
|
349
|
+
await uploadLocalApplication(
|
|
350
|
+
this.token,
|
|
351
|
+
this.superblocksBaseUrl,
|
|
352
|
+
applicationId,
|
|
353
|
+
branch,
|
|
354
|
+
localDirectoryPath,
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
async dbfsGetApplicationDirectoryHash({
|
|
359
|
+
applicationId,
|
|
360
|
+
branch,
|
|
361
|
+
}: {
|
|
362
|
+
applicationId: string;
|
|
363
|
+
branch: string | undefined;
|
|
364
|
+
}) {
|
|
365
|
+
return getApplicationDirectoryHash(
|
|
366
|
+
this.token,
|
|
367
|
+
this.superblocksBaseUrl,
|
|
368
|
+
applicationId,
|
|
369
|
+
branch,
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
async dbfsList({ hash }: { hash: string }) {
|
|
374
|
+
await printDirectoryEntries(this.token, this.superblocksBaseUrl, hash);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
async dbfsCat({ hash }: { hash: string }) {
|
|
378
|
+
await printFileContents(this.token, this.superblocksBaseUrl, hash);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
async hashLocalDirectory(localDirectoryPath: string) {
|
|
382
|
+
return await hashLocalDirectory(localDirectoryPath);
|
|
383
|
+
}
|
|
384
|
+
|
|
311
385
|
async deployApplication(applicationId: string, commitId?: string) {
|
|
312
386
|
return deployApplication(
|
|
313
387
|
this.cliVersion,
|
package/src/socket/handlers.ts
CHANGED
|
@@ -1,53 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { signResource, verifyResources } from "./signing.js";
|
|
2
|
+
import type { AppToSign, AppToVerify, MethodHandlers } from "../types/index.js";
|
|
3
|
+
import type {
|
|
3
4
|
ApiToSign,
|
|
4
5
|
ApiToVerify,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Signature,
|
|
10
|
-
ViewMode,
|
|
11
|
-
} from "../types";
|
|
12
|
-
import { signResource, verifyResources } from "./signing";
|
|
13
|
-
|
|
14
|
-
type MethodSchema<Params, Response> = (params: Params) => Promise<Response>;
|
|
15
|
-
|
|
16
|
-
export interface ClientMethods {
|
|
17
|
-
v1: {
|
|
18
|
-
signing: {
|
|
19
|
-
signApplication: MethodSchema<
|
|
20
|
-
{ branchName: string; toSign: AppToSign },
|
|
21
|
-
{ signature: Signature }
|
|
22
|
-
>;
|
|
23
|
-
signApis: MethodSchema<
|
|
24
|
-
{ branchName: string; toSign: ApiToSign[] },
|
|
25
|
-
{ signatures: Signature[] }
|
|
26
|
-
>;
|
|
27
|
-
verifyApplication: MethodSchema<
|
|
28
|
-
{ branchName: string; toVerify: AppToVerify },
|
|
29
|
-
{ ok: boolean }
|
|
30
|
-
>;
|
|
31
|
-
verifyApi: MethodSchema<
|
|
32
|
-
{ branchName: string; toVerify: ApiToVerify[] },
|
|
33
|
-
{ ok: boolean }
|
|
34
|
-
>;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
type ServerMethodSchema<Params, Response> = MethodSchema<
|
|
40
|
-
Params,
|
|
41
|
-
ResponseDto<Response>
|
|
42
|
-
>;
|
|
6
|
+
ClientMethods,
|
|
7
|
+
ServerMethods,
|
|
8
|
+
} from "@superblocksteam/shared";
|
|
9
|
+
import type { Signature } from "@superblocksteam/util";
|
|
43
10
|
|
|
44
11
|
// This file contains the definition of the protocol used for communication between the SB server and clients
|
|
45
12
|
|
|
46
|
-
type ResponseDto<T> = {
|
|
47
|
-
responseMeta: ResponseMeta;
|
|
48
|
-
data: T;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
13
|
export type ResponseMeta = {
|
|
52
14
|
status: number;
|
|
53
15
|
success: boolean;
|
|
@@ -60,106 +22,6 @@ type APIResponseError = {
|
|
|
60
22
|
message: string;
|
|
61
23
|
};
|
|
62
24
|
|
|
63
|
-
export interface ServerMethods {
|
|
64
|
-
v1: {
|
|
65
|
-
echo: MethodSchema<{ message: string }, { message: string }>;
|
|
66
|
-
public: {
|
|
67
|
-
application: {
|
|
68
|
-
component: {
|
|
69
|
-
register: ServerMethodSchema<
|
|
70
|
-
{
|
|
71
|
-
applicationId: string;
|
|
72
|
-
branchName: string;
|
|
73
|
-
cliVersion: string;
|
|
74
|
-
componentEvent: string;
|
|
75
|
-
components: Record<string, unknown>;
|
|
76
|
-
},
|
|
77
|
-
{ success: boolean }
|
|
78
|
-
>;
|
|
79
|
-
update: ServerMethodSchema<
|
|
80
|
-
{
|
|
81
|
-
applicationId: string;
|
|
82
|
-
branchName?: string;
|
|
83
|
-
srcFiles: string[];
|
|
84
|
-
buildFiles: string[];
|
|
85
|
-
registeredComponents: Record<string, unknown>;
|
|
86
|
-
cliVersion: string | undefined;
|
|
87
|
-
componentBaseUrl: string;
|
|
88
|
-
signingRequired: boolean;
|
|
89
|
-
},
|
|
90
|
-
{ success: boolean }
|
|
91
|
-
>;
|
|
92
|
-
};
|
|
93
|
-
pushCommit: ServerMethodSchema<
|
|
94
|
-
{
|
|
95
|
-
applicationId: string;
|
|
96
|
-
branchName: string;
|
|
97
|
-
commitId: string;
|
|
98
|
-
commitMessage: string;
|
|
99
|
-
application: Record<string, unknown>;
|
|
100
|
-
page: Record<string, unknown>;
|
|
101
|
-
apis: Record<string, unknown>[];
|
|
102
|
-
gitState: LocalGitRepoState;
|
|
103
|
-
},
|
|
104
|
-
RemoteCommitDto
|
|
105
|
-
>;
|
|
106
|
-
};
|
|
107
|
-
api: {
|
|
108
|
-
pushCommit: ServerMethodSchema<
|
|
109
|
-
{
|
|
110
|
-
apiId: string;
|
|
111
|
-
branchName: string;
|
|
112
|
-
commitId?: string;
|
|
113
|
-
commitMessage?: string;
|
|
114
|
-
apiPb: Record<string, unknown>;
|
|
115
|
-
gitState: LocalGitRepoState;
|
|
116
|
-
skipCommit: boolean;
|
|
117
|
-
},
|
|
118
|
-
RemoteCommitDto | { updated: Date }
|
|
119
|
-
>;
|
|
120
|
-
get: ServerMethodSchema<
|
|
121
|
-
{
|
|
122
|
-
apiId: string;
|
|
123
|
-
branchName?: string;
|
|
124
|
-
viewMode: ViewMode;
|
|
125
|
-
commitId?: string;
|
|
126
|
-
},
|
|
127
|
-
any
|
|
128
|
-
>;
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
v2: {
|
|
133
|
-
public: {
|
|
134
|
-
application: {
|
|
135
|
-
pushCommit: ServerMethodSchema<
|
|
136
|
-
{
|
|
137
|
-
applicationId: string;
|
|
138
|
-
branchName: string;
|
|
139
|
-
commitId?: string;
|
|
140
|
-
commitMessage?: string;
|
|
141
|
-
application: Record<string, unknown>;
|
|
142
|
-
pages: Record<string, unknown>[];
|
|
143
|
-
apis: Record<string, unknown>[];
|
|
144
|
-
gitState: LocalGitRepoState;
|
|
145
|
-
skipCommit: boolean;
|
|
146
|
-
},
|
|
147
|
-
RemoteCommitDto | { updated: Date }
|
|
148
|
-
>;
|
|
149
|
-
get: ServerMethodSchema<
|
|
150
|
-
{
|
|
151
|
-
applicationId: string;
|
|
152
|
-
viewMode: ViewMode;
|
|
153
|
-
branchName?: string;
|
|
154
|
-
commitId?: string;
|
|
155
|
-
},
|
|
156
|
-
any
|
|
157
|
-
>;
|
|
158
|
-
};
|
|
159
|
-
};
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
|
|
163
25
|
export function createRequestHandlers({
|
|
164
26
|
agentUrl,
|
|
165
27
|
token,
|
|
@@ -216,7 +78,7 @@ export function createRequestHandlers({
|
|
|
216
78
|
agentUrl,
|
|
217
79
|
token: token,
|
|
218
80
|
branchName,
|
|
219
|
-
resource: { api: apiPb },
|
|
81
|
+
resource: { api: apiPb as any },
|
|
220
82
|
});
|
|
221
83
|
signatures.push(signature);
|
|
222
84
|
}
|
|
@@ -276,7 +138,7 @@ export function createRequestHandlers({
|
|
|
276
138
|
token,
|
|
277
139
|
branchName,
|
|
278
140
|
resources: toVerify.map(({ apiPb }) => ({
|
|
279
|
-
api: apiPb,
|
|
141
|
+
api: apiPb as any,
|
|
280
142
|
})),
|
|
281
143
|
});
|
|
282
144
|
return { ok: true };
|
package/src/socket/index.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import WebSocket from "ws";
|
|
2
|
-
import {
|
|
2
|
+
import { createRequestHandlers } from "./handlers.js";
|
|
3
|
+
import { createISocketClient, ISocket } from "./socket.js";
|
|
4
|
+
import type {
|
|
3
5
|
GenericMiddleware,
|
|
4
6
|
ISocketClient,
|
|
5
7
|
MethodHandlers,
|
|
6
8
|
RequestContextBase,
|
|
7
9
|
SocketTimeouts,
|
|
8
|
-
} from "../types";
|
|
9
|
-
import {
|
|
10
|
-
ClientMethods,
|
|
11
|
-
createRequestHandlers,
|
|
12
|
-
ServerMethods,
|
|
13
|
-
} from "./handlers";
|
|
14
|
-
import { createISocketClient, ISocket } from "./socket";
|
|
10
|
+
} from "../types/index.js";
|
|
11
|
+
import type { ClientMethods, ServerMethods } from "@superblocksteam/shared";
|
|
15
12
|
|
|
16
13
|
export type StdISocketRPCClient = ISocketClient<ServerMethods>;
|
|
17
14
|
|
|
@@ -36,7 +33,7 @@ export async function connectToISocketRPCServer({
|
|
|
36
33
|
wsUrl.protocol = "wss:";
|
|
37
34
|
}
|
|
38
35
|
|
|
39
|
-
if (wsUrl.host === "localhost:3000") {
|
|
36
|
+
if (wsUrl.host === "localhost:3000" || wsUrl.host === "127.0.0.1:3000") {
|
|
40
37
|
wsUrl.host = "127.0.0.1:8080";
|
|
41
38
|
} else if (wsUrl.hostname === "localhost") {
|
|
42
39
|
wsUrl.hostname = "127.0.0.1";
|
package/src/socket/signing.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import axios
|
|
2
|
-
import {
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { getSanitizedApi } from "../utils.js";
|
|
3
|
+
import type {
|
|
3
4
|
ApiResource,
|
|
4
5
|
GenericResource,
|
|
5
|
-
Signature,
|
|
6
6
|
SignatureResponse,
|
|
7
|
-
} from "../types";
|
|
8
|
-
import {
|
|
7
|
+
} from "../types/index.js";
|
|
8
|
+
import type { Signature } from "@superblocksteam/util";
|
|
9
|
+
import type { AxiosRequestConfig, Method } from "axios";
|
|
9
10
|
|
|
10
11
|
export async function signResource({
|
|
11
12
|
token,
|
|
@@ -22,7 +23,6 @@ export async function signResource({
|
|
|
22
23
|
branchName: branchName ?? "main",
|
|
23
24
|
};
|
|
24
25
|
if ((resource as ApiResource).api) {
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
26
26
|
requestResource.api = getSanitizedApi((resource as ApiResource).api);
|
|
27
27
|
} else {
|
|
28
28
|
requestResource.literal = (resource as GenericResource).literal;
|
|
@@ -58,7 +58,6 @@ export async function verifyResources({
|
|
|
58
58
|
resources: resources.map((res) => {
|
|
59
59
|
if ((res as ApiResource).api) {
|
|
60
60
|
return {
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
62
61
|
api: getSanitizedApi((res as ApiResource).api),
|
|
63
62
|
branchName: branchName ?? "main",
|
|
64
63
|
};
|
|
@@ -93,7 +92,7 @@ async function callAgent<T>({
|
|
|
93
92
|
headers: {
|
|
94
93
|
Authorization: "Bearer " + token,
|
|
95
94
|
},
|
|
96
|
-
|
|
95
|
+
|
|
97
96
|
data: data,
|
|
98
97
|
};
|
|
99
98
|
const resp = await axios<T>(config);
|
package/src/socket/socket.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { SocketErrorException } from "../types/index.js";
|
|
2
|
+
import type {
|
|
3
3
|
ISocketClient,
|
|
4
4
|
MethodHandler,
|
|
5
5
|
MethodHandlers,
|
|
6
6
|
RequestContextBase,
|
|
7
7
|
SocketTimeouts,
|
|
8
|
-
SocketErrorException,
|
|
9
8
|
GenericMiddleware,
|
|
10
9
|
NonEmptyArray,
|
|
11
|
-
} from "../types";
|
|
10
|
+
} from "../types/index.js";
|
|
11
|
+
import type WebSocket from "ws";
|
|
12
12
|
|
|
13
13
|
interface SocketRequest<Payload = unknown> {
|
|
14
14
|
method: string;
|
|
@@ -101,9 +101,8 @@ export class ISocket<
|
|
|
101
101
|
|
|
102
102
|
this.ws.addEventListener(
|
|
103
103
|
"message",
|
|
104
|
-
|
|
104
|
+
|
|
105
105
|
async (event: WebSocket.MessageEvent) => {
|
|
106
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
107
106
|
const eventData: SocketMessage = JSON.parse(event.data.toString());
|
|
108
107
|
return this.handleMessage(eventData);
|
|
109
108
|
},
|
|
@@ -205,7 +204,7 @@ export class ISocket<
|
|
|
205
204
|
if (message.response.error) {
|
|
206
205
|
responseHandler.reject(message.response.error);
|
|
207
206
|
}
|
|
208
|
-
|
|
207
|
+
|
|
209
208
|
responseHandler.resolve(message.response.payload as any);
|
|
210
209
|
clearTimeout(responseHandler.timeout);
|
|
211
210
|
this.responseHandler.delete(message.response.id);
|
|
@@ -241,7 +240,7 @@ export class ISocket<
|
|
|
241
240
|
const requestId = ++this.nxtRequestId;
|
|
242
241
|
this.responseHandler.set(requestId, {
|
|
243
242
|
resolve: (result) => resolve(result as Result),
|
|
244
|
-
|
|
243
|
+
|
|
245
244
|
reject: (error: SocketError) => reject(error),
|
|
246
245
|
});
|
|
247
246
|
const toSend: SocketMessage = {
|
|
@@ -394,7 +393,7 @@ export function createISocketClient<
|
|
|
394
393
|
): ISocketClient<CallableMethods> {
|
|
395
394
|
return {
|
|
396
395
|
close: () => socket.close(),
|
|
397
|
-
|
|
396
|
+
|
|
398
397
|
call: createIsocketProxy(socket, undefined) as any,
|
|
399
398
|
};
|
|
400
399
|
}
|