@cloudflare/sandbox 0.0.0-7de28be → 0.0.0-7edbfa9

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +232 -0
  2. package/Dockerfile +125 -55
  3. package/README.md +89 -488
  4. package/dist/index.d.ts +1907 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +3159 -0
  7. package/dist/index.js.map +1 -0
  8. package/package.json +16 -8
  9. package/src/clients/base-client.ts +295 -0
  10. package/src/clients/command-client.ts +115 -0
  11. package/src/clients/file-client.ts +300 -0
  12. package/src/clients/git-client.ts +91 -0
  13. package/src/clients/index.ts +60 -0
  14. package/src/clients/interpreter-client.ts +333 -0
  15. package/src/clients/port-client.ts +105 -0
  16. package/src/clients/process-client.ts +180 -0
  17. package/src/clients/sandbox-client.ts +39 -0
  18. package/src/clients/types.ts +88 -0
  19. package/src/clients/utility-client.ts +123 -0
  20. package/src/errors/adapter.ts +238 -0
  21. package/src/errors/classes.ts +594 -0
  22. package/src/errors/index.ts +109 -0
  23. package/src/file-stream.ts +169 -0
  24. package/src/index.ts +94 -14
  25. package/src/interpreter.ts +168 -0
  26. package/src/request-handler.ts +94 -55
  27. package/src/sandbox.ts +917 -320
  28. package/src/security.ts +34 -28
  29. package/src/sse-parser.ts +8 -11
  30. package/src/version.ts +6 -0
  31. package/startup.sh +3 -0
  32. package/tests/base-client.test.ts +364 -0
  33. package/tests/command-client.test.ts +444 -0
  34. package/tests/file-client.test.ts +831 -0
  35. package/tests/file-stream.test.ts +310 -0
  36. package/tests/get-sandbox.test.ts +149 -0
  37. package/tests/git-client.test.ts +415 -0
  38. package/tests/port-client.test.ts +293 -0
  39. package/tests/process-client.test.ts +683 -0
  40. package/tests/request-handler.test.ts +292 -0
  41. package/tests/sandbox.test.ts +702 -0
  42. package/tests/sse-parser.test.ts +291 -0
  43. package/tests/utility-client.test.ts +339 -0
  44. package/tests/version.test.ts +16 -0
  45. package/tests/wrangler.jsonc +35 -0
  46. package/tsconfig.json +9 -1
  47. package/tsdown.config.ts +12 -0
  48. package/vitest.config.ts +31 -0
  49. package/container_src/handler/exec.ts +0 -338
  50. package/container_src/handler/file.ts +0 -844
  51. package/container_src/handler/git.ts +0 -182
  52. package/container_src/handler/ports.ts +0 -314
  53. package/container_src/handler/process.ts +0 -640
  54. package/container_src/index.ts +0 -361
  55. package/container_src/package.json +0 -9
  56. package/container_src/types.ts +0 -108
  57. package/src/client.ts +0 -1038
  58. package/src/types.ts +0 -386
@@ -0,0 +1,291 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import {
3
+ asyncIterableToSSEStream,
4
+ parseSSEStream,
5
+ responseToAsyncIterable
6
+ } from '../src/sse-parser';
7
+
8
+ function createMockSSEStream(events: string[]): ReadableStream<Uint8Array> {
9
+ return new ReadableStream({
10
+ start(controller) {
11
+ const encoder = new TextEncoder();
12
+ for (const event of events) {
13
+ controller.enqueue(encoder.encode(event));
14
+ }
15
+ controller.close();
16
+ }
17
+ });
18
+ }
19
+
20
+ describe('SSE Parser', () => {
21
+ let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
22
+
23
+ beforeEach(() => {
24
+ consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
25
+ });
26
+
27
+ afterEach(() => {
28
+ consoleErrorSpy.mockRestore();
29
+ });
30
+
31
+ describe('parseSSEStream', () => {
32
+ it('should parse valid SSE events', async () => {
33
+ const stream = createMockSSEStream([
34
+ 'data: {"type":"start","command":"echo test"}\n\n',
35
+ 'data: {"type":"stdout","data":"test\\n"}\n\n',
36
+ 'data: {"type":"complete","exitCode":0}\n\n'
37
+ ]);
38
+
39
+ const events: any[] = [];
40
+ for await (const event of parseSSEStream(stream)) {
41
+ events.push(event);
42
+ }
43
+
44
+ expect(events).toHaveLength(3);
45
+ expect(events[0]).toEqual({ type: 'start', command: 'echo test' });
46
+ expect(events[1]).toEqual({ type: 'stdout', data: 'test\n' });
47
+ expect(events[2]).toEqual({ type: 'complete', exitCode: 0 });
48
+ });
49
+
50
+ it('should handle empty data lines', async () => {
51
+ const stream = createMockSSEStream([
52
+ 'data: \n\n',
53
+ 'data: {"type":"stdout","data":"valid"}\n\n'
54
+ ]);
55
+
56
+ const events: any[] = [];
57
+ for await (const event of parseSSEStream(stream)) {
58
+ events.push(event);
59
+ }
60
+
61
+ expect(events).toHaveLength(1);
62
+ expect(events[0]).toEqual({ type: 'stdout', data: 'valid' });
63
+ });
64
+
65
+ it('should skip [DONE] markers', async () => {
66
+ const stream = createMockSSEStream([
67
+ 'data: {"type":"start"}\n\n',
68
+ 'data: [DONE]\n\n',
69
+ 'data: {"type":"complete"}\n\n'
70
+ ]);
71
+
72
+ const events: any[] = [];
73
+ for await (const event of parseSSEStream(stream)) {
74
+ events.push(event);
75
+ }
76
+
77
+ expect(events).toHaveLength(2);
78
+ expect(events[0]).toEqual({ type: 'start' });
79
+ expect(events[1]).toEqual({ type: 'complete' });
80
+ });
81
+
82
+ it('should handle malformed JSON gracefully', async () => {
83
+ const stream = createMockSSEStream([
84
+ 'data: invalid json\n\n',
85
+ 'data: {"type":"stdout","data":"valid"}\n\n',
86
+ 'data: {incomplete\n\n'
87
+ ]);
88
+
89
+ const events: any[] = [];
90
+ for await (const event of parseSSEStream(stream)) {
91
+ events.push(event);
92
+ }
93
+
94
+ expect(events).toHaveLength(1);
95
+ expect(events[0]).toEqual({ type: 'stdout', data: 'valid' });
96
+ });
97
+
98
+ it('should handle empty lines and comments', async () => {
99
+ const stream = createMockSSEStream([
100
+ '\n',
101
+ ' \n',
102
+ ': this is a comment\n',
103
+ 'data: {"type":"test"}\n\n',
104
+ '\n'
105
+ ]);
106
+
107
+ const events: any[] = [];
108
+ for await (const event of parseSSEStream(stream)) {
109
+ events.push(event);
110
+ }
111
+
112
+ expect(events).toHaveLength(1);
113
+ expect(events[0]).toEqual({ type: 'test' });
114
+ });
115
+
116
+ it('should handle chunked data properly', async () => {
117
+ // Simulate chunked delivery where data arrives in parts
118
+ const stream = new ReadableStream({
119
+ start(controller) {
120
+ const encoder = new TextEncoder();
121
+ // Send partial data
122
+ controller.enqueue(encoder.encode('data: {"typ'));
123
+ controller.enqueue(encoder.encode('e":"start"}\n\n'));
124
+ controller.enqueue(encoder.encode('data: {"type":"end"}\n\n'));
125
+ controller.close();
126
+ }
127
+ });
128
+
129
+ const events: any[] = [];
130
+ for await (const event of parseSSEStream(stream)) {
131
+ events.push(event);
132
+ }
133
+
134
+ expect(events).toHaveLength(2);
135
+ expect(events[0]).toEqual({ type: 'start' });
136
+ expect(events[1]).toEqual({ type: 'end' });
137
+ });
138
+
139
+ it('should handle remaining buffer data after stream ends', async () => {
140
+ const stream = createMockSSEStream(['data: {"type":"complete"}']);
141
+
142
+ const events: any[] = [];
143
+ for await (const event of parseSSEStream(stream)) {
144
+ events.push(event);
145
+ }
146
+
147
+ expect(events).toHaveLength(1);
148
+ expect(events[0]).toEqual({ type: 'complete' });
149
+ });
150
+
151
+ it('should support cancellation via AbortSignal', async () => {
152
+ const controller = new AbortController();
153
+ const stream = createMockSSEStream(['data: {"type":"start"}\n\n']);
154
+ controller.abort();
155
+
156
+ await expect(async () => {
157
+ for await (const event of parseSSEStream(stream, controller.signal)) {
158
+ }
159
+ }).rejects.toThrow('Operation was aborted');
160
+ });
161
+
162
+ it('should handle non-data SSE lines', async () => {
163
+ const stream = createMockSSEStream([
164
+ 'event: message\n',
165
+ 'id: 123\n',
166
+ 'retry: 3000\n',
167
+ 'data: {"type":"test"}\n\n'
168
+ ]);
169
+
170
+ const events: any[] = [];
171
+ for await (const event of parseSSEStream(stream)) {
172
+ events.push(event);
173
+ }
174
+
175
+ expect(events).toHaveLength(1);
176
+ expect(events[0]).toEqual({ type: 'test' });
177
+ });
178
+ });
179
+
180
+ describe('responseToAsyncIterable', () => {
181
+ it('should convert Response with SSE stream to AsyncIterable', async () => {
182
+ const mockBody = createMockSSEStream([
183
+ 'data: {"type":"start"}\n\n',
184
+ 'data: {"type":"end"}\n\n'
185
+ ]);
186
+
187
+ const mockResponse = {
188
+ ok: true,
189
+ body: mockBody
190
+ } as Response;
191
+
192
+ const events: any[] = [];
193
+ for await (const event of responseToAsyncIterable(mockResponse)) {
194
+ events.push(event);
195
+ }
196
+
197
+ expect(events).toHaveLength(2);
198
+ expect(events[0]).toEqual({ type: 'start' });
199
+ expect(events[1]).toEqual({ type: 'end' });
200
+ });
201
+
202
+ it('should throw error for non-ok response', async () => {
203
+ const mockResponse = {
204
+ ok: false,
205
+ status: 500,
206
+ statusText: 'Internal Server Error'
207
+ } as Response;
208
+
209
+ await expect(async () => {
210
+ for await (const event of responseToAsyncIterable(mockResponse)) {
211
+ // Should not reach here
212
+ }
213
+ }).rejects.toThrow('Response not ok: 500 Internal Server Error');
214
+ });
215
+
216
+ it('should throw error for response without body', async () => {
217
+ const mockResponse = {
218
+ ok: true,
219
+ body: null
220
+ } as Response;
221
+
222
+ await expect(async () => {
223
+ for await (const event of responseToAsyncIterable(mockResponse)) {
224
+ // Should not reach here
225
+ }
226
+ }).rejects.toThrow('No response body');
227
+ });
228
+ });
229
+
230
+ describe('asyncIterableToSSEStream', () => {
231
+ it('should convert AsyncIterable to SSE-formatted ReadableStream', async () => {
232
+ async function* mockEvents() {
233
+ yield { type: 'start', command: 'test' };
234
+ yield { type: 'stdout', data: 'output' };
235
+ yield { type: 'complete', exitCode: 0 };
236
+ }
237
+
238
+ const stream = asyncIterableToSSEStream(mockEvents());
239
+ const reader = stream.getReader();
240
+ const decoder = new TextDecoder();
241
+
242
+ const chunks: string[] = [];
243
+ let done = false;
244
+
245
+ while (!done) {
246
+ const { value, done: readerDone } = await reader.read();
247
+ done = readerDone;
248
+ if (value) {
249
+ chunks.push(decoder.decode(value));
250
+ }
251
+ }
252
+
253
+ const fullOutput = chunks.join('');
254
+ expect(fullOutput).toBe(
255
+ 'data: {"type":"start","command":"test"}\n\n' +
256
+ 'data: {"type":"stdout","data":"output"}\n\n' +
257
+ 'data: {"type":"complete","exitCode":0}\n\n' +
258
+ 'data: [DONE]\n\n'
259
+ );
260
+ });
261
+
262
+ it('should use custom serializer when provided', async () => {
263
+ async function* mockEvents() {
264
+ yield { name: 'test', value: 123 };
265
+ }
266
+
267
+ const stream = asyncIterableToSSEStream(mockEvents(), {
268
+ serialize: (event) => `custom:${event.name}=${event.value}`
269
+ });
270
+
271
+ const reader = stream.getReader();
272
+ const decoder = new TextDecoder();
273
+ const { value } = await reader.read();
274
+
275
+ expect(decoder.decode(value!)).toBe('data: custom:test=123\n\n');
276
+ });
277
+
278
+ it('should handle errors in async iterable', async () => {
279
+ async function* mockEvents() {
280
+ yield { type: 'start' };
281
+ throw new Error('Async iterable error');
282
+ }
283
+
284
+ const stream = asyncIterableToSSEStream(mockEvents());
285
+ const reader = stream.getReader();
286
+
287
+ await reader.read();
288
+ await expect(reader.read()).rejects.toThrow('Async iterable error');
289
+ });
290
+ });
291
+ });
@@ -0,0 +1,339 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import type {
3
+ CommandsResponse,
4
+ PingResponse,
5
+ VersionResponse
6
+ } from '../src/clients';
7
+ import { UtilityClient } from '../src/clients/utility-client';
8
+ import { SandboxError } from '../src/errors';
9
+
10
+ // Mock data factory for creating test responses
11
+ const mockPingResponse = (
12
+ overrides: Partial<PingResponse> = {}
13
+ ): PingResponse => ({
14
+ success: true,
15
+ message: 'pong',
16
+ uptime: 12345,
17
+ timestamp: '2023-01-01T00:00:00Z',
18
+ ...overrides
19
+ });
20
+
21
+ const mockCommandsResponse = (
22
+ commands: string[],
23
+ overrides: Partial<CommandsResponse> = {}
24
+ ): CommandsResponse => ({
25
+ success: true,
26
+ availableCommands: commands,
27
+ count: commands.length,
28
+ timestamp: '2023-01-01T00:00:00Z',
29
+ ...overrides
30
+ });
31
+
32
+ const mockVersionResponse = (
33
+ version: string = '0.4.5',
34
+ overrides: Partial<VersionResponse> = {}
35
+ ): VersionResponse => ({
36
+ success: true,
37
+ version,
38
+ timestamp: '2023-01-01T00:00:00Z',
39
+ ...overrides
40
+ });
41
+
42
+ describe('UtilityClient', () => {
43
+ let client: UtilityClient;
44
+ let mockFetch: ReturnType<typeof vi.fn>;
45
+
46
+ beforeEach(() => {
47
+ vi.clearAllMocks();
48
+
49
+ mockFetch = vi.fn();
50
+ global.fetch = mockFetch as unknown as typeof fetch;
51
+
52
+ client = new UtilityClient({
53
+ baseUrl: 'http://test.com',
54
+ port: 3000
55
+ });
56
+ });
57
+
58
+ afterEach(() => {
59
+ vi.restoreAllMocks();
60
+ });
61
+
62
+ describe('health checking', () => {
63
+ it('should check sandbox health successfully', async () => {
64
+ mockFetch.mockResolvedValue(
65
+ new Response(JSON.stringify(mockPingResponse()), { status: 200 })
66
+ );
67
+
68
+ const result = await client.ping();
69
+
70
+ expect(result).toBe('pong');
71
+ });
72
+
73
+ it('should handle different health messages', async () => {
74
+ const messages = ['pong', 'alive', 'ok'];
75
+
76
+ for (const message of messages) {
77
+ mockFetch.mockResolvedValueOnce(
78
+ new Response(JSON.stringify(mockPingResponse({ message })), {
79
+ status: 200
80
+ })
81
+ );
82
+
83
+ const result = await client.ping();
84
+ expect(result).toBe(message);
85
+ }
86
+ });
87
+
88
+ it('should handle concurrent health checks', async () => {
89
+ mockFetch.mockImplementation(() =>
90
+ Promise.resolve(new Response(JSON.stringify(mockPingResponse())))
91
+ );
92
+
93
+ const healthChecks = await Promise.all([
94
+ client.ping(),
95
+ client.ping(),
96
+ client.ping()
97
+ ]);
98
+
99
+ expect(healthChecks).toHaveLength(3);
100
+ healthChecks.forEach((result) => {
101
+ expect(result).toBe('pong');
102
+ });
103
+
104
+ expect(mockFetch).toHaveBeenCalledTimes(3);
105
+ });
106
+
107
+ it('should detect unhealthy sandbox conditions', async () => {
108
+ const errorResponse = {
109
+ error: 'Service Unavailable',
110
+ code: 'HEALTH_CHECK_FAILED'
111
+ };
112
+
113
+ mockFetch.mockResolvedValue(
114
+ new Response(JSON.stringify(errorResponse), { status: 503 })
115
+ );
116
+
117
+ await expect(client.ping()).rejects.toThrow();
118
+ });
119
+
120
+ it('should handle network failures during health checks', async () => {
121
+ mockFetch.mockRejectedValue(new Error('Network connection failed'));
122
+
123
+ await expect(client.ping()).rejects.toThrow('Network connection failed');
124
+ });
125
+ });
126
+
127
+ describe('command discovery', () => {
128
+ it('should discover available system commands', async () => {
129
+ const systemCommands = ['ls', 'cat', 'echo', 'grep', 'find'];
130
+
131
+ mockFetch.mockResolvedValue(
132
+ new Response(JSON.stringify(mockCommandsResponse(systemCommands)), {
133
+ status: 200
134
+ })
135
+ );
136
+
137
+ const result = await client.getCommands();
138
+
139
+ expect(result).toEqual(systemCommands);
140
+ expect(result).toContain('ls');
141
+ expect(result).toContain('grep');
142
+ expect(result).toHaveLength(systemCommands.length);
143
+ });
144
+
145
+ it('should handle minimal command environments', async () => {
146
+ const minimalCommands = ['sh', 'echo', 'cat'];
147
+
148
+ mockFetch.mockResolvedValue(
149
+ new Response(JSON.stringify(mockCommandsResponse(minimalCommands)), {
150
+ status: 200
151
+ })
152
+ );
153
+
154
+ const result = await client.getCommands();
155
+
156
+ expect(result).toEqual(minimalCommands);
157
+ expect(result).toHaveLength(3);
158
+ });
159
+
160
+ it('should handle large command environments', async () => {
161
+ const richCommands = Array.from({ length: 150 }, (_, i) => `cmd_${i}`);
162
+
163
+ mockFetch.mockResolvedValue(
164
+ new Response(JSON.stringify(mockCommandsResponse(richCommands)), {
165
+ status: 200
166
+ })
167
+ );
168
+
169
+ const result = await client.getCommands();
170
+
171
+ expect(result).toEqual(richCommands);
172
+ expect(result).toHaveLength(150);
173
+ });
174
+
175
+ it('should handle empty command environments', async () => {
176
+ mockFetch.mockResolvedValue(
177
+ new Response(JSON.stringify(mockCommandsResponse([])), { status: 200 })
178
+ );
179
+
180
+ const result = await client.getCommands();
181
+
182
+ expect(result).toEqual([]);
183
+ expect(result).toHaveLength(0);
184
+ });
185
+
186
+ it('should handle command discovery failures', async () => {
187
+ const errorResponse = {
188
+ error: 'Access denied to command list',
189
+ code: 'PERMISSION_DENIED'
190
+ };
191
+
192
+ mockFetch.mockResolvedValue(
193
+ new Response(JSON.stringify(errorResponse), { status: 403 })
194
+ );
195
+
196
+ await expect(client.getCommands()).rejects.toThrow();
197
+ });
198
+ });
199
+
200
+ describe('error handling and resilience', () => {
201
+ it('should handle malformed server responses gracefully', async () => {
202
+ mockFetch.mockResolvedValue(
203
+ new Response('invalid json {', { status: 200 })
204
+ );
205
+
206
+ await expect(client.ping()).rejects.toThrow(SandboxError);
207
+ });
208
+
209
+ it('should handle network timeouts and connectivity issues', async () => {
210
+ const networkError = new Error('Network timeout');
211
+ mockFetch.mockRejectedValue(networkError);
212
+
213
+ await expect(client.ping()).rejects.toThrow(networkError.message);
214
+ });
215
+
216
+ it('should handle partial service failures', async () => {
217
+ // First call (ping) succeeds
218
+ mockFetch.mockResolvedValueOnce(
219
+ new Response(JSON.stringify(mockPingResponse()), { status: 200 })
220
+ );
221
+
222
+ // Second call (getCommands) fails
223
+ const errorResponse = {
224
+ error: 'Command enumeration service unavailable',
225
+ code: 'SERVICE_UNAVAILABLE'
226
+ };
227
+
228
+ mockFetch.mockResolvedValueOnce(
229
+ new Response(JSON.stringify(errorResponse), { status: 503 })
230
+ );
231
+
232
+ const pingResult = await client.ping();
233
+ expect(pingResult).toBe('pong');
234
+
235
+ await expect(client.getCommands()).rejects.toThrow();
236
+ });
237
+
238
+ it('should handle concurrent operations with mixed success', async () => {
239
+ let callCount = 0;
240
+ mockFetch.mockImplementation(() => {
241
+ callCount++;
242
+ if (callCount % 2 === 0) {
243
+ return Promise.reject(new Error('Intermittent failure'));
244
+ } else {
245
+ return Promise.resolve(
246
+ new Response(JSON.stringify(mockPingResponse()))
247
+ );
248
+ }
249
+ });
250
+
251
+ const results = await Promise.allSettled([
252
+ client.ping(), // Should succeed (call 1)
253
+ client.ping(), // Should fail (call 2)
254
+ client.ping(), // Should succeed (call 3)
255
+ client.ping() // Should fail (call 4)
256
+ ]);
257
+
258
+ expect(results[0].status).toBe('fulfilled');
259
+ expect(results[1].status).toBe('rejected');
260
+ expect(results[2].status).toBe('fulfilled');
261
+ expect(results[3].status).toBe('rejected');
262
+ });
263
+ });
264
+
265
+ describe('version checking', () => {
266
+ it('should get container version successfully', async () => {
267
+ mockFetch.mockResolvedValue(
268
+ new Response(JSON.stringify(mockVersionResponse('0.4.5')), {
269
+ status: 200
270
+ })
271
+ );
272
+
273
+ const result = await client.getVersion();
274
+
275
+ expect(result).toBe('0.4.5');
276
+ });
277
+
278
+ it('should handle different version formats', async () => {
279
+ const versions = ['1.0.0', '2.5.3-beta', '0.0.1', '10.20.30'];
280
+
281
+ for (const version of versions) {
282
+ mockFetch.mockResolvedValueOnce(
283
+ new Response(JSON.stringify(mockVersionResponse(version)), {
284
+ status: 200
285
+ })
286
+ );
287
+
288
+ const result = await client.getVersion();
289
+ expect(result).toBe(version);
290
+ }
291
+ });
292
+
293
+ it('should return "unknown" when version endpoint does not exist (backward compatibility)', async () => {
294
+ // Simulate 404 or other error for old containers
295
+ mockFetch.mockResolvedValue(
296
+ new Response(JSON.stringify({ error: 'Not Found' }), { status: 404 })
297
+ );
298
+
299
+ const result = await client.getVersion();
300
+
301
+ expect(result).toBe('unknown');
302
+ });
303
+
304
+ it('should return "unknown" on network failure (backward compatibility)', async () => {
305
+ mockFetch.mockRejectedValue(new Error('Network connection failed'));
306
+
307
+ const result = await client.getVersion();
308
+
309
+ expect(result).toBe('unknown');
310
+ });
311
+
312
+ it('should handle version response with unknown value', async () => {
313
+ mockFetch.mockResolvedValue(
314
+ new Response(JSON.stringify(mockVersionResponse('unknown')), {
315
+ status: 200
316
+ })
317
+ );
318
+
319
+ const result = await client.getVersion();
320
+
321
+ expect(result).toBe('unknown');
322
+ });
323
+ });
324
+
325
+ describe('constructor options', () => {
326
+ it('should initialize with minimal options', () => {
327
+ const minimalClient = new UtilityClient();
328
+ expect(minimalClient).toBeInstanceOf(UtilityClient);
329
+ });
330
+
331
+ it('should initialize with full options', () => {
332
+ const fullOptionsClient = new UtilityClient({
333
+ baseUrl: 'http://custom.com',
334
+ port: 8080
335
+ });
336
+ expect(fullOptionsClient).toBeInstanceOf(UtilityClient);
337
+ });
338
+ });
339
+ });
@@ -0,0 +1,16 @@
1
+ import { describe, expect, test } from 'vitest';
2
+ import packageJson from '../package.json';
3
+ import { SDK_VERSION } from '../src/version';
4
+
5
+ describe('Version Sync', () => {
6
+ test('SDK_VERSION matches package.json version', () => {
7
+ // Verify versions match
8
+ expect(SDK_VERSION).toBe(packageJson.version);
9
+ });
10
+
11
+ test('SDK_VERSION is a valid semver version', () => {
12
+ // Check if version matches semver pattern (major.minor.patch)
13
+ const semverPattern = /^\d+\.\d+\.\d+(-[\w.]+)?$/;
14
+ expect(SDK_VERSION).toMatch(semverPattern);
15
+ });
16
+ });
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "sandbox-test",
3
+ "main": "src/index.ts",
4
+ "compatibility_date": "2025-05-06",
5
+ "compatibility_flags": ["nodejs_compat"],
6
+
7
+ "observability": {
8
+ "enabled": true
9
+ },
10
+
11
+ "containers": [
12
+ {
13
+ "class_name": "Sandbox",
14
+ "image": "../Dockerfile",
15
+ "name": "sandbox",
16
+ "max_instances": 1
17
+ }
18
+ ],
19
+
20
+ "durable_objects": {
21
+ "bindings": [
22
+ {
23
+ "class_name": "Sandbox",
24
+ "name": "Sandbox"
25
+ }
26
+ ]
27
+ },
28
+
29
+ "migrations": [
30
+ {
31
+ "new_sqlite_classes": ["Sandbox"],
32
+ "tag": "v1"
33
+ }
34
+ ]
35
+ }
package/tsconfig.json CHANGED
@@ -1,3 +1,11 @@
1
1
  {
2
- "extends": "../../tsconfig.base.json"
2
+ "extends": "@repo/typescript-config/base.json",
3
+ "compilerOptions": {
4
+ "baseUrl": ".",
5
+ "types": ["node", "@cloudflare/workers-types"],
6
+ "lib": ["ES2022"],
7
+ "resolveJsonModule": true
8
+ },
9
+ "include": ["src/**/*.ts"],
10
+ "exclude": ["tests/**", "node_modules", "dist"]
3
11
  }
@@ -0,0 +1,12 @@
1
+ import { defineConfig } from 'tsdown';
2
+
3
+ export default defineConfig({
4
+ entry: 'src/index.ts',
5
+ outDir: 'dist',
6
+ dts: {
7
+ sourcemap: true,
8
+ resolve: ['@repo/shared']
9
+ },
10
+ sourcemap: true,
11
+ format: 'esm'
12
+ });