Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/js-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"knip": "^5.43.6",
"npm-check-updates": "^16.14.20",
"npm-run-all": "^4.1.5",
"openapi-typescript": "^7.6.1",
"openapi-typescript": "^7.9.1",
"playwright": "^1.48.0",
"react": "^18.3.1",
"tsup": "^8.4.0",
Expand Down Expand Up @@ -95,7 +95,7 @@
"compare-versions": "^6.1.0",
"dockerfile-ast": "^0.7.1",
"glob": "^11.0.3",
"openapi-fetch": "^0.9.7",
"openapi-fetch": "^0.14.1",
"platform": "^1.3.6",
"tar": "^7.4.3"
},
Expand Down
10 changes: 6 additions & 4 deletions packages/js-sdk/src/envd/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ import { StartResponse, ConnectResponse } from './process/process_pb'
import { Code, ConnectError } from '@connectrpc/connect'
import { WatchDirResponse } from './filesystem/filesystem_pb'

export async function handleEnvdApiError<A, B, C extends `${string}/${string}`>(
res: FetchResponse<A, B, C>
) {
export async function handleEnvdApiError<
A extends { responses: Record<string, any> },
B,
C extends `${string}/${string}`,
>(res: FetchResponse<A, B, C>) {
if (!res.error) {
return
}

const message: string =
typeof res.error == 'string'
? res.error
: res.error?.message || (await res.response.text())
: (res.error as any)?.message || (await res.response.text())

switch (res.response.status) {
case 400:
Expand Down
17 changes: 8 additions & 9 deletions packages/js-sdk/src/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,18 @@ export function createRpcLogger(logger: Logger): Interceptor {

export function createApiLogger(logger: Logger): Middleware {
return {
async onRequest(req) {
logger.info?.(`Request ${req.method} ${req.url}`)

return req
async onRequest({ request }) {
logger.info?.(`Request ${request.method} ${request.url}`)
return request
},
async onResponse(res) {
if (res.status >= 400) {
logger.error?.('Response:', res.status, res.statusText)
async onResponse({ response }) {
if (response.status >= 400) {
logger.error?.('Response:', response.status, response.statusText)
} else {
logger.info?.('Response:', res.status, res.statusText)
logger.info?.('Response:', response.status, response.statusText)
}

return res
return response
},
}
}
6 changes: 1 addition & 5 deletions packages/js-sdk/src/sandbox/filesystem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,17 +359,13 @@ export class Filesystem {
// Important: RFC 7578, Section 4.2 requires that if a filename is provided,
// the directory path information must not be used.
// BUT in our case we need to use the directory path information with a custom
// muktipart part name getter in envd.
// multipart part name getter in envd.
fd.append('file', blob, writeFiles[i].path)

return fd
}, new FormData())
},
body: {},
headers: {
'Content-Type': 'multipart/form-data',
'Bun-Content-Type': 'temporary-fix', // https://github.com/oven-sh/bun/issues/14988
},
})

const err = await handleEnvdApiError(res)
Expand Down
5 changes: 5 additions & 0 deletions packages/js-sdk/tests/runtimes/bun/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ test(

expect(cmd.exitCode).toBe(0)
expect(cmd.stdout).toEqual(`${text}\n`)

await sbx.files.write('test.txt', text)
const test = await sbx.files.read('test.txt')

expect(test).toEqual(text)
} finally {
await sbx.kill()
}
Expand Down
Loading