@cloudflare/sandbox 0.0.8 → 0.0.9

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.
@@ -0,0 +1,247 @@
1
+ import { Container } from '@cloudflare/containers';
2
+
3
+ declare function getSandbox(ns: DurableObjectNamespace<Sandbox>, id: string): DurableObjectStub<Sandbox<unknown>>;
4
+ declare class Sandbox<Env = unknown> extends Container<Env> {
5
+ sleepAfter: string;
6
+ client: HttpClient;
7
+ private workerHostname;
8
+ private sandboxName;
9
+ constructor(ctx: DurableObjectState, env: Env);
10
+ setSandboxName(name: string): Promise<void>;
11
+ onStart(): void;
12
+ onStop(): void;
13
+ onError(error: unknown): void;
14
+ fetch(request: Request): Promise<Response>;
15
+ private determinePort;
16
+ exec(command: string, args: string[], options?: {
17
+ stream?: boolean;
18
+ background?: boolean;
19
+ }): Promise<void | ExecuteResponse>;
20
+ gitCheckout(repoUrl: string, options: {
21
+ branch?: string;
22
+ targetDir?: string;
23
+ stream?: boolean;
24
+ }): Promise<void | GitCheckoutResponse>;
25
+ mkdir(path: string, options?: {
26
+ recursive?: boolean;
27
+ stream?: boolean;
28
+ }): Promise<void | MkdirResponse>;
29
+ writeFile(path: string, content: string, options?: {
30
+ encoding?: string;
31
+ stream?: boolean;
32
+ }): Promise<void | WriteFileResponse>;
33
+ deleteFile(path: string, options?: {
34
+ stream?: boolean;
35
+ }): Promise<void | DeleteFileResponse>;
36
+ renameFile(oldPath: string, newPath: string, options?: {
37
+ stream?: boolean;
38
+ }): Promise<void | RenameFileResponse>;
39
+ moveFile(sourcePath: string, destinationPath: string, options?: {
40
+ stream?: boolean;
41
+ }): Promise<void | MoveFileResponse>;
42
+ readFile(path: string, options?: {
43
+ encoding?: string;
44
+ stream?: boolean;
45
+ }): Promise<void | ReadFileResponse>;
46
+ exposePort(port: number, options?: {
47
+ name?: string;
48
+ }): Promise<{
49
+ url: string;
50
+ port: number;
51
+ name: string | undefined;
52
+ }>;
53
+ unexposePort(port: number): Promise<void>;
54
+ getExposedPorts(): Promise<{
55
+ url: string;
56
+ port: number;
57
+ name: string | undefined;
58
+ exposedAt: string;
59
+ }[]>;
60
+ private getHostname;
61
+ private constructPreviewUrl;
62
+ }
63
+
64
+ interface ExecuteResponse {
65
+ success: boolean;
66
+ stdout: string;
67
+ stderr: string;
68
+ exitCode: number;
69
+ command: string;
70
+ args: string[];
71
+ timestamp: string;
72
+ }
73
+ interface SessionListResponse {
74
+ sessions: Array<{
75
+ sessionId: string;
76
+ hasActiveProcess: boolean;
77
+ createdAt: string;
78
+ }>;
79
+ count: number;
80
+ timestamp: string;
81
+ }
82
+ interface GitCheckoutResponse {
83
+ success: boolean;
84
+ stdout: string;
85
+ stderr: string;
86
+ exitCode: number;
87
+ repoUrl: string;
88
+ branch: string;
89
+ targetDir: string;
90
+ timestamp: string;
91
+ }
92
+ interface MkdirResponse {
93
+ success: boolean;
94
+ stdout: string;
95
+ stderr: string;
96
+ exitCode: number;
97
+ path: string;
98
+ recursive: boolean;
99
+ timestamp: string;
100
+ }
101
+ interface WriteFileResponse {
102
+ success: boolean;
103
+ exitCode: number;
104
+ path: string;
105
+ timestamp: string;
106
+ }
107
+ interface ReadFileResponse {
108
+ success: boolean;
109
+ exitCode: number;
110
+ path: string;
111
+ content: string;
112
+ timestamp: string;
113
+ }
114
+ interface DeleteFileResponse {
115
+ success: boolean;
116
+ exitCode: number;
117
+ path: string;
118
+ timestamp: string;
119
+ }
120
+ interface RenameFileResponse {
121
+ success: boolean;
122
+ exitCode: number;
123
+ oldPath: string;
124
+ newPath: string;
125
+ timestamp: string;
126
+ }
127
+ interface MoveFileResponse {
128
+ success: boolean;
129
+ exitCode: number;
130
+ sourcePath: string;
131
+ destinationPath: string;
132
+ timestamp: string;
133
+ }
134
+ interface PreviewInfo {
135
+ url: string;
136
+ port: number;
137
+ name?: string;
138
+ }
139
+ interface ExposedPort extends PreviewInfo {
140
+ exposedAt: string;
141
+ timestamp: string;
142
+ }
143
+ interface ExposePortResponse {
144
+ success: boolean;
145
+ port: number;
146
+ name?: string;
147
+ exposedAt: string;
148
+ timestamp: string;
149
+ }
150
+ interface UnexposePortResponse {
151
+ success: boolean;
152
+ port: number;
153
+ timestamp: string;
154
+ }
155
+ interface GetExposedPortsResponse {
156
+ ports: ExposedPort[];
157
+ count: number;
158
+ timestamp: string;
159
+ }
160
+ interface StreamEvent {
161
+ type: "command_start" | "output" | "command_complete" | "error";
162
+ command?: string;
163
+ args?: string[];
164
+ stream?: "stdout" | "stderr";
165
+ data?: string;
166
+ message?: string;
167
+ path?: string;
168
+ oldPath?: string;
169
+ newPath?: string;
170
+ sourcePath?: string;
171
+ destinationPath?: string;
172
+ content?: string;
173
+ success?: boolean;
174
+ exitCode?: number;
175
+ stdout?: string;
176
+ stderr?: string;
177
+ error?: string;
178
+ timestamp?: string;
179
+ }
180
+ interface HttpClientOptions {
181
+ stub?: Sandbox;
182
+ baseUrl?: string;
183
+ port?: number;
184
+ onCommandStart?: (command: string, args: string[]) => void;
185
+ onOutput?: (stream: "stdout" | "stderr", data: string, command: string) => void;
186
+ onCommandComplete?: (success: boolean, exitCode: number, stdout: string, stderr: string, command: string, args: string[]) => void;
187
+ onError?: (error: string, command?: string, args?: string[]) => void;
188
+ onStreamEvent?: (event: StreamEvent) => void;
189
+ }
190
+ declare class HttpClient {
191
+ private baseUrl;
192
+ private options;
193
+ private sessionId;
194
+ constructor(options?: HttpClientOptions);
195
+ private doFetch;
196
+ setOnOutput(handler: (stream: "stdout" | "stderr", data: string, command: string) => void): void;
197
+ setOnCommandComplete(handler: (success: boolean, exitCode: number, stdout: string, stderr: string, command: string, args: string[]) => void): void;
198
+ setOnStreamEvent(handler: (event: StreamEvent) => void): void;
199
+ getOnOutput(): ((stream: "stdout" | "stderr", data: string, command: string) => void) | undefined;
200
+ getOnCommandComplete(): ((success: boolean, exitCode: number, stdout: string, stderr: string, command: string, args: string[]) => void) | undefined;
201
+ getOnStreamEvent(): ((event: StreamEvent) => void) | undefined;
202
+ createSession(): Promise<string>;
203
+ listSessions(): Promise<SessionListResponse>;
204
+ execute(command: string, args?: string[], sessionId?: string, background?: boolean): Promise<ExecuteResponse>;
205
+ executeStream(command: string, args?: string[], sessionId?: string, background?: boolean): Promise<void>;
206
+ gitCheckout(repoUrl: string, branch?: string, targetDir?: string, sessionId?: string): Promise<GitCheckoutResponse>;
207
+ gitCheckoutStream(repoUrl: string, branch?: string, targetDir?: string, sessionId?: string): Promise<void>;
208
+ mkdir(path: string, recursive?: boolean, sessionId?: string): Promise<MkdirResponse>;
209
+ mkdirStream(path: string, recursive?: boolean, sessionId?: string): Promise<void>;
210
+ writeFile(path: string, content: string, encoding?: string, sessionId?: string): Promise<WriteFileResponse>;
211
+ writeFileStream(path: string, content: string, encoding?: string, sessionId?: string): Promise<void>;
212
+ readFile(path: string, encoding?: string, sessionId?: string): Promise<ReadFileResponse>;
213
+ readFileStream(path: string, encoding?: string, sessionId?: string): Promise<void>;
214
+ deleteFile(path: string, sessionId?: string): Promise<DeleteFileResponse>;
215
+ deleteFileStream(path: string, sessionId?: string): Promise<void>;
216
+ renameFile(oldPath: string, newPath: string, sessionId?: string): Promise<RenameFileResponse>;
217
+ renameFileStream(oldPath: string, newPath: string, sessionId?: string): Promise<void>;
218
+ moveFile(sourcePath: string, destinationPath: string, sessionId?: string): Promise<MoveFileResponse>;
219
+ moveFileStream(sourcePath: string, destinationPath: string, sessionId?: string): Promise<void>;
220
+ exposePort(port: number, name?: string): Promise<ExposePortResponse>;
221
+ unexposePort(port: number): Promise<UnexposePortResponse>;
222
+ getExposedPorts(): Promise<GetExposedPortsResponse>;
223
+ ping(): Promise<string>;
224
+ getCommands(): Promise<string[]>;
225
+ getSessionId(): string | null;
226
+ setSessionId(sessionId: string): void;
227
+ clearSession(): void;
228
+ }
229
+ declare function createClient(options?: HttpClientOptions): HttpClient;
230
+ declare function quickExecute(command: string, args?: string[], options?: HttpClientOptions): Promise<ExecuteResponse>;
231
+ declare function quickExecuteStream(command: string, args?: string[], options?: HttpClientOptions): Promise<void>;
232
+ declare function quickGitCheckout(repoUrl: string, branch?: string, targetDir?: string, options?: HttpClientOptions): Promise<GitCheckoutResponse>;
233
+ declare function quickMkdir(path: string, recursive?: boolean, options?: HttpClientOptions): Promise<MkdirResponse>;
234
+ declare function quickGitCheckoutStream(repoUrl: string, branch?: string, targetDir?: string, options?: HttpClientOptions): Promise<void>;
235
+ declare function quickMkdirStream(path: string, recursive?: boolean, options?: HttpClientOptions): Promise<void>;
236
+ declare function quickWriteFile(path: string, content: string, encoding?: string, options?: HttpClientOptions): Promise<WriteFileResponse>;
237
+ declare function quickWriteFileStream(path: string, content: string, encoding?: string, options?: HttpClientOptions): Promise<void>;
238
+ declare function quickReadFile(path: string, encoding?: string, options?: HttpClientOptions): Promise<ReadFileResponse>;
239
+ declare function quickReadFileStream(path: string, encoding?: string, options?: HttpClientOptions): Promise<void>;
240
+ declare function quickDeleteFile(path: string, options?: HttpClientOptions): Promise<DeleteFileResponse>;
241
+ declare function quickDeleteFileStream(path: string, options?: HttpClientOptions): Promise<void>;
242
+ declare function quickRenameFile(oldPath: string, newPath: string, options?: HttpClientOptions): Promise<RenameFileResponse>;
243
+ declare function quickRenameFileStream(oldPath: string, newPath: string, options?: HttpClientOptions): Promise<void>;
244
+ declare function quickMoveFile(sourcePath: string, destinationPath: string, options?: HttpClientOptions): Promise<MoveFileResponse>;
245
+ declare function quickMoveFileStream(sourcePath: string, destinationPath: string, options?: HttpClientOptions): Promise<void>;
246
+
247
+ export { type DeleteFileResponse as D, type ExecuteResponse as E, type GitCheckoutResponse as G, HttpClient as H, type MkdirResponse as M, type ReadFileResponse as R, Sandbox as S, type WriteFileResponse as W, type MoveFileResponse as a, type RenameFileResponse as b, createClient as c, quickExecuteStream as d, quickGitCheckout as e, quickMkdir as f, getSandbox as g, quickGitCheckoutStream as h, quickMkdirStream as i, quickWriteFile as j, quickWriteFileStream as k, quickReadFile as l, quickReadFileStream as m, quickDeleteFile as n, quickDeleteFileStream as o, quickRenameFile as p, quickExecute as q, quickRenameFileStream as r, quickMoveFile as s, quickMoveFileStream as t };
package/dist/client.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { D as DeleteFileResponse, E as ExecuteResponse, G as GitCheckoutResponse, H as HttpClient, M as MkdirResponse, b as MoveFileResponse, R as ReadFileResponse, a as RenameFileResponse, W as WriteFileResponse, c as createClient, m as quickDeleteFile, n as quickDeleteFileStream, q as quickExecute, d as quickExecuteStream, e as quickGitCheckout, g as quickGitCheckoutStream, f as quickMkdir, h as quickMkdirStream, r as quickMoveFile, s as quickMoveFileStream, k as quickReadFile, l as quickReadFileStream, o as quickRenameFile, p as quickRenameFileStream, i as quickWriteFile, j as quickWriteFileStream } from './index.js';
1
+ export { D as DeleteFileResponse, E as ExecuteResponse, G as GitCheckoutResponse, H as HttpClient, M as MkdirResponse, a as MoveFileResponse, R as ReadFileResponse, b as RenameFileResponse, W as WriteFileResponse, c as createClient, n as quickDeleteFile, o as quickDeleteFileStream, q as quickExecute, d as quickExecuteStream, e as quickGitCheckout, h as quickGitCheckoutStream, f as quickMkdir, i as quickMkdirStream, s as quickMoveFile, t as quickMoveFileStream, l as quickReadFile, m as quickReadFileStream, p as quickRenameFile, r as quickRenameFileStream, j as quickWriteFile, k as quickWriteFileStream } from './client-BuVjqV00.js';
2
2
  import '@cloudflare/containers';
package/dist/client.js CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  quickRenameFileStream,
18
18
  quickWriteFile,
19
19
  quickWriteFileStream
20
- } from "./chunk-7WZJ3TRE.js";
20
+ } from "./chunk-4J5LQCCN.js";
21
21
  export {
22
22
  HttpClient,
23
23
  createClient,
package/dist/index.d.ts CHANGED
@@ -1,200 +1,3 @@
1
- import { Container } from '@cloudflare/containers';
2
-
3
- declare function getSandbox(ns: DurableObjectNamespace<Sandbox>, id: string): DurableObjectStub<Sandbox<unknown>>;
4
- declare class Sandbox<Env = unknown> extends Container<Env> {
5
- defaultPort: number;
6
- sleepAfter: string;
7
- client: HttpClient;
8
- constructor(ctx: DurableObjectState, env: Env);
9
- envVars: {
10
- MESSAGE: string;
11
- };
12
- onStart(): void;
13
- onStop(): void;
14
- onError(error: unknown): void;
15
- exec(command: string, args: string[], options?: {
16
- stream?: boolean;
17
- }): Promise<void | ExecuteResponse>;
18
- gitCheckout(repoUrl: string, options: {
19
- branch?: string;
20
- targetDir?: string;
21
- stream?: boolean;
22
- }): Promise<void | GitCheckoutResponse>;
23
- mkdir(path: string, options?: {
24
- recursive?: boolean;
25
- stream?: boolean;
26
- }): Promise<void | MkdirResponse>;
27
- writeFile(path: string, content: string, options?: {
28
- encoding?: string;
29
- stream?: boolean;
30
- }): Promise<void | WriteFileResponse>;
31
- deleteFile(path: string, options?: {
32
- stream?: boolean;
33
- }): Promise<void | DeleteFileResponse>;
34
- renameFile(oldPath: string, newPath: string, options?: {
35
- stream?: boolean;
36
- }): Promise<void | RenameFileResponse>;
37
- moveFile(sourcePath: string, destinationPath: string, options?: {
38
- stream?: boolean;
39
- }): Promise<void | MoveFileResponse>;
40
- readFile(path: string, options?: {
41
- encoding?: string;
42
- stream?: boolean;
43
- }): Promise<void | ReadFileResponse>;
44
- }
45
-
46
- interface ExecuteResponse {
47
- success: boolean;
48
- stdout: string;
49
- stderr: string;
50
- exitCode: number;
51
- command: string;
52
- args: string[];
53
- timestamp: string;
54
- }
55
- interface SessionListResponse {
56
- sessions: Array<{
57
- sessionId: string;
58
- hasActiveProcess: boolean;
59
- createdAt: string;
60
- }>;
61
- count: number;
62
- timestamp: string;
63
- }
64
- interface GitCheckoutResponse {
65
- success: boolean;
66
- stdout: string;
67
- stderr: string;
68
- exitCode: number;
69
- repoUrl: string;
70
- branch: string;
71
- targetDir: string;
72
- timestamp: string;
73
- }
74
- interface MkdirResponse {
75
- success: boolean;
76
- stdout: string;
77
- stderr: string;
78
- exitCode: number;
79
- path: string;
80
- recursive: boolean;
81
- timestamp: string;
82
- }
83
- interface WriteFileResponse {
84
- success: boolean;
85
- exitCode: number;
86
- path: string;
87
- timestamp: string;
88
- }
89
- interface ReadFileResponse {
90
- success: boolean;
91
- exitCode: number;
92
- path: string;
93
- content: string;
94
- timestamp: string;
95
- }
96
- interface DeleteFileResponse {
97
- success: boolean;
98
- exitCode: number;
99
- path: string;
100
- timestamp: string;
101
- }
102
- interface RenameFileResponse {
103
- success: boolean;
104
- exitCode: number;
105
- oldPath: string;
106
- newPath: string;
107
- timestamp: string;
108
- }
109
- interface MoveFileResponse {
110
- success: boolean;
111
- exitCode: number;
112
- sourcePath: string;
113
- destinationPath: string;
114
- timestamp: string;
115
- }
116
- interface StreamEvent {
117
- type: "command_start" | "output" | "command_complete" | "error";
118
- command?: string;
119
- args?: string[];
120
- stream?: "stdout" | "stderr";
121
- data?: string;
122
- message?: string;
123
- path?: string;
124
- oldPath?: string;
125
- newPath?: string;
126
- sourcePath?: string;
127
- destinationPath?: string;
128
- content?: string;
129
- success?: boolean;
130
- exitCode?: number;
131
- stdout?: string;
132
- stderr?: string;
133
- error?: string;
134
- timestamp?: string;
135
- }
136
- interface HttpClientOptions {
137
- stub?: Sandbox;
138
- baseUrl?: string;
139
- port?: number;
140
- onCommandStart?: (command: string, args: string[]) => void;
141
- onOutput?: (stream: "stdout" | "stderr", data: string, command: string) => void;
142
- onCommandComplete?: (success: boolean, exitCode: number, stdout: string, stderr: string, command: string, args: string[]) => void;
143
- onError?: (error: string, command?: string, args?: string[]) => void;
144
- onStreamEvent?: (event: StreamEvent) => void;
145
- }
146
- declare class HttpClient {
147
- private baseUrl;
148
- private options;
149
- private sessionId;
150
- constructor(options?: HttpClientOptions);
151
- private doFetch;
152
- setOnOutput(handler: (stream: "stdout" | "stderr", data: string, command: string) => void): void;
153
- setOnCommandComplete(handler: (success: boolean, exitCode: number, stdout: string, stderr: string, command: string, args: string[]) => void): void;
154
- setOnStreamEvent(handler: (event: StreamEvent) => void): void;
155
- getOnOutput(): ((stream: "stdout" | "stderr", data: string, command: string) => void) | undefined;
156
- getOnCommandComplete(): ((success: boolean, exitCode: number, stdout: string, stderr: string, command: string, args: string[]) => void) | undefined;
157
- getOnStreamEvent(): ((event: StreamEvent) => void) | undefined;
158
- createSession(): Promise<string>;
159
- listSessions(): Promise<SessionListResponse>;
160
- execute(command: string, args?: string[], sessionId?: string): Promise<ExecuteResponse>;
161
- executeStream(command: string, args?: string[], sessionId?: string): Promise<void>;
162
- gitCheckout(repoUrl: string, branch?: string, targetDir?: string, sessionId?: string): Promise<GitCheckoutResponse>;
163
- gitCheckoutStream(repoUrl: string, branch?: string, targetDir?: string, sessionId?: string): Promise<void>;
164
- mkdir(path: string, recursive?: boolean, sessionId?: string): Promise<MkdirResponse>;
165
- mkdirStream(path: string, recursive?: boolean, sessionId?: string): Promise<void>;
166
- writeFile(path: string, content: string, encoding?: string, sessionId?: string): Promise<WriteFileResponse>;
167
- writeFileStream(path: string, content: string, encoding?: string, sessionId?: string): Promise<void>;
168
- readFile(path: string, encoding?: string, sessionId?: string): Promise<ReadFileResponse>;
169
- readFileStream(path: string, encoding?: string, sessionId?: string): Promise<void>;
170
- deleteFile(path: string, sessionId?: string): Promise<DeleteFileResponse>;
171
- deleteFileStream(path: string, sessionId?: string): Promise<void>;
172
- renameFile(oldPath: string, newPath: string, sessionId?: string): Promise<RenameFileResponse>;
173
- renameFileStream(oldPath: string, newPath: string, sessionId?: string): Promise<void>;
174
- moveFile(sourcePath: string, destinationPath: string, sessionId?: string): Promise<MoveFileResponse>;
175
- moveFileStream(sourcePath: string, destinationPath: string, sessionId?: string): Promise<void>;
176
- ping(): Promise<string>;
177
- getCommands(): Promise<string[]>;
178
- getSessionId(): string | null;
179
- setSessionId(sessionId: string): void;
180
- clearSession(): void;
181
- }
182
- declare function createClient(options?: HttpClientOptions): HttpClient;
183
- declare function quickExecute(command: string, args?: string[], options?: HttpClientOptions): Promise<ExecuteResponse>;
184
- declare function quickExecuteStream(command: string, args?: string[], options?: HttpClientOptions): Promise<void>;
185
- declare function quickGitCheckout(repoUrl: string, branch?: string, targetDir?: string, options?: HttpClientOptions): Promise<GitCheckoutResponse>;
186
- declare function quickMkdir(path: string, recursive?: boolean, options?: HttpClientOptions): Promise<MkdirResponse>;
187
- declare function quickGitCheckoutStream(repoUrl: string, branch?: string, targetDir?: string, options?: HttpClientOptions): Promise<void>;
188
- declare function quickMkdirStream(path: string, recursive?: boolean, options?: HttpClientOptions): Promise<void>;
189
- declare function quickWriteFile(path: string, content: string, encoding?: string, options?: HttpClientOptions): Promise<WriteFileResponse>;
190
- declare function quickWriteFileStream(path: string, content: string, encoding?: string, options?: HttpClientOptions): Promise<void>;
191
- declare function quickReadFile(path: string, encoding?: string, options?: HttpClientOptions): Promise<ReadFileResponse>;
192
- declare function quickReadFileStream(path: string, encoding?: string, options?: HttpClientOptions): Promise<void>;
193
- declare function quickDeleteFile(path: string, options?: HttpClientOptions): Promise<DeleteFileResponse>;
194
- declare function quickDeleteFileStream(path: string, options?: HttpClientOptions): Promise<void>;
195
- declare function quickRenameFile(oldPath: string, newPath: string, options?: HttpClientOptions): Promise<RenameFileResponse>;
196
- declare function quickRenameFileStream(oldPath: string, newPath: string, options?: HttpClientOptions): Promise<void>;
197
- declare function quickMoveFile(sourcePath: string, destinationPath: string, options?: HttpClientOptions): Promise<MoveFileResponse>;
198
- declare function quickMoveFileStream(sourcePath: string, destinationPath: string, options?: HttpClientOptions): Promise<void>;
199
-
200
- export { type DeleteFileResponse as D, type ExecuteResponse as E, type GitCheckoutResponse as G, HttpClient as H, type MkdirResponse as M, type ReadFileResponse as R, Sandbox, type WriteFileResponse as W, type RenameFileResponse as a, type MoveFileResponse as b, createClient as c, quickExecuteStream as d, quickGitCheckout as e, quickMkdir as f, quickGitCheckoutStream as g, getSandbox, quickMkdirStream as h, quickWriteFile as i, quickWriteFileStream as j, quickReadFile as k, quickReadFileStream as l, quickDeleteFile as m, quickDeleteFileStream as n, quickRenameFile as o, quickRenameFileStream as p, quickExecute as q, quickMoveFile as r, quickMoveFileStream as s };
1
+ export { D as DeleteFileResponse, E as ExecuteResponse, G as GitCheckoutResponse, M as MkdirResponse, a as MoveFileResponse, R as ReadFileResponse, b as RenameFileResponse, S as Sandbox, W as WriteFileResponse, g as getSandbox } from './client-BuVjqV00.js';
2
+ export { RouteInfo, SandboxEnv, proxyToSandbox } from './request-handler.js';
3
+ import '@cloudflare/containers';
package/dist/index.js CHANGED
@@ -1,111 +1,12 @@
1
1
  import {
2
- HttpClient
3
- } from "./chunk-7WZJ3TRE.js";
4
-
5
- // src/index.ts
6
- import { Container, getContainer } from "@cloudflare/containers";
7
- function getSandbox(ns, id) {
8
- return getContainer(ns, id);
9
- }
10
- var Sandbox = class extends Container {
11
- defaultPort = 3e3;
12
- // The default port for the container to listen on
13
- sleepAfter = "3m";
14
- // Sleep the sandbox if no requests are made in this timeframe
15
- client;
16
- constructor(ctx, env) {
17
- super(ctx, env);
18
- this.client = new HttpClient({
19
- onCommandComplete: (success, exitCode, stdout, stderr, command, args) => {
20
- console.log(
21
- `[Container] Command completed: ${command}, Success: ${success}, Exit code: ${exitCode}`
22
- );
23
- },
24
- onCommandStart: (command, args) => {
25
- console.log(
26
- `[Container] Command started: ${command} ${args.join(" ")}`
27
- );
28
- },
29
- onError: (error, command, args) => {
30
- console.error(`[Container] Command error: ${error}`);
31
- },
32
- onOutput: (stream, data, command) => {
33
- console.log(`[Container] [${stream}] ${data}`);
34
- },
35
- port: this.defaultPort,
36
- stub: this
37
- });
38
- }
39
- envVars = {
40
- MESSAGE: "I was passed in via the Sandbox class!"
41
- };
42
- onStart() {
43
- console.log("Sandbox successfully started");
44
- }
45
- onStop() {
46
- console.log("Sandbox successfully shut down");
47
- if (this.client) {
48
- this.client.clearSession();
49
- }
50
- }
51
- onError(error) {
52
- console.log("Sandbox error:", error);
53
- }
54
- async exec(command, args, options) {
55
- if (options?.stream) {
56
- return this.client.executeStream(command, args);
57
- }
58
- return this.client.execute(command, args);
59
- }
60
- async gitCheckout(repoUrl, options) {
61
- if (options?.stream) {
62
- return this.client.gitCheckoutStream(
63
- repoUrl,
64
- options.branch,
65
- options.targetDir
66
- );
67
- }
68
- return this.client.gitCheckout(repoUrl, options.branch, options.targetDir);
69
- }
70
- async mkdir(path, options = {}) {
71
- if (options?.stream) {
72
- return this.client.mkdirStream(path, options.recursive);
73
- }
74
- return this.client.mkdir(path, options.recursive);
75
- }
76
- async writeFile(path, content, options = {}) {
77
- if (options?.stream) {
78
- return this.client.writeFileStream(path, content, options.encoding);
79
- }
80
- return this.client.writeFile(path, content, options.encoding);
81
- }
82
- async deleteFile(path, options = {}) {
83
- if (options?.stream) {
84
- return this.client.deleteFileStream(path);
85
- }
86
- return this.client.deleteFile(path);
87
- }
88
- async renameFile(oldPath, newPath, options = {}) {
89
- if (options?.stream) {
90
- return this.client.renameFileStream(oldPath, newPath);
91
- }
92
- return this.client.renameFile(oldPath, newPath);
93
- }
94
- async moveFile(sourcePath, destinationPath, options = {}) {
95
- if (options?.stream) {
96
- return this.client.moveFileStream(sourcePath, destinationPath);
97
- }
98
- return this.client.moveFile(sourcePath, destinationPath);
99
- }
100
- async readFile(path, options = {}) {
101
- if (options?.stream) {
102
- return this.client.readFileStream(path, options.encoding);
103
- }
104
- return this.client.readFile(path, options.encoding);
105
- }
106
- };
2
+ Sandbox,
3
+ getSandbox,
4
+ proxyToSandbox
5
+ } from "./chunk-5SZ3RVJZ.js";
6
+ import "./chunk-4J5LQCCN.js";
107
7
  export {
108
8
  Sandbox,
109
- getSandbox
9
+ getSandbox,
10
+ proxyToSandbox
110
11
  };
111
12
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Container, getContainer } from \"@cloudflare/containers\";\nimport { HttpClient } from \"./client\";\n\nexport function getSandbox(ns: DurableObjectNamespace<Sandbox>, id: string) {\n return getContainer(ns, id);\n}\n\nexport class Sandbox<Env = unknown> extends Container<Env> {\n defaultPort = 3000; // The default port for the container to listen on\n sleepAfter = \"3m\"; // Sleep the sandbox if no requests are made in this timeframe\n client: HttpClient;\n\n constructor(ctx: DurableObjectState, env: Env) {\n super(ctx, env);\n this.client = new HttpClient({\n onCommandComplete: (success, exitCode, stdout, stderr, command, args) => {\n console.log(\n `[Container] Command completed: ${command}, Success: ${success}, Exit code: ${exitCode}`\n );\n },\n onCommandStart: (command, args) => {\n console.log(\n `[Container] Command started: ${command} ${args.join(\" \")}`\n );\n },\n onError: (error, command, args) => {\n console.error(`[Container] Command error: ${error}`);\n },\n onOutput: (stream, data, command) => {\n console.log(`[Container] [${stream}] ${data}`);\n },\n port: this.defaultPort,\n stub: this,\n });\n }\n\n envVars = {\n MESSAGE: \"I was passed in via the Sandbox class!\",\n };\n\n override onStart() {\n console.log(\"Sandbox successfully started\");\n }\n\n override onStop() {\n console.log(\"Sandbox successfully shut down\");\n if (this.client) {\n this.client.clearSession();\n }\n }\n\n override onError(error: unknown) {\n console.log(\"Sandbox error:\", error);\n }\n\n async exec(command: string, args: string[], options?: { stream?: boolean }) {\n if (options?.stream) {\n return this.client.executeStream(command, args);\n }\n return this.client.execute(command, args);\n }\n\n async gitCheckout(\n repoUrl: string,\n options: { branch?: string; targetDir?: string; stream?: boolean }\n ) {\n if (options?.stream) {\n return this.client.gitCheckoutStream(\n repoUrl,\n options.branch,\n options.targetDir\n );\n }\n return this.client.gitCheckout(repoUrl, options.branch, options.targetDir);\n }\n\n async mkdir(\n path: string,\n options: { recursive?: boolean; stream?: boolean } = {}\n ) {\n if (options?.stream) {\n return this.client.mkdirStream(path, options.recursive);\n }\n return this.client.mkdir(path, options.recursive);\n }\n\n async writeFile(\n path: string,\n content: string,\n options: { encoding?: string; stream?: boolean } = {}\n ) {\n if (options?.stream) {\n return this.client.writeFileStream(path, content, options.encoding);\n }\n return this.client.writeFile(path, content, options.encoding);\n }\n\n async deleteFile(path: string, options: { stream?: boolean } = {}) {\n if (options?.stream) {\n return this.client.deleteFileStream(path);\n }\n return this.client.deleteFile(path);\n }\n\n async renameFile(\n oldPath: string,\n newPath: string,\n options: { stream?: boolean } = {}\n ) {\n if (options?.stream) {\n return this.client.renameFileStream(oldPath, newPath);\n }\n return this.client.renameFile(oldPath, newPath);\n }\n\n async moveFile(\n sourcePath: string,\n destinationPath: string,\n options: { stream?: boolean } = {}\n ) {\n if (options?.stream) {\n return this.client.moveFileStream(sourcePath, destinationPath);\n }\n return this.client.moveFile(sourcePath, destinationPath);\n }\n\n async readFile(\n path: string,\n options: { encoding?: string; stream?: boolean } = {}\n ) {\n if (options?.stream) {\n return this.client.readFileStream(path, options.encoding);\n }\n return this.client.readFile(path, options.encoding);\n }\n}\n"],"mappings":"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","names":[]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,15 @@
1
+ import { S as Sandbox } from './client-BuVjqV00.js';
2
+ import '@cloudflare/containers';
3
+
4
+ interface SandboxEnv {
5
+ Sandbox: DurableObjectNamespace<Sandbox>;
6
+ }
7
+ interface RouteInfo {
8
+ port: number;
9
+ sandboxId: string;
10
+ path: string;
11
+ }
12
+ declare function proxyToSandbox<E extends SandboxEnv>(request: Request, env: E): Promise<Response | null>;
13
+ declare function isLocalhostPattern(hostname: string): boolean;
14
+
15
+ export { type RouteInfo, type SandboxEnv, isLocalhostPattern, proxyToSandbox };
@@ -0,0 +1,10 @@
1
+ import {
2
+ isLocalhostPattern,
3
+ proxyToSandbox
4
+ } from "./chunk-5SZ3RVJZ.js";
5
+ import "./chunk-4J5LQCCN.js";
6
+ export {
7
+ isLocalhostPattern,
8
+ proxyToSandbox
9
+ };
10
+ //# sourceMappingURL=request-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,2 @@
1
+ export { S as Sandbox, g as getSandbox } from './client-BuVjqV00.js';
2
+ import '@cloudflare/containers';
@@ -0,0 +1,10 @@
1
+ import {
2
+ Sandbox,
3
+ getSandbox
4
+ } from "./chunk-5SZ3RVJZ.js";
5
+ import "./chunk-4J5LQCCN.js";
6
+ export {
7
+ Sandbox,
8
+ getSandbox
9
+ };
10
+ //# sourceMappingURL=sandbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@cloudflare/sandbox",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cloudflare/sandbox-sdk"
7
7
  },
8
8
  "description": "A sandboxed environment for running commands",
9
9
  "dependencies": {
10
- "@cloudflare/containers": "^0.0.19"
10
+ "@cloudflare/containers": "^0.0.23"
11
11
  },
12
12
  "tags": [
13
13
  "sandbox",