{"version":3,"file":"bundle-path.mjs","names":[],"sources":["../src/bundle-path.ts"],"sourcesContent":["import path from \"node:path\";\n\n/**\n * Maps a bundle URL onto the staged namespace layout. Bundle URLs carry their\n * namespace in the path (`…/bundles/<account>/<gateway>/<workspace>/…`); the\n * staged layout mirrors it under `<bundleDir>/<account>/<gateway>/…`. The\n * namespace is taken from the URL itself — unlike the runtime-identity\n * resolution, this answers \"which staged directory do these bytes live in?\"\n * rather than \"is this my namespace?\" — and the result is contained within\n * the account/gateway directory. Returns null for foreign shapes.\n */\nexport function bundleUrlToStagedPath(url: string, bundleDir: string): string | null {\n  let parsed: URL;\n  try {\n    parsed = new URL(url);\n  } catch {\n    return null;\n  }\n  if (parsed.protocol !== \"https:\" && parsed.protocol !== \"http:\") return null;\n\n  const segments = parsed.pathname.split(\"/\").filter(Boolean);\n  if (segments[0] !== \"bundles\" || segments.length < 3) return null;\n\n  let decoded: string[];\n  try {\n    decoded = segments.slice(1).map((segment) => decodeURIComponent(segment));\n  } catch {\n    return null;\n  }\n  const [account, gateway, ...rest] = decoded;\n  if (!account || !gateway || rest.length === 0) return null;\n\n  const nsDir = path.resolve(bundleDir, account, gateway);\n  const filePath = path.resolve(nsDir, ...rest);\n  if (filePath === nsDir || !filePath.startsWith(nsDir + path.sep)) return null;\n  return filePath;\n}\n\n/** Resolve a relative config-supplied path inside `dir`, or null on escape. */\nexport function resolveContained(dir: string, relative: string): string | null {\n  const resolved = path.resolve(dir, ...relative.split(\"/\").filter(Boolean));\n  if (resolved === dir || !resolved.startsWith(dir + path.sep)) return null;\n  return resolved;\n}\n"],"mappings":";;;;;;;;;;;;AAWA,SAAgB,sBAAsB,KAAa,WAAkC;CACnF,IAAI;CACJ,IAAI;EACF,SAAS,IAAI,IAAI,GAAG;CACtB,QAAQ;EACN,OAAO;CACT;CACA,IAAI,OAAO,aAAa,YAAY,OAAO,aAAa,SAAS,OAAO;CAExE,MAAM,WAAW,OAAO,SAAS,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO;CAC1D,IAAI,SAAS,OAAO,aAAa,SAAS,SAAS,GAAG,OAAO;CAE7D,IAAI;CACJ,IAAI;EACF,UAAU,SAAS,MAAM,CAAC,CAAC,CAAC,KAAK,YAAY,mBAAmB,OAAO,CAAC;CAC1E,QAAQ;EACN,OAAO;CACT;CACA,MAAM,CAAC,SAAS,SAAS,GAAG,QAAQ;CACpC,IAAI,CAAC,WAAW,CAAC,WAAW,KAAK,WAAW,GAAG,OAAO;CAEtD,MAAM,QAAQ,KAAK,QAAQ,WAAW,SAAS,OAAO;CACtD,MAAM,WAAW,KAAK,QAAQ,OAAO,GAAG,IAAI;CAC5C,IAAI,aAAa,SAAS,CAAC,SAAS,WAAW,QAAQ,KAAK,GAAG,GAAG,OAAO;CACzE,OAAO;AACT;;AAGA,SAAgB,iBAAiB,KAAa,UAAiC;CAC7E,MAAM,WAAW,KAAK,QAAQ,KAAK,GAAG,SAAS,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO,CAAC;CACzE,IAAI,aAAa,OAAO,CAAC,SAAS,WAAW,MAAM,KAAK,GAAG,GAAG,OAAO;CACrE,OAAO;AACT"}