@cloudflare/sandbox 0.4.8 → 0.4.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.
@@ -1,5 +1,5 @@
1
1
  import * as _repo_shared from '@repo/shared';
2
- import { Logger, MkdirResult, WriteFileResult, ReadFileResult, DeleteFileResult, RenameFileResult, MoveFileResult, ListFilesOptions, ListFilesResult, GitCheckoutResult, CreateContextOptions, CodeContext, OutputMessage, Result, ExecutionError, PortExposeResult, PortCloseResult, PortListResult, ProcessStartResult, ProcessListResult, ProcessInfoResult, ProcessKillResult, ProcessCleanupResult, ProcessLogsResult, ISandbox, ExecOptions, ExecResult, ProcessOptions, Process, StreamOptions, SessionOptions, ExecutionSession, RunCodeOptions, ExecutionResult, SandboxOptions } from '@repo/shared';
2
+ import { Logger, MkdirResult, WriteFileResult, ReadFileResult, DeleteFileResult, RenameFileResult, MoveFileResult, ListFilesOptions, ListFilesResult, FileExistsResult, GitCheckoutResult, CreateContextOptions, CodeContext, OutputMessage, Result, ExecutionError, PortExposeResult, PortCloseResult, PortListResult, ProcessStartResult, ProcessListResult, ProcessInfoResult, ProcessKillResult, ProcessCleanupResult, ProcessLogsResult, ISandbox, ExecOptions, ExecResult, ProcessOptions, Process, StreamOptions, SessionOptions, ExecutionSession, RunCodeOptions, ExecutionResult, SandboxOptions } from '@repo/shared';
3
3
  import { DurableObject } from 'cloudflare:workers';
4
4
  import { Container } from '@cloudflare/containers';
5
5
 
@@ -239,6 +239,12 @@ declare class FileClient extends BaseHttpClient {
239
239
  * @param options - Optional settings (recursive, includeHidden)
240
240
  */
241
241
  listFiles(path: string, sessionId: string, options?: ListFilesOptions): Promise<ListFilesResult>;
242
+ /**
243
+ * Check if a file or directory exists
244
+ * @param path - Path to check
245
+ * @param sessionId - The session ID for this operation
246
+ */
247
+ exists(path: string, sessionId: string): Promise<FileExistsResult>;
242
248
  }
243
249
 
244
250
  /**
@@ -546,6 +552,7 @@ declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox
546
552
  recursive?: boolean;
547
553
  includeHidden?: boolean;
548
554
  }): Promise<_repo_shared.ListFilesResult>;
555
+ exists(path: string, sessionId?: string): Promise<_repo_shared.FileExistsResult>;
549
556
  exposePort(port: number, options: {
550
557
  name?: string;
551
558
  hostname: string;
package/dist/sandbox.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import '@repo/shared';
2
2
  import 'cloudflare:workers';
3
3
  import '@cloudflare/containers';
4
- export { b as Sandbox, g as getSandbox } from './sandbox-DMlNr93l.js';
4
+ export { b as Sandbox, g as getSandbox } from './sandbox-DWQVgVTY.js';
package/dist/sandbox.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  Sandbox,
3
3
  getSandbox
4
- } from "./chunk-MA44U7QN.js";
4
+ } from "./chunk-HBTENZ2Q.js";
5
5
  import "./chunk-JXZMAU2C.js";
6
6
  import "./chunk-Z532A7QC.js";
7
7
  import "./chunk-EKSWCBCA.js";
8
- import "./chunk-3RA7RDAX.js";
8
+ import "./chunk-QHRFHK6X.js";
9
9
  export {
10
10
  Sandbox,
11
11
  getSandbox
package/dist/version.d.ts CHANGED
@@ -3,6 +3,6 @@
3
3
  * This file is auto-updated by .github/changeset-version.ts during releases
4
4
  * DO NOT EDIT MANUALLY - Changes will be overwritten on the next version bump
5
5
  */
6
- declare const SDK_VERSION = "0.4.8";
6
+ declare const SDK_VERSION = "0.4.9";
7
7
 
8
8
  export { SDK_VERSION };
package/dist/version.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  SDK_VERSION
3
- } from "./chunk-3RA7RDAX.js";
3
+ } from "./chunk-QHRFHK6X.js";
4
4
  export {
5
5
  SDK_VERSION
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/sandbox",
3
- "version": "0.4.8",
3
+ "version": "0.4.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cloudflare/sandbox-sdk"
@@ -1,5 +1,6 @@
1
1
  import type {
2
2
  DeleteFileResult,
3
+ FileExistsResult,
3
4
  ListFilesOptions,
4
5
  ListFilesResult,
5
6
  MkdirResult,
@@ -266,4 +267,29 @@ export class FileClient extends BaseHttpClient {
266
267
  throw error;
267
268
  }
268
269
  }
270
+
271
+ /**
272
+ * Check if a file or directory exists
273
+ * @param path - Path to check
274
+ * @param sessionId - The session ID for this operation
275
+ */
276
+ async exists(
277
+ path: string,
278
+ sessionId: string
279
+ ): Promise<FileExistsResult> {
280
+ try {
281
+ const data = {
282
+ path,
283
+ sessionId,
284
+ };
285
+
286
+ const response = await this.post<FileExistsResult>('/api/exists', data);
287
+
288
+ this.logSuccess('Path existence checked', `${path} (exists: ${response.exists})`);
289
+ return response;
290
+ } catch (error) {
291
+ this.logError('exists', error);
292
+ throw error;
293
+ }
294
+ }
269
295
  }
package/src/sandbox.ts CHANGED
@@ -697,6 +697,11 @@ export class Sandbox<Env = unknown> extends Container<Env> implements ISandbox {
697
697
  return this.client.files.listFiles(path, session, options);
698
698
  }
699
699
 
700
+ async exists(path: string, sessionId?: string) {
701
+ const session = sessionId ?? await this.ensureDefaultSession();
702
+ return this.client.files.exists(path, session);
703
+ }
704
+
700
705
  async exposePort(port: number, options: { name?: string; hostname: string }) {
701
706
  // Check if hostname is workers.dev domain (doesn't support wildcard subdomains)
702
707
  if (options.hostname.endsWith('.workers.dev')) {
@@ -934,6 +939,7 @@ export class Sandbox<Env = unknown> extends Container<Env> implements ISandbox {
934
939
  renameFile: (oldPath, newPath) => this.renameFile(oldPath, newPath, sessionId),
935
940
  moveFile: (sourcePath, destPath) => this.moveFile(sourcePath, destPath, sessionId),
936
941
  listFiles: (path, options) => this.client.files.listFiles(path, sessionId, options),
942
+ exists: (path) => this.exists(path, sessionId),
937
943
 
938
944
  // Git operations
939
945
  gitCheckout: (repoUrl, options) => this.gitCheckout(repoUrl, { ...options, sessionId }),
package/src/version.ts CHANGED
@@ -3,4 +3,4 @@
3
3
  * This file is auto-updated by .github/changeset-version.ts during releases
4
4
  * DO NOT EDIT MANUALLY - Changes will be overwritten on the next version bump
5
5
  */
6
- export const SDK_VERSION = '0.4.8';
6
+ export const SDK_VERSION = '0.4.9';
@@ -1,5 +1,6 @@
1
1
  import type {
2
2
  DeleteFileResult,
3
+ FileExistsResult,
3
4
  ListFilesResult,
4
5
  MkdirResult,
5
6
  MoveFileResult,
@@ -584,6 +585,81 @@ database:
584
585
  });
585
586
  });
586
587
 
588
+ describe('exists', () => {
589
+ it('should return true when file exists', async () => {
590
+ const mockResponse: FileExistsResult = {
591
+ success: true,
592
+ path: '/workspace/test.txt',
593
+ exists: true,
594
+ timestamp: '2023-01-01T00:00:00Z',
595
+ };
596
+
597
+ mockFetch.mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 }));
598
+
599
+ const result = await client.exists('/workspace/test.txt', 'session-exists');
600
+
601
+ expect(result.success).toBe(true);
602
+ expect(result.exists).toBe(true);
603
+ expect(result.path).toBe('/workspace/test.txt');
604
+ });
605
+
606
+ it('should return false when file does not exist', async () => {
607
+ const mockResponse: FileExistsResult = {
608
+ success: true,
609
+ path: '/workspace/nonexistent.txt',
610
+ exists: false,
611
+ timestamp: '2023-01-01T00:00:00Z',
612
+ };
613
+
614
+ mockFetch.mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 }));
615
+
616
+ const result = await client.exists('/workspace/nonexistent.txt', 'session-exists');
617
+
618
+ expect(result.success).toBe(true);
619
+ expect(result.exists).toBe(false);
620
+ });
621
+
622
+ it('should return true when directory exists', async () => {
623
+ const mockResponse: FileExistsResult = {
624
+ success: true,
625
+ path: '/workspace/some-dir',
626
+ exists: true,
627
+ timestamp: '2023-01-01T00:00:00Z',
628
+ };
629
+
630
+ mockFetch.mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 }));
631
+
632
+ const result = await client.exists('/workspace/some-dir', 'session-exists');
633
+
634
+ expect(result.success).toBe(true);
635
+ expect(result.exists).toBe(true);
636
+ });
637
+
638
+ it('should send correct request payload', async () => {
639
+ const mockResponse: FileExistsResult = {
640
+ success: true,
641
+ path: '/test/path',
642
+ exists: true,
643
+ timestamp: '2023-01-01T00:00:00Z',
644
+ };
645
+
646
+ mockFetch.mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 }));
647
+
648
+ await client.exists('/test/path', 'session-test');
649
+
650
+ expect(mockFetch).toHaveBeenCalledWith(
651
+ expect.stringContaining('/api/exists'),
652
+ expect.objectContaining({
653
+ method: 'POST',
654
+ body: JSON.stringify({
655
+ path: '/test/path',
656
+ sessionId: 'session-test',
657
+ })
658
+ })
659
+ );
660
+ });
661
+ });
662
+
587
663
  describe('error handling', () => {
588
664
  it('should handle network failures gracefully', async () => {
589
665
  mockFetch.mockRejectedValue(new Error('Network connection failed'));
@@ -1,7 +0,0 @@
1
- // src/version.ts
2
- var SDK_VERSION = "0.4.8";
3
-
4
- export {
5
- SDK_VERSION
6
- };
7
- //# sourceMappingURL=chunk-3RA7RDAX.js.map