Skip to content

Commit 3cb0e60

Browse files
Add: Infra OAPI & EnvD gRPC client + Sandbox Details Server Function (#76)
Added infrastructure API client and envd gRPC client generation, then migrated existing infrastructure calls to use the new openapi-fetch pattern. **Key Changes:** - **Added infra API & envd gRPC client generation** - New API schema with endpoints for templates, nodes, access tokens, and API keys - **Refactored infra invocations to openapi-fetch** - Migrated from manual API calls to generated client methods across dashboard, sandboxes, templates, and team management - **Improved error handling** - Added `handleDefaultInfraError` function that informs users about billing limit blockage on 403 errors - Added correct error handing for template deletion - **Fixed build errors from `noUncheckedIndexedAccess`** - Added optional chaining in chart tooltips and cleaned up unsafe array/object access patterns **Cleanup:** - Removed unused `AssemblyLoader` component - Enabled stricter TypeScript checking for better type safety Completes E2B-2467, Completes E2B-2469, Completes E2B-2374
1 parent 475be4d commit 3cb0e60

33 files changed

+2862
-405
lines changed

bun.lock

Lines changed: 107 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
"dev:scan": "bun dev & bun scan",
1515
"start:scan": "bun start & bun scan",
1616
"<<<<<< Database": "",
17-
"db:types": "bunx supabase@latest gen types typescript --schema public > src/types/database.types.ts --project-id $SUPABASE_PROJECT_ID",
1817
"db:migrations:create": "bun run scripts:create-migration",
1918
"db:migrations:apply": "bun run scripts:apply-migrations",
19+
"<<<<<< Gen": "",
20+
"generate:infra": "bunx openapi-typescript https://raw.githubusercontent.com/e2b-dev/infra/main/spec/openapi.yml -o ./src/types/infra-api.d.ts",
21+
"generate:supabase": "bunx supabase@latest gen types typescript --schema public > src/types/database.types.ts --project-id $SUPABASE_PROJECT_ID",
22+
"generate:envd": "buf generate --template ./spec/envd/buf.gen.yaml",
2023
"<<<<<< Scripts": "",
2124
"scripts:check-app-env": "bun scripts/check-app-env.ts",
2225
"scripts:build-storybook": "bun scripts/build-storybook.ts",
@@ -37,6 +40,7 @@
3740
"test:ui:integration": "bun scripts:check-app-env && vitest --ui src/__test__/integration/"
3841
},
3942
"dependencies": {
43+
"@connectrpc/connect": "^2.0.2",
4044
"@fumadocs/mdx-remote": "^1.2.0",
4145
"@google-cloud/storage": "^7.15.2",
4246
"@hookform/resolvers": "^3.10.0",
@@ -90,6 +94,7 @@
9094
"next-logger": "^5.0.1",
9195
"next-safe-action": "^7.10.4",
9296
"next-themes": "^0.4.4",
97+
"openapi-fetch": "^0.14.0",
9398
"pino": "^9.6.0",
9499
"pino-pretty": "^13.0.0",
95100
"postgres": "^3.4.5",
@@ -143,6 +148,7 @@
143148
"eslint-config-next": "^15.1.6",
144149
"eslint-config-prettier": "^10.0.1",
145150
"eslint-plugin-prettier": "^5.2.3",
151+
"openapi-typescript": "^7.8.0",
146152
"postcss": "8.5.1",
147153
"postcss-import": "^16.1.0",
148154
"prettier": "^3.4.2",
@@ -154,7 +160,11 @@
154160
"tailwindcss-animate": "^1.0.7",
155161
"tsx": "^4.19.2",
156162
"typescript": "5.7.3",
157-
"vitest": "^3.0.7"
163+
"vitest": "^3.0.7",
164+
"@bufbuild/buf": "^1.54.0",
165+
"@bufbuild/protobuf": "^2.5.2",
166+
"@bufbuild/protoc-gen-es": "^2.5.2",
167+
"@connectrpc/protoc-gen-connect-es": "^1.6.1"
158168
},
159169
"resolutions": {
160170
"whatwg-url": "^13",

spec/envd/buf.gen.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# buf.gen.yaml defines a local generation template.
2+
# For details, see https://buf.build/docs/configuration/v2/buf-gen-yaml
3+
version: v2
4+
plugins:
5+
- local: protoc-gen-es
6+
out: ./src/lib/clients/envd
7+
opt:
8+
- target=ts
9+
- local: protoc-gen-connect-es
10+
out: ./src/lib/clients/envd
11+
opt:
12+
- target=ts
13+
14+
managed:
15+
enabled: true
16+
override:
17+
- file_option: optimize_for
18+
value: SPEED
19+
20+
inputs:
21+
- directory: spec/envd
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
syntax = "proto3";
2+
3+
package filesystem;
4+
5+
service Filesystem {
6+
rpc Stat(StatRequest) returns (StatResponse);
7+
rpc MakeDir(MakeDirRequest) returns (MakeDirResponse);
8+
rpc Move(MoveRequest) returns (MoveResponse);
9+
rpc ListDir(ListDirRequest) returns (ListDirResponse);
10+
rpc Remove(RemoveRequest) returns (RemoveResponse);
11+
12+
rpc WatchDir(WatchDirRequest) returns (stream WatchDirResponse);
13+
14+
// Non-streaming versions of WatchDir
15+
rpc CreateWatcher(CreateWatcherRequest) returns (CreateWatcherResponse);
16+
rpc GetWatcherEvents(GetWatcherEventsRequest) returns (GetWatcherEventsResponse);
17+
rpc RemoveWatcher(RemoveWatcherRequest) returns (RemoveWatcherResponse);
18+
}
19+
20+
message MoveRequest {
21+
string source = 1;
22+
string destination = 2;
23+
}
24+
25+
message MoveResponse {
26+
EntryInfo entry = 1;
27+
}
28+
29+
message MakeDirRequest {
30+
string path = 1;
31+
}
32+
33+
message MakeDirResponse {
34+
EntryInfo entry = 1;
35+
}
36+
37+
message RemoveRequest {
38+
string path = 1;
39+
}
40+
41+
message RemoveResponse {}
42+
43+
message StatRequest {
44+
string path = 1;
45+
}
46+
47+
message StatResponse {
48+
EntryInfo entry = 1;
49+
}
50+
51+
message EntryInfo {
52+
string name = 1;
53+
FileType type = 2;
54+
string path = 3;
55+
}
56+
57+
enum FileType {
58+
FILE_TYPE_UNSPECIFIED = 0;
59+
FILE_TYPE_FILE = 1;
60+
FILE_TYPE_DIRECTORY = 2;
61+
}
62+
63+
message ListDirRequest {
64+
string path = 1;
65+
uint32 depth = 2;
66+
}
67+
68+
message ListDirResponse {
69+
repeated EntryInfo entries = 1;
70+
}
71+
72+
message WatchDirRequest {
73+
string path = 1;
74+
bool recursive = 2;
75+
}
76+
77+
message FilesystemEvent {
78+
string name = 1;
79+
EventType type = 2;
80+
}
81+
82+
message WatchDirResponse {
83+
oneof event {
84+
StartEvent start = 1;
85+
FilesystemEvent filesystem = 2;
86+
KeepAlive keepalive = 3;
87+
}
88+
89+
message StartEvent {}
90+
91+
message KeepAlive {}
92+
}
93+
94+
message CreateWatcherRequest {
95+
string path = 1;
96+
bool recursive = 2;
97+
}
98+
99+
message CreateWatcherResponse {
100+
string watcher_id = 1;
101+
}
102+
103+
message GetWatcherEventsRequest {
104+
string watcher_id = 1;
105+
}
106+
107+
message GetWatcherEventsResponse {
108+
repeated FilesystemEvent events = 1;
109+
}
110+
111+
message RemoveWatcherRequest {
112+
string watcher_id = 1;
113+
}
114+
115+
message RemoveWatcherResponse {}
116+
117+
enum EventType {
118+
EVENT_TYPE_UNSPECIFIED = 0;
119+
EVENT_TYPE_CREATE = 1;
120+
EVENT_TYPE_WRITE = 2;
121+
EVENT_TYPE_REMOVE = 3;
122+
EVENT_TYPE_RENAME = 4;
123+
EVENT_TYPE_CHMOD = 5;
124+
}

src/app/(auth)/auth/cli/page.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ async function handleCLIAuth(
3434

3535
try {
3636
const defaultTeam = await getDefaultTeamRelation(userId)
37-
const e2bAccessToken = await generateE2BUserAccessToken(
38-
supabaseAccessToken,
39-
userId
40-
)
37+
const e2bAccessToken = await generateE2BUserAccessToken(supabaseAccessToken)
4138

4239
const searchParams = new URLSearchParams({
4340
email: userEmail,

src/app/dashboard/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export async function GET(request: NextRequest) {
6363
}
6464

6565
// Use default team or first team
66-
const defaultTeam = teamsData.find((t) => t.is_default) || teamsData[0]
66+
const defaultTeam = teamsData.find((t) => t.is_default) || teamsData[0]!
6767
teamId = defaultTeam.team_id
6868
teamSlug = defaultTeam.team?.slug || defaultTeam.team_id
6969
}

src/configs/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const API_KEY_PREFIX = 'e2b_'
22
export const ACCESS_TOKEN_PREFIX = 'sk_e2b_'
33
export const SUPABASE_TOKEN_HEADER = 'X-Supabase-Token'
44
export const SUPABASE_TEAM_HEADER = 'X-Supabase-Team'
5+
export const ENVD_ACCESS_TOKEN_HEADER = 'X-Access-Token'
56

67
export const SUPABASE_AUTH_HEADERS = (token: string, teamId?: string) => ({
78
[SUPABASE_TOKEN_HEADER]: token,

0 commit comments

Comments
 (0)