@cloudflare/sandbox 0.0.0-cbb7fcd → 0.0.0-d1c7c99
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/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/client.ts +15 -5
- package/src/index.ts +9 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @cloudflare/sandbox
|
|
2
2
|
|
|
3
|
+
## 0.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#9](https://github.com/cloudflare/sandbox-sdk/pull/9) [`24f5470`](https://github.com/cloudflare/sandbox-sdk/commit/24f547048d5a26137de4656cea13d83ad2cc0b43) Thanks [@ItsWendell](https://github.com/ItsWendell)! - fix baseUrl for stub and stub forwarding
|
|
8
|
+
|
|
3
9
|
## 0.0.5
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -203,7 +203,9 @@ export class HttpClient {
|
|
|
203
203
|
path: string,
|
|
204
204
|
options?: RequestInit
|
|
205
205
|
): Promise<Response> {
|
|
206
|
-
const url = this.options.stub
|
|
206
|
+
const url = this.options.stub
|
|
207
|
+
? `http://localhost:${this.options.port}${path}`
|
|
208
|
+
: `${this.baseUrl}${path}`;
|
|
207
209
|
const method = options?.method || "GET";
|
|
208
210
|
|
|
209
211
|
console.log(`[HTTP Client] Making ${method} request to ${url}`);
|
|
@@ -212,15 +214,23 @@ export class HttpClient {
|
|
|
212
214
|
let response: Response;
|
|
213
215
|
|
|
214
216
|
if (this.options.stub) {
|
|
215
|
-
response = await this.options.stub.containerFetch(
|
|
217
|
+
response = await this.options.stub.containerFetch(
|
|
218
|
+
url,
|
|
219
|
+
options,
|
|
220
|
+
this.options.port
|
|
221
|
+
);
|
|
216
222
|
} else {
|
|
217
|
-
response = await fetch(
|
|
223
|
+
response = await fetch(url, options);
|
|
218
224
|
}
|
|
219
225
|
|
|
220
|
-
console.log(
|
|
226
|
+
console.log(
|
|
227
|
+
`[HTTP Client] Response: ${response.status} ${response.statusText}`
|
|
228
|
+
);
|
|
221
229
|
|
|
222
230
|
if (!response.ok) {
|
|
223
|
-
console.error(
|
|
231
|
+
console.error(
|
|
232
|
+
`[HTTP Client] Request failed: ${method} ${url} - ${response.status} ${response.statusText}`
|
|
233
|
+
);
|
|
224
234
|
}
|
|
225
235
|
|
|
226
236
|
return response;
|
package/src/index.ts
CHANGED
|
@@ -19,7 +19,9 @@ export class Sandbox<Env = unknown> extends Container<Env> {
|
|
|
19
19
|
);
|
|
20
20
|
},
|
|
21
21
|
onCommandStart: (command, args) => {
|
|
22
|
-
console.log(
|
|
22
|
+
console.log(
|
|
23
|
+
`[Container] Command started: ${command} ${args.join(" ")}`
|
|
24
|
+
);
|
|
23
25
|
},
|
|
24
26
|
onError: (error, command, args) => {
|
|
25
27
|
console.error(`[Container] Command error: ${error}`);
|
|
@@ -74,7 +76,7 @@ export class Sandbox<Env = unknown> extends Container<Env> {
|
|
|
74
76
|
|
|
75
77
|
async mkdir(
|
|
76
78
|
path: string,
|
|
77
|
-
options: { recursive?: boolean; stream?: boolean }
|
|
79
|
+
options: { recursive?: boolean; stream?: boolean } = {}
|
|
78
80
|
) {
|
|
79
81
|
if (options?.stream) {
|
|
80
82
|
return this.client.mkdirStream(path, options.recursive);
|
|
@@ -85,7 +87,7 @@ export class Sandbox<Env = unknown> extends Container<Env> {
|
|
|
85
87
|
async writeFile(
|
|
86
88
|
path: string,
|
|
87
89
|
content: string,
|
|
88
|
-
options: { encoding?: string; stream?: boolean }
|
|
90
|
+
options: { encoding?: string; stream?: boolean } = {}
|
|
89
91
|
) {
|
|
90
92
|
if (options?.stream) {
|
|
91
93
|
return this.client.writeFileStream(path, content, options.encoding);
|
|
@@ -93,7 +95,7 @@ export class Sandbox<Env = unknown> extends Container<Env> {
|
|
|
93
95
|
return this.client.writeFile(path, content, options.encoding);
|
|
94
96
|
}
|
|
95
97
|
|
|
96
|
-
async deleteFile(path: string, options: { stream?: boolean }) {
|
|
98
|
+
async deleteFile(path: string, options: { stream?: boolean } = {}) {
|
|
97
99
|
if (options?.stream) {
|
|
98
100
|
return this.client.deleteFileStream(path);
|
|
99
101
|
}
|
|
@@ -103,7 +105,7 @@ export class Sandbox<Env = unknown> extends Container<Env> {
|
|
|
103
105
|
async renameFile(
|
|
104
106
|
oldPath: string,
|
|
105
107
|
newPath: string,
|
|
106
|
-
options: { stream?: boolean }
|
|
108
|
+
options: { stream?: boolean } = {}
|
|
107
109
|
) {
|
|
108
110
|
if (options?.stream) {
|
|
109
111
|
return this.client.renameFileStream(oldPath, newPath);
|
|
@@ -114,7 +116,7 @@ export class Sandbox<Env = unknown> extends Container<Env> {
|
|
|
114
116
|
async moveFile(
|
|
115
117
|
sourcePath: string,
|
|
116
118
|
destinationPath: string,
|
|
117
|
-
options: { stream?: boolean }
|
|
119
|
+
options: { stream?: boolean } = {}
|
|
118
120
|
) {
|
|
119
121
|
if (options?.stream) {
|
|
120
122
|
return this.client.moveFileStream(sourcePath, destinationPath);
|
|
@@ -124,7 +126,7 @@ export class Sandbox<Env = unknown> extends Container<Env> {
|
|
|
124
126
|
|
|
125
127
|
async readFile(
|
|
126
128
|
path: string,
|
|
127
|
-
options: { encoding?: string; stream?: boolean }
|
|
129
|
+
options: { encoding?: string; stream?: boolean } = {}
|
|
128
130
|
) {
|
|
129
131
|
if (options?.stream) {
|
|
130
132
|
return this.client.readFileStream(path, options.encoding);
|