Skip to content

Commit bec5b14

Browse files
authored
Update openapi fetch (#929)
<!-- CURSOR_SUMMARY --> > [!NOTE] > Upgrade openapi-fetch to v0.14 and openapi-typescript to v7.9 with required API/middleware changes, adjust multipart upload, and extend Bun test with file I/O. > > - **JS SDK**: > - **Dependencies**: Bump `openapi-fetch` to `^0.14.1` and `openapi-typescript` to `^7.9.1`. > - **API Client (`src/envd/api.ts`)**: > - Update `handleEnvdApiError` to accept `{ error, response }` per new client response shape; remove `FetchResponse` generic import. > - **Logging (`src/logs.ts`)**: > - Update `Middleware` usage to new signatures: `onRequest({ request })` and `onResponse({ response })` and return `request`/`response`. > - **Filesystem (`src/sandbox/filesystem/index.ts`)**: > - Adjust `POST /files` multipart upload: use `bodySerializer()` with `FormData`; remove manual `Content-Type` headers; minor comment typo fix. > - **Tests**: > - Extend Bun runtime test to write/read a file via `sbx.files`. > - **Release**: Add patch changeset. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 03afbac. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent ebb3f08 commit bec5b14

File tree

7 files changed

+105
-92
lines changed

7 files changed

+105
-92
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'e2b': patch
3+
---
4+
5+
Update openapi fetch

packages/js-sdk/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"knip": "^5.43.6",
5959
"npm-check-updates": "^16.14.20",
6060
"npm-run-all": "^4.1.5",
61-
"openapi-typescript": "^7.6.1",
61+
"openapi-typescript": "^7.9.1",
6262
"playwright": "^1.48.0",
6363
"react": "^18.3.1",
6464
"tsup": "^8.4.0",
@@ -95,7 +95,7 @@
9595
"compare-versions": "^6.1.0",
9696
"dockerfile-ast": "^0.7.1",
9797
"glob": "^11.0.3",
98-
"openapi-fetch": "^0.9.7",
98+
"openapi-fetch": "^0.14.1",
9999
"platform": "^1.3.6",
100100
"tar": "^7.4.3"
101101
},

packages/js-sdk/src/envd/api.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import createClient, { FetchResponse } from 'openapi-fetch'
1+
import createClient from 'openapi-fetch'
22

33
import type { components, paths } from './schema.gen'
44
import { ConnectionConfig } from '../connectionConfig'
@@ -15,9 +15,12 @@ import { StartResponse, ConnectResponse } from './process/process_pb'
1515
import { Code, ConnectError } from '@connectrpc/connect'
1616
import { WatchDirResponse } from './filesystem/filesystem_pb'
1717

18-
export async function handleEnvdApiError<A, B, C extends `${string}/${string}`>(
19-
res: FetchResponse<A, B, C>
20-
) {
18+
type ApiError = { message?: string } | string
19+
20+
export async function handleEnvdApiError(res: {
21+
error?: ApiError
22+
response: Response
23+
}) {
2124
if (!res.error) {
2225
return
2326
}

packages/js-sdk/src/logs.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,18 @@ export function createRpcLogger(logger: Logger): Interceptor {
5454

5555
export function createApiLogger(logger: Logger): Middleware {
5656
return {
57-
async onRequest(req) {
58-
logger.info?.(`Request ${req.method} ${req.url}`)
59-
60-
return req
57+
async onRequest({ request }) {
58+
logger.info?.(`Request ${request.method} ${request.url}`)
59+
return request
6160
},
62-
async onResponse(res) {
63-
if (res.status >= 400) {
64-
logger.error?.('Response:', res.status, res.statusText)
61+
async onResponse({ response }) {
62+
if (response.status >= 400) {
63+
logger.error?.('Response:', response.status, response.statusText)
6564
} else {
66-
logger.info?.('Response:', res.status, res.statusText)
65+
logger.info?.('Response:', response.status, response.statusText)
6766
}
6867

69-
return res
68+
return response
7069
},
7170
}
7271
}

packages/js-sdk/src/sandbox/filesystem/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,17 +359,13 @@ export class Filesystem {
359359
// Important: RFC 7578, Section 4.2 requires that if a filename is provided,
360360
// the directory path information must not be used.
361361
// BUT in our case we need to use the directory path information with a custom
362-
// muktipart part name getter in envd.
362+
// multipart part name getter in envd.
363363
fd.append('file', blob, writeFiles[i].path)
364364

365365
return fd
366366
}, new FormData())
367367
},
368368
body: {},
369-
headers: {
370-
'Content-Type': 'multipart/form-data',
371-
'Bun-Content-Type': 'temporary-fix', // https://github.com/oven-sh/bun/issues/14988
372-
},
373369
})
374370

375371
const err = await handleEnvdApiError(res)

packages/js-sdk/tests/runtimes/bun/run.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ test(
1717

1818
expect(cmd.exitCode).toBe(0)
1919
expect(cmd.stdout).toEqual(`${text}\n`)
20+
21+
await sbx.files.write('test.txt', text)
22+
const test = await sbx.files.read('test.txt')
23+
24+
expect(test).toEqual(text)
2025
} finally {
2126
await sbx.kill()
2227
}

0 commit comments

Comments
 (0)