@cloudflare/sandbox 0.13.0-next.738.2 → 0.13.0-next.748.1

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,7 +1,7 @@
1
1
  import "../errors-CXR0xBpw.js";
2
2
  import "../errors-QYlSkVGz.js";
3
3
  import "../dist-Duor5GbS.js";
4
- import { g as validateTunnelName, h as validatePort, m as SandboxSecurityError, n as getSandbox$1, x as streamFile } from "../sandbox-CdJaXKpV.js";
4
+ import { g as validateTunnelName, h as validatePort, m as SandboxSecurityError, n as getSandbox$1, x as streamFile } from "../sandbox-CXc1T45U.js";
5
5
  import "../extensions-CFB2xHqY.js";
6
6
  import { DurableObject, env } from "cloudflare:workers";
7
7
  import { Hono } from "hono";
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import "./errors-CXR0xBpw.js";
2
2
  import { $ as TerminalControlError, G as BackupRestoreError, H as BackupCreateError, J as InvalidTerminalCursorError, K as ContainerUnavailableError, Q as StaleTerminalHandleError, U as BackupExpiredError, W as BackupNotFoundError, X as OperationInterruptedError, Y as InvalidTerminalCwdError, Z as RPCTransportError, _ as StaleProcessHandleError, c as InvalidProcessEnvironmentError, d as ProcessExitedBeforeLogError, et as TerminalNotFoundError, f as ProcessExitedBeforeReadyError, g as ProcessWaitTimeoutError, h as ProcessSpawnFailedError, l as ProcessAbortedError, m as ProcessReadyTimeoutError, n as RuntimeIdentityInactiveError, o as InvalidProcessCursorError, p as ProcessNotFoundError, q as InvalidBackupConfigError, r as RuntimeControlProtocolError, s as InvalidProcessCwdError, u as ProcessError } from "./errors-QYlSkVGz.js";
3
3
  import { a as TraceContext, r as createLogger } from "./dist-Duor5GbS.js";
4
- import { _ as proxyTerminal, a as responseToAsyncIterable, b as collectFile, c as BucketUnmountError, d as S3FSMountError, f as parsePreviewRoute, i as parseSSEStream, l as InvalidMountConfigError, n as getSandbox, o as ContainerProxy, p as withPreviewProxyMetadata, r as asyncIterableToSSEStream, s as BucketMountError, t as Sandbox, u as MissingCredentialsError, v as isDurableObjectCodeUpdateReset, x as streamFile, y as isPlatformTransientError } from "./sandbox-CdJaXKpV.js";
4
+ import { _ as proxyTerminal, a as responseToAsyncIterable, b as collectFile, c as BucketUnmountError, d as S3FSMountError, f as parsePreviewRoute, i as parseSSEStream, l as InvalidMountConfigError, n as getSandbox, o as ContainerProxy, p as withPreviewProxyMetadata, r as asyncIterableToSSEStream, s as BucketMountError, t as Sandbox, u as MissingCredentialsError, v as isDurableObjectCodeUpdateReset, x as streamFile, y as isPlatformTransientError } from "./sandbox-CXc1T45U.js";
5
5
  import "./extensions-CFB2xHqY.js";
6
6
 
7
7
  //#region src/request-handler.ts
@@ -719,6 +719,10 @@ function trimTrailingSlashes(s) {
719
719
  while (end > 0 && s[end - 1] === "/") end--;
720
720
  return s.slice(0, end);
721
721
  }
722
+ function normalizeMountPrefix(prefix) {
723
+ if (!prefix) return void 0;
724
+ return trimTrailingSlashes(normalizeObjectKey(prefix)) || void 0;
725
+ }
722
726
  function parsePath(pathname) {
723
727
  const stripped = pathname.startsWith("/") ? pathname.slice(1) : pathname;
724
728
  if (!stripped) return null;
@@ -916,15 +920,17 @@ async function handleGetObject(r2, key, request) {
916
920
  headers
917
921
  });
918
922
  }
919
- async function handlePutObject(r2, bucketName, key, request, env$1, permitted, mountPrefix) {
923
+ async function handlePutObject(r2, bucketName, key, request, env$1, buckets) {
920
924
  const copySourceHeader = request.headers.get("x-amz-copy-source");
921
925
  if (copySourceHeader) {
922
926
  const copySource = parseCopySource(copySourceHeader);
923
927
  if (!copySource || !copySource.key) return new Response("Bad Request: invalid x-amz-copy-source", { status: 400 });
924
- if (!permitted.has(copySource.bucket)) return new Response(`Access to R2 bucket "${copySource.bucket}" is not permitted. Call mountBucket() with this bucket before accessing it.`, { status: 403 });
928
+ if (!Object.hasOwn(buckets, copySource.bucket)) return new Response(`Access to R2 bucket "${copySource.bucket}" is not permitted. Call mountBucket() with this bucket before accessing it.`, { status: 403 });
929
+ const sourceParams = buckets[copySource.bucket];
925
930
  const sourceBucket = copySource.bucket === bucketName ? r2 : resolveR2Bucket(env$1, copySource.bucket);
926
931
  if (!sourceBucket) return new Response(`R2 binding "${copySource.bucket}" not found in Worker env. Ensure the binding name matches the bucket name passed to mountBucket().`, { status: 500 });
927
- const sourceKey = mountPrefix && copySource.bucket === bucketName ? `${mountPrefix}/${copySource.key}` : copySource.key;
932
+ const sourcePrefix = normalizeMountPrefix(sourceParams.prefix);
933
+ const sourceKey = sourcePrefix ? `${sourcePrefix}/${copySource.key}` : copySource.key;
928
934
  const sourceObject = await sourceBucket.get(sourceKey);
929
935
  if (!sourceObject) return new Response(null, { status: 404 });
930
936
  const httpMetadata = request.headers.get("x-amz-metadata-directive")?.toUpperCase() === "REPLACE" ? extractHttpMetadata(request) : sourceObject.httpMetadata;
@@ -998,8 +1004,7 @@ const r2EgressHandler = async (request, env$1, ctx) => {
998
1004
  const { bucket: bucketName, key } = parsed;
999
1005
  if (!ctx.params?.buckets || !(bucketName in ctx.params.buckets)) return new Response(`Access to R2 bucket "${bucketName}" is not permitted. Call mountBucket() with this bucket before accessing it.`, { status: 403 });
1000
1006
  const bucketParams = ctx.params.buckets[bucketName];
1001
- const rawPrefix = bucketParams.prefix;
1002
- const mountPrefix = rawPrefix ? trimTrailingSlashes(normalizeObjectKey(rawPrefix)) : void 0;
1007
+ const mountPrefix = normalizeMountPrefix(bucketParams.prefix);
1003
1008
  const readOnly = bucketParams.readOnly ?? false;
1004
1009
  const r2 = resolveR2Bucket(env$1, bucketName);
1005
1010
  if (!r2) return new Response(`R2 binding "${bucketName}" not found in Worker env. Ensure the binding name matches the bucket name passed to mountBucket().`, { status: 500 });
@@ -1011,7 +1016,6 @@ const r2EgressHandler = async (request, env$1, ctx) => {
1011
1016
  return new Response("Method Not Allowed", { status: 405 });
1012
1017
  }
1013
1018
  const fullKey = mountPrefix ? `${mountPrefix}/${key}` : key;
1014
- const permitted = new Set(Object.keys(ctx.params.buckets));
1015
1019
  if (readOnly && (method === "PUT" || method === "DELETE" || method === "POST" && (url.searchParams.has("uploads") || url.searchParams.has("uploadId")))) return new Response("Forbidden: bucket mount is read-only", { status: 403 });
1016
1020
  if (method === "POST" && url.searchParams.has("uploads")) return handleCreateMultipartUpload(r2, bucketName, fullKey, request);
1017
1021
  if (method === "POST" && url.searchParams.has("uploadId")) return handleCompleteMultipartUpload(r2, bucketName, fullKey, url, request);
@@ -1020,7 +1024,7 @@ const r2EgressHandler = async (request, env$1, ctx) => {
1020
1024
  switch (method) {
1021
1025
  case "HEAD": return handleHeadObject(r2, fullKey);
1022
1026
  case "GET": return handleGetObject(r2, fullKey, request);
1023
- case "PUT": return handlePutObject(r2, bucketName, fullKey, request, env$1, permitted, mountPrefix);
1027
+ case "PUT": return handlePutObject(r2, bucketName, fullKey, request, env$1, ctx.params.buckets);
1024
1028
  case "DELETE": return handleDeleteObject(r2, fullKey);
1025
1029
  default: return new Response("Method Not Allowed", { status: 405 });
1026
1030
  }
@@ -10036,4 +10040,4 @@ var Sandbox = class extends Container {
10036
10040
 
10037
10041
  //#endregion
10038
10042
  export { proxyTerminal as _, responseToAsyncIterable as a, collectFile as b, BucketUnmountError as c, S3FSMountError as d, parsePreviewRoute as f, validateTunnelName as g, validatePort as h, parseSSEStream as i, InvalidMountConfigError as l, SandboxSecurityError as m, getSandbox as n, ContainerProxy$1 as o, withPreviewProxyMetadata as p, asyncIterableToSSEStream as r, BucketMountError as s, Sandbox as t, MissingCredentialsError as u, isDurableObjectCodeUpdateReset as v, streamFile as x, isPlatformTransientError as y };
10039
- //# sourceMappingURL=sandbox-CdJaXKpV.js.map
10043
+ //# sourceMappingURL=sandbox-CXc1T45U.js.map