@patodo/localapp 0.2.6 → 0.2.8

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 (64) hide show
  1. package/.localapp-artifact.json +80 -80
  2. package/bin/localapp.mjs +539 -489
  3. package/package.json +1 -1
  4. package/runtime/native/adapter-manifest.json +1 -1
  5. package/runtime/native/win32-x64/localapp-native.exe +0 -0
  6. package/runtime/server/.localapp-server-runtime.json +57 -57
  7. package/runtime/server/bin/worker.cjs +325 -316
  8. package/runtime/server/web/404.html +1 -1
  9. package/runtime/server/web/inbox.html +1 -1
  10. package/runtime/server/web/inbox.txt +1 -1
  11. package/runtime/server/web/index.html +1 -1
  12. package/runtime/server/web/index.txt +1 -1
  13. package/runtime/server/web/my/analytics.html +1 -1
  14. package/runtime/server/web/my/analytics.txt +1 -1
  15. package/runtime/server/web/my/apps/placeholder/settings.html +1 -1
  16. package/runtime/server/web/my/apps/placeholder/settings.txt +1 -1
  17. package/runtime/server/web/my/apps.html +1 -1
  18. package/runtime/server/web/my/apps.txt +1 -1
  19. package/runtime/server/web/my/dashboard.html +1 -1
  20. package/runtime/server/web/my/dashboard.txt +1 -1
  21. package/runtime/server/web/my/device-actions.html +1 -1
  22. package/runtime/server/web/my/device-actions.txt +1 -1
  23. package/runtime/server/web/my/device-notifications.html +1 -1
  24. package/runtime/server/web/my/device-notifications.txt +1 -1
  25. package/runtime/server/web/my/favorites.html +1 -1
  26. package/runtime/server/web/my/favorites.txt +1 -1
  27. package/runtime/server/web/my/groups.html +1 -1
  28. package/runtime/server/web/my/groups.txt +1 -1
  29. package/runtime/server/web/my/info.html +1 -1
  30. package/runtime/server/web/my/info.txt +1 -1
  31. package/runtime/server/web/my/keys.html +1 -1
  32. package/runtime/server/web/my/keys.txt +1 -1
  33. package/runtime/server/web/my/orgs.html +1 -1
  34. package/runtime/server/web/my/orgs.txt +1 -1
  35. package/runtime/server/web/my/pages.html +1 -1
  36. package/runtime/server/web/my/pages.txt +1 -1
  37. package/runtime/server/web/my/peers.html +1 -1
  38. package/runtime/server/web/my/peers.txt +1 -1
  39. package/runtime/server/web/my/recent.html +1 -1
  40. package/runtime/server/web/my/recent.txt +1 -1
  41. package/runtime/server/web/my/settings.html +1 -1
  42. package/runtime/server/web/my/settings.txt +1 -1
  43. package/runtime/server/web/my/studio.html +1 -1
  44. package/runtime/server/web/my/studio.txt +1 -1
  45. package/runtime/server/web/my/subscriptions.html +1 -1
  46. package/runtime/server/web/my/subscriptions.txt +1 -1
  47. package/runtime/server/web/my/system.html +1 -1
  48. package/runtime/server/web/my/system.txt +1 -1
  49. package/runtime/server/web/my/tasks.html +1 -1
  50. package/runtime/server/web/my/tasks.txt +1 -1
  51. package/runtime/server/web/my/users.html +1 -1
  52. package/runtime/server/web/my/users.txt +1 -1
  53. package/runtime/server/web/my.html +1 -1
  54. package/runtime/server/web/my.txt +1 -1
  55. package/runtime/server/web/platform-shell/placeholder/placeholder.html +1 -1
  56. package/runtime/server/web/platform-shell/placeholder/placeholder.txt +1 -1
  57. package/runtime/server/web/platform-shell-preview.html +1 -1
  58. package/runtime/server/web/platform-shell-preview.txt +1 -1
  59. package/runtime/server/web/setup.html +1 -1
  60. package/runtime/server/web/setup.txt +1 -1
  61. package/template/runtime/version.json +1 -1
  62. package/template/tests/dev-shell-template.test.ts +4 -1
  63. /package/runtime/server/web/_next/static/{qBns-ZRUDtxsd4XX5SLLK → 53tcXasdrXUY226RhYFJX}/_buildManifest.js +0 -0
  64. /package/runtime/server/web/_next/static/{qBns-ZRUDtxsd4XX5SLLK → 53tcXasdrXUY226RhYFJX}/_ssgManifest.js +0 -0
@@ -137318,12 +137318,7 @@ async function retainExactPackage(pageDir, localVersion, inspected) {
137318
137318
  await import_node_fs9.default.promises.chmod(tempPath, 384);
137319
137319
  const copied = await inspectAppPackage(tempPath);
137320
137320
  if (copied.digest !== inspected.digest) throw new AppInstallError("APP_PACKAGE_STORAGE_CORRUPT", "Retained package digest mismatch", 500);
137321
- const handle = await import_node_fs9.default.promises.open(tempPath, "r");
137322
- try {
137323
- await handle.sync();
137324
- } finally {
137325
- await handle.close();
137326
- }
137321
+ syncFile2(tempPath);
137327
137322
  import_node_fs9.default.renameSync(tempPath, finalPath);
137328
137323
  syncDirectory4(directory);
137329
137324
  syncDirectory4(pageDir);
@@ -138164,6 +138159,7 @@ async function pagesRoutes(app) {
138164
138159
  // packages/server/src/routes/serve.ts
138165
138160
  var import_node_crypto20 = __toESM(require("node:crypto"));
138166
138161
  var import_node_fs15 = __toESM(require("node:fs"));
138162
+ var import_node_fs16 = require("node:fs");
138167
138163
  var import_node_path22 = __toESM(require("node:path"));
138168
138164
 
138169
138165
  // packages/server/src/lib/request-logger.ts
@@ -140776,8 +140772,7 @@ async function serveRoutes(app, options2 = {}) {
140776
140772
  const versionDir = import_node_path22.default.join(getPageDir(dataDir2(), userId, name), "versions", `v${version}`);
140777
140773
  const indexPath = import_node_path22.default.join(versionDir, "index.html");
140778
140774
  if (import_node_fs15.default.existsSync(indexPath)) {
140779
- reply.header("Content-Security-Policy", CSP_HEADER);
140780
- return reply.type("text/html").send(import_node_fs15.default.readFileSync(indexPath));
140775
+ return sendAppFile(req, reply, indexPath, "index.html");
140781
140776
  }
140782
140777
  return reply.status(404).send({ success: false, error: "index.html not found" });
140783
140778
  }
@@ -140919,18 +140914,32 @@ async function serveRoutes(app, options2 = {}) {
140919
140914
  }
140920
140915
  let filePath = import_node_path22.default.join(versionDir, restPath || "index.html");
140921
140916
  if (import_node_fs15.default.existsSync(filePath) && import_node_fs15.default.statSync(filePath).isFile()) {
140922
- reply.header("Content-Security-Policy", CSP_HEADER);
140923
- return reply.type(getMimeType(filePath)).send(import_node_fs15.default.readFileSync(filePath));
140917
+ return sendAppFile(req, reply, filePath, restPath);
140924
140918
  }
140925
140919
  const indexPath = import_node_path22.default.join(versionDir, "index.html");
140926
140920
  if (import_node_fs15.default.existsSync(indexPath) && !restPath.includes(".")) {
140927
- reply.header("Content-Security-Policy", CSP_HEADER);
140928
- return reply.type("text/html").send(import_node_fs15.default.readFileSync(indexPath));
140921
+ return sendAppFile(req, reply, indexPath, restPath);
140929
140922
  }
140930
140923
  return reply.status(404).send({ success: false, error: "File not found" });
140931
140924
  }
140932
140925
  );
140933
140926
  }
140927
+ function isImmutableAppAsset(restPath) {
140928
+ return /(?:^|\/)assets\/[^/]+-[A-Za-z0-9_-]{8,}\.[a-z0-9]+$/.test(restPath);
140929
+ }
140930
+ function sendAppFile(req, reply, filePath, restPath) {
140931
+ const stat2 = import_node_fs15.default.statSync(filePath);
140932
+ const etag = `W/"${stat2.size.toString(16)}-${Math.trunc(stat2.mtimeMs).toString(16)}"`;
140933
+ reply.header("ETag", etag);
140934
+ reply.header("Last-Modified", stat2.mtime.toUTCString());
140935
+ reply.header("Cache-Control", isImmutableAppAsset(restPath) ? "public, max-age=31536000, immutable" : "no-cache");
140936
+ reply.header("Content-Security-Policy", CSP_HEADER);
140937
+ const ifNoneMatch = req.headers["if-none-match"];
140938
+ if (typeof ifNoneMatch === "string" && ifNoneMatch.split(",").some((value) => value.trim() === etag)) {
140939
+ return reply.status(304).send();
140940
+ }
140941
+ return reply.type(getMimeType(filePath)).send((0, import_node_fs16.createReadStream)(filePath));
140942
+ }
140934
140943
  function injectNativeShellMetadata(html, userId, name) {
140935
140944
  const resourceBase = `/serve/${userId}/${name}/`;
140936
140945
  const marker = [
@@ -141862,13 +141871,13 @@ function sendManifestError(reply, error5) {
141862
141871
  }
141863
141872
 
141864
141873
  // packages/server/src/routes/deps.ts
141865
- var import_node_fs16 = __toESM(require("node:fs"));
141874
+ var import_node_fs17 = __toESM(require("node:fs"));
141866
141875
  var import_node_path23 = __toESM(require("node:path"));
141867
141876
  var DEPS_DIR = import_node_path23.default.resolve(process.cwd(), "static", "deps");
141868
141877
  function readNodeJson() {
141869
141878
  const p2 = import_node_path23.default.join(DEPS_DIR, "node.json");
141870
- if (!import_node_fs16.default.existsSync(p2)) return null;
141871
- return JSON.parse(import_node_fs16.default.readFileSync(p2, "utf-8"));
141879
+ if (!import_node_fs17.default.existsSync(p2)) return null;
141880
+ return JSON.parse(import_node_fs17.default.readFileSync(p2, "utf-8"));
141872
141881
  }
141873
141882
  async function depsRoutes(app) {
141874
141883
  app.get("/api/deps/node", async (_req, reply) => {
@@ -141897,10 +141906,10 @@ async function depsRoutes(app) {
141897
141906
  const filename = platforms[platformKey];
141898
141907
  const version = info.version;
141899
141908
  const binPath = import_node_path23.default.join(DEPS_DIR, "node", version, filename);
141900
- if (!import_node_fs16.default.existsSync(binPath)) {
141909
+ if (!import_node_fs17.default.existsSync(binPath)) {
141901
141910
  return reply.status(404).send({ success: false, error: "Installer file not found on server" });
141902
141911
  }
141903
- return reply.header("Content-Disposition", `attachment; filename="${filename}"`).type("application/octet-stream").send(import_node_fs16.default.createReadStream(binPath));
141912
+ return reply.header("Content-Disposition", `attachment; filename="${filename}"`).type("application/octet-stream").send(import_node_fs17.default.createReadStream(binPath));
141904
141913
  }
141905
141914
  );
141906
141915
  }
@@ -143748,7 +143757,7 @@ async function authRoutes(app) {
143748
143757
  }
143749
143758
 
143750
143759
  // packages/server/src/routes/profile.ts
143751
- var import_node_fs17 = __toESM(require("node:fs"));
143760
+ var import_node_fs18 = __toESM(require("node:fs"));
143752
143761
  var import_node_path24 = __toESM(require("node:path"));
143753
143762
  init_meta_sqlite();
143754
143763
  var MAX_AVATAR_SIZE = 2 * 1024 * 1024;
@@ -143839,13 +143848,13 @@ async function profileRoutes(app) {
143839
143848
  }
143840
143849
  const ext2 = extFromMime(data2.mimetype);
143841
143850
  const avatarsDir = import_node_path24.default.join(dataDir2(), "avatars");
143842
- import_node_fs17.default.mkdirSync(avatarsDir, { recursive: true });
143843
- const existingFiles = import_node_fs17.default.readdirSync(avatarsDir).filter((f5) => f5.startsWith(req.visitorId + "."));
143851
+ import_node_fs18.default.mkdirSync(avatarsDir, { recursive: true });
143852
+ const existingFiles = import_node_fs18.default.readdirSync(avatarsDir).filter((f5) => f5.startsWith(req.visitorId + "."));
143844
143853
  for (const f5 of existingFiles) {
143845
- import_node_fs17.default.unlinkSync(import_node_path24.default.join(avatarsDir, f5));
143854
+ import_node_fs18.default.unlinkSync(import_node_path24.default.join(avatarsDir, f5));
143846
143855
  }
143847
143856
  const filename = `${req.visitorId}.${ext2}`;
143848
- import_node_fs17.default.writeFileSync(import_node_path24.default.join(avatarsDir, filename), buffer);
143857
+ import_node_fs18.default.writeFileSync(import_node_path24.default.join(avatarsDir, filename), buffer);
143849
143858
  const avatarUrl = `/api/avatar/${req.visitorId}`;
143850
143859
  updateUserAvatar(req.visitorId, avatarUrl);
143851
143860
  return { success: true, data: { avatarUrl } };
@@ -143859,7 +143868,7 @@ async function profileRoutes(app) {
143859
143868
  return reply.status(404).send({ success: false, error: "No avatar" });
143860
143869
  }
143861
143870
  const avatarsDir = import_node_path24.default.join(dataDir2(), "avatars");
143862
- const files = import_node_fs17.default.readdirSync(avatarsDir).filter((f5) => f5.startsWith(req.visitorId + "."));
143871
+ const files = import_node_fs18.default.readdirSync(avatarsDir).filter((f5) => f5.startsWith(req.visitorId + "."));
143863
143872
  if (files.length === 0) {
143864
143873
  return reply.status(404).send({ success: false, error: "No avatar" });
143865
143874
  }
@@ -143867,15 +143876,15 @@ async function profileRoutes(app) {
143867
143876
  const ext2 = import_node_path24.default.extname(filePath).toLowerCase();
143868
143877
  const mimeMap = { ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".png": "image/png", ".webp": "image/webp" };
143869
143878
  reply.header("Content-Type", mimeMap[ext2] || "application/octet-stream");
143870
- return reply.send(import_node_fs17.default.readFileSync(filePath));
143879
+ return reply.send(import_node_fs18.default.readFileSync(filePath));
143871
143880
  });
143872
143881
  app.get("/api/avatar/:userId", async (req, reply) => {
143873
143882
  const { userId } = req.params;
143874
143883
  const avatarsDir = import_node_path24.default.join(dataDir2(), "avatars");
143875
- if (!import_node_fs17.default.existsSync(avatarsDir)) {
143884
+ if (!import_node_fs18.default.existsSync(avatarsDir)) {
143876
143885
  return reply.status(404).send({ success: false, error: "No avatar" });
143877
143886
  }
143878
- const files = import_node_fs17.default.readdirSync(avatarsDir).filter((f5) => f5.startsWith(userId + "."));
143887
+ const files = import_node_fs18.default.readdirSync(avatarsDir).filter((f5) => f5.startsWith(userId + "."));
143879
143888
  if (files.length === 0) {
143880
143889
  return reply.status(404).send({ success: false, error: "No avatar" });
143881
143890
  }
@@ -143884,14 +143893,14 @@ async function profileRoutes(app) {
143884
143893
  const mimeMap = { ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".png": "image/png", ".webp": "image/webp" };
143885
143894
  reply.header("Content-Type", mimeMap[ext2] || "application/octet-stream");
143886
143895
  reply.header("Cache-Control", "public, max-age=3600");
143887
- return reply.send(import_node_fs17.default.readFileSync(filePath));
143896
+ return reply.send(import_node_fs18.default.readFileSync(filePath));
143888
143897
  });
143889
143898
  app.get("/api/me/pages", async (req, reply) => {
143890
143899
  if (!requireSession(req.visitorId, reply)) return;
143891
143900
  const { limit } = req.query;
143892
143901
  const userDir = import_node_path24.default.join(dataDir2(), req.visitorId);
143893
- if (!import_node_fs17.default.existsSync(userDir)) return { success: true, data: [] };
143894
- const entries = import_node_fs17.default.readdirSync(userDir, { withFileTypes: true });
143902
+ if (!import_node_fs18.default.existsSync(userDir)) return { success: true, data: [] };
143903
+ const entries = import_node_fs18.default.readdirSync(userDir, { withFileTypes: true });
143895
143904
  const pages = [];
143896
143905
  for (const entry of entries) {
143897
143906
  if (!entry.isDirectory()) continue;
@@ -143966,21 +143975,21 @@ async function profileRoutes(app) {
143966
143975
  }
143967
143976
 
143968
143977
  // packages/server/src/routes/app-settings.ts
143969
- var import_node_fs21 = __toESM(require("node:fs"));
143978
+ var import_node_fs22 = __toESM(require("node:fs"));
143970
143979
  var import_node_path28 = __toESM(require("node:path"));
143971
143980
  var import_node_crypto24 = __toESM(require("node:crypto"));
143972
143981
  var import_promises6 = require("node:stream/promises");
143973
143982
 
143974
143983
  // packages/server/src/lib/app-data-service.ts
143975
143984
  var import_node_crypto23 = __toESM(require("node:crypto"));
143976
- var import_node_fs20 = __toESM(require("node:fs"));
143985
+ var import_node_fs21 = __toESM(require("node:fs"));
143977
143986
  var import_node_path27 = __toESM(require("node:path"));
143978
143987
  var import_sql3 = __toESM(require("sql.js"));
143979
143988
  var import_server_core9 = __toESM(require_dist5());
143980
143989
 
143981
143990
  // packages/server/src/lib/app-data-archive.ts
143982
143991
  var import_node_crypto22 = __toESM(require("node:crypto"));
143983
- var import_node_fs19 = __toESM(require("node:fs"));
143992
+ var import_node_fs20 = __toESM(require("node:fs"));
143984
143993
  var import_node_path26 = __toESM(require("node:path"));
143985
143994
  var import_node_stream12 = require("node:stream");
143986
143995
  var import_promises5 = require("node:stream/promises");
@@ -143988,7 +143997,7 @@ var import_yauzl2 = __toESM(require_yauzl());
143988
143997
 
143989
143998
  // packages/server/src/lib/app-data-schema.ts
143990
143999
  var import_node_crypto21 = __toESM(require("node:crypto"));
143991
- var import_node_fs18 = __toESM(require("node:fs"));
144000
+ var import_node_fs19 = __toESM(require("node:fs"));
143992
144001
  var import_node_path25 = __toESM(require("node:path"));
143993
144002
  var import_sql2 = __toESM(require("sql.js"));
143994
144003
  var import_server_core8 = __toESM(require_dist5());
@@ -144039,7 +144048,7 @@ function schemaDescription(db2) {
144039
144048
  async function openDatabase(dbPath2) {
144040
144049
  const SQL = await (0, import_sql2.default)();
144041
144050
  try {
144042
- return new SQL.Database(import_node_fs18.default.readFileSync(dbPath2));
144051
+ return new SQL.Database(import_node_fs19.default.readFileSync(dbPath2));
144043
144052
  } catch (caught) {
144044
144053
  throw new AppDataError("APP_DATABASE_INVALID", `Cannot open SQLite database: ${caught instanceof Error ? caught.message : String(caught)}`);
144045
144054
  }
@@ -144093,7 +144102,7 @@ async function validateCandidateSchema(input) {
144093
144102
  reference.close();
144094
144103
  }
144095
144104
  } finally {
144096
- import_node_fs18.default.rmSync(referencePath, { force: true });
144105
+ import_node_fs19.default.rmSync(referencePath, { force: true });
144097
144106
  }
144098
144107
  }
144099
144108
 
@@ -144101,7 +144110,7 @@ async function validateCandidateSchema(input) {
144101
144110
  var MAX_MANIFEST_BYTES = 16 * 1024 * 1024;
144102
144111
  async function hashFile(filePath) {
144103
144112
  const hash2 = import_node_crypto22.default.createHash("sha256");
144104
- for await (const chunk of import_node_fs19.default.createReadStream(filePath)) hash2.update(chunk);
144113
+ for await (const chunk of import_node_fs20.default.createReadStream(filePath)) hash2.update(chunk);
144105
144114
  return hash2.digest("hex");
144106
144115
  }
144107
144116
  function appObjectKeyAllowed(key, owner, appName) {
@@ -144145,14 +144154,14 @@ async function createDataArchive(input) {
144145
144154
  if (input.objects.length > input.limits.maxFileEntries) {
144146
144155
  throw new AppDataError("APP_ARCHIVE_LIMIT_EXCEEDED", "Application file count exceeds archive limit");
144147
144156
  }
144148
- const databaseSize = import_node_fs19.default.statSync(input.databasePath).size;
144157
+ const databaseSize = import_node_fs20.default.statSync(input.databasePath).size;
144149
144158
  let expandedBytes = databaseSize;
144150
144159
  if (expandedBytes > input.limits.maxExpandedBytes) {
144151
144160
  throw new AppDataError("APP_ARCHIVE_LIMIT_EXCEEDED", "Application data exceeds expanded archive limit");
144152
144161
  }
144153
- import_node_fs19.default.mkdirSync(import_node_path26.default.dirname(input.outputPath), { recursive: true });
144162
+ import_node_fs20.default.mkdirSync(import_node_path26.default.dirname(input.outputPath), { recursive: true });
144154
144163
  const { ZipArchive: ZipArchive2 } = await Promise.resolve().then(() => (init_archiver(), archiver_exports));
144155
- const output = import_node_fs19.default.createWriteStream(input.outputPath, { mode: 384 });
144164
+ const output = import_node_fs20.default.createWriteStream(input.outputPath, { mode: 384 });
144156
144165
  const archive = new ZipArchive2({ forceZip64: true, zlib: { level: 6 } });
144157
144166
  const closed = new Promise((resolve3, reject) => {
144158
144167
  output.on("close", resolve3);
@@ -144167,7 +144176,7 @@ async function createDataArchive(input) {
144167
144176
  sha256: await hashFile(input.databasePath),
144168
144177
  schemaFingerprint: await computeSchemaFingerprint(input.databasePath)
144169
144178
  };
144170
- await appendArchiveEntry(archive, import_node_fs19.default.createReadStream(input.databasePath), databaseEntry.path);
144179
+ await appendArchiveEntry(archive, import_node_fs20.default.createReadStream(input.databasePath), databaseEntry.path);
144171
144180
  const files = [];
144172
144181
  const sourceApplication = input.sourceApplication ?? input.application;
144173
144182
  const rebasedKeys = /* @__PURE__ */ new Set();
@@ -144226,7 +144235,7 @@ async function createDataArchive(input) {
144226
144235
  await appendArchiveEntry(archive, manifestBytes, "localapp-data.json");
144227
144236
  await archive.finalize();
144228
144237
  await closed;
144229
- const archiveSize = import_node_fs19.default.statSync(input.outputPath).size;
144238
+ const archiveSize = import_node_fs20.default.statSync(input.outputPath).size;
144230
144239
  if (archiveSize > input.limits.maxCompressedBytes) {
144231
144240
  throw new AppDataError("APP_ARCHIVE_LIMIT_EXCEEDED", "Compressed archive exceeds size limit");
144232
144241
  }
@@ -144235,7 +144244,7 @@ async function createDataArchive(input) {
144235
144244
  archive.abort();
144236
144245
  output.destroy();
144237
144246
  await closed.catch(() => void 0);
144238
- import_node_fs19.default.rmSync(input.outputPath, { force: true });
144247
+ import_node_fs20.default.rmSync(input.outputPath, { force: true });
144239
144248
  throw caught;
144240
144249
  }
144241
144250
  }
@@ -144298,7 +144307,7 @@ async function extractEntries(zipFile, stagingDir, limits) {
144298
144307
  throw new AppDataError("APP_ARCHIVE_LIMIT_EXCEEDED", "Expanded archive exceeds size limit");
144299
144308
  }
144300
144309
  const destination = stagingPath(stagingDir, entry.fileName);
144301
- import_node_fs19.default.mkdirSync(import_node_path26.default.dirname(destination), { recursive: true });
144310
+ import_node_fs20.default.mkdirSync(import_node_path26.default.dirname(destination), { recursive: true });
144302
144311
  const hash2 = import_node_crypto22.default.createHash("sha256");
144303
144312
  let actualSize = 0;
144304
144313
  const hashing = new import_node_stream12.Transform({
@@ -144309,7 +144318,7 @@ async function extractEntries(zipFile, stagingDir, limits) {
144309
144318
  }
144310
144319
  });
144311
144320
  const source = await openEntry2(zipFile, entry);
144312
- await (0, import_promises5.pipeline)(source, hashing, import_node_fs19.default.createWriteStream(destination, { mode: 384 }));
144321
+ await (0, import_promises5.pipeline)(source, hashing, import_node_fs20.default.createWriteStream(destination, { mode: 384 }));
144313
144322
  extracted.set(entry.fileName, { path: destination, size: actualSize, sha256: hash2.digest("hex") });
144314
144323
  zipFile.readEntry();
144315
144324
  })().catch(fail2);
@@ -144321,7 +144330,7 @@ async function extractEntries(zipFile, stagingDir, limits) {
144321
144330
  function parseManifest(filePath) {
144322
144331
  let value;
144323
144332
  try {
144324
- value = JSON.parse(import_node_fs19.default.readFileSync(filePath, "utf8"));
144333
+ value = JSON.parse(import_node_fs20.default.readFileSync(filePath, "utf8"));
144325
144334
  } catch {
144326
144335
  throw new AppDataError("APP_ARCHIVE_MANIFEST_INVALID", "Archive manifest is not valid JSON");
144327
144336
  }
@@ -144340,11 +144349,11 @@ function assertEntryMatches(entry, expected, label) {
144340
144349
  return entry;
144341
144350
  }
144342
144351
  async function extractAndValidateDataArchive(input) {
144343
- if (import_node_fs19.default.statSync(input.archivePath).size > input.limits.maxCompressedBytes) {
144352
+ if (import_node_fs20.default.statSync(input.archivePath).size > input.limits.maxCompressedBytes) {
144344
144353
  throw new AppDataError("APP_ARCHIVE_LIMIT_EXCEEDED", "Compressed archive exceeds size limit");
144345
144354
  }
144346
- import_node_fs19.default.rmSync(input.stagingDir, { recursive: true, force: true });
144347
- import_node_fs19.default.mkdirSync(input.stagingDir, { recursive: true });
144355
+ import_node_fs20.default.rmSync(input.stagingDir, { recursive: true, force: true });
144356
+ import_node_fs20.default.mkdirSync(input.stagingDir, { recursive: true });
144348
144357
  try {
144349
144358
  const extracted = await extractEntries(await openZip2(input.archivePath), input.stagingDir, input.limits);
144350
144359
  const manifestEntry = extracted.get("localapp-data.json");
@@ -144395,7 +144404,7 @@ async function extractAndValidateDataArchive(input) {
144395
144404
  }
144396
144405
  return { manifest, databasePath: database.path, files };
144397
144406
  } catch (caught) {
144398
- import_node_fs19.default.rmSync(input.stagingDir, { recursive: true, force: true });
144407
+ import_node_fs20.default.rmSync(input.stagingDir, { recursive: true, force: true });
144399
144408
  if (caught instanceof AppDataError) throw caught;
144400
144409
  throw new AppDataError("APP_ARCHIVE_INVALID", caught instanceof Error ? caught.message : String(caught));
144401
144410
  }
@@ -144434,13 +144443,13 @@ function isAppBackupId(id2) {
144434
144443
  return /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(id2);
144435
144444
  }
144436
144445
  function atomicWrite(filePath, bytes) {
144437
- import_node_fs20.default.mkdirSync(import_node_path27.default.dirname(filePath), { recursive: true });
144446
+ import_node_fs21.default.mkdirSync(import_node_path27.default.dirname(filePath), { recursive: true });
144438
144447
  const tempPath = `${filePath}.${process.pid}.${import_node_crypto23.default.randomUUID()}.tmp`;
144439
144448
  try {
144440
- import_node_fs20.default.writeFileSync(tempPath, bytes, { mode: 384 });
144441
- import_node_fs20.default.renameSync(tempPath, filePath);
144449
+ import_node_fs21.default.writeFileSync(tempPath, bytes, { mode: 384 });
144450
+ import_node_fs21.default.renameSync(tempPath, filePath);
144442
144451
  } finally {
144443
- import_node_fs20.default.rmSync(tempPath, { force: true });
144452
+ import_node_fs21.default.rmSync(tempPath, { force: true });
144444
144453
  }
144445
144454
  }
144446
144455
  function normalizeBackupName(name, fallback2) {
@@ -144451,7 +144460,7 @@ function normalizeBackupName(name, fallback2) {
144451
144460
  function inferAppDataIdentity(pageDir) {
144452
144461
  let version = 0;
144453
144462
  try {
144454
- const meta = JSON.parse(import_node_fs20.default.readFileSync(import_node_path27.default.join(pageDir, "meta.json"), "utf8"));
144463
+ const meta = JSON.parse(import_node_fs21.default.readFileSync(import_node_path27.default.join(pageDir, "meta.json"), "utf8"));
144455
144464
  if (Number.isInteger(meta.currentVersion) && Number(meta.currentVersion) >= 0) version = Number(meta.currentVersion);
144456
144465
  } catch {
144457
144466
  }
@@ -144460,14 +144469,14 @@ function inferAppDataIdentity(pageDir) {
144460
144469
  async function createArchiveAt(input) {
144461
144470
  (0, app_db_exports.closeConnectionsForPage)(input.pageDir);
144462
144471
  const sourceDatabasePath = import_node_path27.default.join(input.pageDir, "app.db");
144463
- if (!import_node_fs20.default.existsSync(sourceDatabasePath)) throw new AppDataError("APP_DATABASE_NOT_FOUND", "Application database does not exist");
144472
+ if (!import_node_fs21.default.existsSync(sourceDatabasePath)) throw new AppDataError("APP_DATABASE_NOT_FOUND", "Application database does not exist");
144464
144473
  const sourceApplication = input.sourceApplication ?? input.application;
144465
144474
  const objects = await input.storage.listAppObjects(sourceApplication.owner, sourceApplication.name);
144466
144475
  const crossOwner = sourceApplication.owner !== input.application.owner || sourceApplication.name !== input.application.name;
144467
144476
  const databasePath = crossOwner ? import_node_path27.default.join(operationDir(input.pageDir), `export-database-${import_node_crypto23.default.randomUUID()}.db`) : sourceDatabasePath;
144468
144477
  try {
144469
144478
  if (crossOwner) {
144470
- import_node_fs20.default.copyFileSync(sourceDatabasePath, databasePath);
144479
+ import_node_fs21.default.copyFileSync(sourceDatabasePath, databasePath);
144471
144480
  await rebaseDatabaseReferences(databasePath, {
144472
144481
  sourceApplication,
144473
144482
  targetApplication: input.application,
@@ -144488,7 +144497,7 @@ async function createArchiveAt(input) {
144488
144497
  limits: input.limits
144489
144498
  });
144490
144499
  } finally {
144491
- if (crossOwner) import_node_fs20.default.rmSync(databasePath, { force: true });
144500
+ if (crossOwner) import_node_fs21.default.rmSync(databasePath, { force: true });
144492
144501
  }
144493
144502
  }
144494
144503
  function rebaseObjectKey(key, source, target) {
@@ -144500,21 +144509,21 @@ function rebaseObjectKey(key, source, target) {
144500
144509
  }
144501
144510
  function declaredIdentityColumns(pageDir, version) {
144502
144511
  const resourcesDir = import_node_path27.default.join(pageDir, "versions", `v${version}`, "backend", "resources");
144503
- if (!import_node_fs20.default.existsSync(resourcesDir)) return [];
144512
+ if (!import_node_fs21.default.existsSync(resourcesDir)) return [];
144504
144513
  const result = /* @__PURE__ */ new Map();
144505
- for (const entry of import_node_fs20.default.readdirSync(resourcesDir, { withFileTypes: true })) {
144514
+ for (const entry of import_node_fs21.default.readdirSync(resourcesDir, { withFileTypes: true })) {
144506
144515
  if (!entry.isDirectory()) continue;
144507
144516
  const resourceDir = import_node_path27.default.join(resourcesDir, entry.name);
144508
144517
  const schemaPath = import_node_path27.default.join(resourceDir, "schema.json");
144509
144518
  try {
144510
- const schema = JSON.parse(import_node_fs20.default.readFileSync(schemaPath, "utf8"));
144519
+ const schema = JSON.parse(import_node_fs21.default.readFileSync(schemaPath, "utf8"));
144511
144520
  if (typeof schema.name !== "string") throw new Error("resource name is missing");
144512
144521
  const ownerField = typeof schema.business?.ownerField === "string" ? schema.business.ownerField : void 0;
144513
144522
  if (ownerField) result.set(`${schema.name}\0${ownerField}`, { table: schema.name, column: ownerField });
144514
144523
  for (const contractName of ["queries.json", "mutations.json"]) {
144515
144524
  const contractPath = import_node_path27.default.join(resourceDir, contractName);
144516
- if (!import_node_fs20.default.existsSync(contractPath)) continue;
144517
- const contract = JSON.parse(import_node_fs20.default.readFileSync(contractPath, "utf8"));
144525
+ if (!import_node_fs21.default.existsSync(contractPath)) continue;
144526
+ const contract = JSON.parse(import_node_fs21.default.readFileSync(contractPath, "utf8"));
144518
144527
  const definitions = contract[contractName === "queries.json" ? "queries" : "mutations"];
144519
144528
  if (!definitions || typeof definitions !== "object" || Array.isArray(definitions)) continue;
144520
144529
  for (const definition2 of Object.values(definitions)) {
@@ -144561,7 +144570,7 @@ async function createManagedBackupUnlocked(input) {
144561
144570
  atomicWrite(backupMetaPath(input.pageDir, id2), Buffer.from(`${JSON.stringify(backup, null, 2)}
144562
144571
  `));
144563
144572
  } catch (caught) {
144564
- import_node_fs20.default.rmSync(outputPath, { force: true });
144573
+ import_node_fs21.default.rmSync(outputPath, { force: true });
144565
144574
  throw caught;
144566
144575
  }
144567
144576
  return backup;
@@ -144569,18 +144578,18 @@ async function createManagedBackupUnlocked(input) {
144569
144578
  function readBackupMetadata(pageDir, id2) {
144570
144579
  if (!isAppBackupId(id2)) return null;
144571
144580
  const metaPath = backupMetaPath(pageDir, id2);
144572
- if (!import_node_fs20.default.existsSync(metaPath)) return null;
144581
+ if (!import_node_fs21.default.existsSync(metaPath)) return null;
144573
144582
  try {
144574
- const stored = JSON.parse(import_node_fs20.default.readFileSync(metaPath, "utf8"));
144583
+ const stored = JSON.parse(import_node_fs21.default.readFileSync(metaPath, "utf8"));
144575
144584
  if (stored.id !== id2 || typeof stored.name !== "string" || typeof stored.createdAt !== "string" || stored.source !== "manual" && stored.source !== "automatic") return null;
144576
- const format2 = import_node_fs20.default.existsSync(backupDataPath(pageDir, id2, "zip")) ? "zip" : "legacy-db";
144585
+ const format2 = import_node_fs21.default.existsSync(backupDataPath(pageDir, id2, "zip")) ? "zip" : "legacy-db";
144577
144586
  const dataPath = backupDataPath(pageDir, id2, format2);
144578
- if (!import_node_fs20.default.existsSync(dataPath)) return null;
144587
+ if (!import_node_fs21.default.existsSync(dataPath)) return null;
144579
144588
  return {
144580
144589
  id: id2,
144581
144590
  name: stored.name,
144582
144591
  createdAt: stored.createdAt,
144583
- size: import_node_fs20.default.statSync(dataPath).size,
144592
+ size: import_node_fs21.default.statSync(dataPath).size,
144584
144593
  source: stored.source,
144585
144594
  format: format2,
144586
144595
  fileCount: format2 === "zip" && Number.isInteger(stored.fileCount) ? Number(stored.fileCount) : 0,
@@ -144593,29 +144602,29 @@ function readBackupMetadata(pageDir, id2) {
144593
144602
  }
144594
144603
  function listAppBackups(pageDir) {
144595
144604
  const directory = backupDir(pageDir);
144596
- if (!import_node_fs20.default.existsSync(directory)) return [];
144597
- return import_node_fs20.default.readdirSync(directory).filter((filename) => filename.endsWith(".json")).map((filename) => readBackupMetadata(pageDir, filename.slice(0, -5))).filter((backup) => backup !== null).sort((left, right) => right.createdAt.localeCompare(left.createdAt));
144605
+ if (!import_node_fs21.default.existsSync(directory)) return [];
144606
+ return import_node_fs21.default.readdirSync(directory).filter((filename) => filename.endsWith(".json")).map((filename) => readBackupMetadata(pageDir, filename.slice(0, -5))).filter((backup) => backup !== null).sort((left, right) => right.createdAt.localeCompare(left.createdAt));
144598
144607
  }
144599
144608
  function swapDatabaseFile(pageDir, candidatePath) {
144600
144609
  (0, app_db_exports.closeConnectionsForPage)(pageDir);
144601
- import_node_fs20.default.mkdirSync(pageDir, { recursive: true });
144610
+ import_node_fs21.default.mkdirSync(pageDir, { recursive: true });
144602
144611
  const targetPath = import_node_path27.default.join(pageDir, "app.db");
144603
144612
  const token = import_node_crypto23.default.randomUUID();
144604
144613
  const stagedPath = import_node_path27.default.join(pageDir, `.app.db.${token}.candidate`);
144605
144614
  const previousPath = import_node_path27.default.join(pageDir, `.app.db.${token}.previous`);
144606
144615
  try {
144607
- import_node_fs20.default.copyFileSync(candidatePath, stagedPath);
144608
- if (import_node_fs20.default.existsSync(targetPath)) import_node_fs20.default.renameSync(targetPath, previousPath);
144609
- import_node_fs20.default.renameSync(stagedPath, targetPath);
144610
- import_node_fs20.default.rmSync(previousPath, { force: true });
144616
+ import_node_fs21.default.copyFileSync(candidatePath, stagedPath);
144617
+ if (import_node_fs21.default.existsSync(targetPath)) import_node_fs21.default.renameSync(targetPath, previousPath);
144618
+ import_node_fs21.default.renameSync(stagedPath, targetPath);
144619
+ import_node_fs21.default.rmSync(previousPath, { force: true });
144611
144620
  } catch (caught) {
144612
- import_node_fs20.default.rmSync(targetPath, { force: true });
144613
- if (import_node_fs20.default.existsSync(previousPath)) import_node_fs20.default.renameSync(previousPath, targetPath);
144621
+ import_node_fs21.default.rmSync(targetPath, { force: true });
144622
+ if (import_node_fs21.default.existsSync(previousPath)) import_node_fs21.default.renameSync(previousPath, targetPath);
144614
144623
  throw caught;
144615
144624
  } finally {
144616
- import_node_fs20.default.rmSync(stagedPath, { force: true });
144617
- if (import_node_fs20.default.existsSync(previousPath) && !import_node_fs20.default.existsSync(targetPath)) import_node_fs20.default.renameSync(previousPath, targetPath);
144618
- else import_node_fs20.default.rmSync(previousPath, { force: true });
144625
+ import_node_fs21.default.rmSync(stagedPath, { force: true });
144626
+ if (import_node_fs21.default.existsSync(previousPath) && !import_node_fs21.default.existsSync(targetPath)) import_node_fs21.default.renameSync(previousPath, targetPath);
144627
+ else import_node_fs21.default.rmSync(previousPath, { force: true });
144619
144628
  }
144620
144629
  }
144621
144630
  async function applyPreparedData(input) {
@@ -144668,7 +144677,7 @@ async function rebaseDatabaseReferences(databasePath, input) {
144668
144677
  }
144669
144678
  }
144670
144679
  const SQL = await (0, import_sql3.default)();
144671
- const db2 = new SQL.Database(import_node_fs20.default.readFileSync(databasePath));
144680
+ const db2 = new SQL.Database(import_node_fs21.default.readFileSync(databasePath));
144672
144681
  try {
144673
144682
  const result = db2.exec("SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%'");
144674
144683
  const tables = (result[0]?.values ?? []).map((row) => String(row[0]));
@@ -144700,7 +144709,7 @@ async function rebaseDatabaseReferences(databasePath, input) {
144700
144709
  db2.run("ROLLBACK");
144701
144710
  throw error5;
144702
144711
  }
144703
- import_node_fs20.default.writeFileSync(databasePath, Buffer.from(db2.export()), { mode: 384 });
144712
+ import_node_fs21.default.writeFileSync(databasePath, Buffer.from(db2.export()), { mode: 384 });
144704
144713
  } finally {
144705
144714
  db2.close();
144706
144715
  }
@@ -144745,7 +144754,7 @@ async function createAppDataExport(input) {
144745
144754
  const limits = input.limits ?? DEFAULT_ARCHIVE_LIMITS;
144746
144755
  const storage2 = input.storage ?? defaultStorage;
144747
144756
  return withAppDataMaintenance(input.pageDir, async () => {
144748
- import_node_fs20.default.mkdirSync(operationDir(input.pageDir), { recursive: true });
144757
+ import_node_fs21.default.mkdirSync(operationDir(input.pageDir), { recursive: true });
144749
144758
  const archivePath = import_node_path27.default.join(operationDir(input.pageDir), `export-${import_node_crypto23.default.randomUUID()}.zip`);
144750
144759
  try {
144751
144760
  await createArchiveAt({
@@ -144756,9 +144765,9 @@ async function createAppDataExport(input) {
144756
144765
  storage: storage2,
144757
144766
  outputPath: archivePath
144758
144767
  });
144759
- return { archivePath, cleanup: () => import_node_fs20.default.rmSync(archivePath, { force: true }) };
144768
+ return { archivePath, cleanup: () => import_node_fs21.default.rmSync(archivePath, { force: true }) };
144760
144769
  } catch (caught) {
144761
- import_node_fs20.default.rmSync(archivePath, { force: true });
144770
+ import_node_fs21.default.rmSync(archivePath, { force: true });
144762
144771
  throw caught;
144763
144772
  }
144764
144773
  });
@@ -144805,14 +144814,14 @@ async function importAppData(input) {
144805
144814
  throw caught;
144806
144815
  }
144807
144816
  return {
144808
- databaseSize: import_node_fs20.default.statSync(import_node_path27.default.join(input.pageDir, "app.db")).size,
144817
+ databaseSize: import_node_fs21.default.statSync(import_node_path27.default.join(input.pageDir, "app.db")).size,
144809
144818
  fileCount: prepared.manifest.files.length,
144810
144819
  fileSize: prepared.manifest.files.reduce((total, file) => total + file.size, 0),
144811
144820
  safetyBackupId: safety.id
144812
144821
  };
144813
144822
  } finally {
144814
- import_node_fs20.default.rmSync(stagingDir, { recursive: true, force: true });
144815
- import_node_fs20.default.rmSync(rollbackDir, { recursive: true, force: true });
144823
+ import_node_fs21.default.rmSync(stagingDir, { recursive: true, force: true });
144824
+ import_node_fs21.default.rmSync(rollbackDir, { recursive: true, force: true });
144816
144825
  }
144817
144826
  });
144818
144827
  }
@@ -144829,8 +144838,8 @@ function getAppBackup(pageDir, id2) {
144829
144838
  async function deleteAppBackup(pageDir, id2) {
144830
144839
  await withAppDataMaintenance(pageDir, async () => {
144831
144840
  const backup = getAppBackup(pageDir, id2);
144832
- import_node_fs20.default.rmSync(backupDataPath(pageDir, id2, backup.format), { force: true });
144833
- import_node_fs20.default.rmSync(backupMetaPath(pageDir, id2), { force: true });
144841
+ import_node_fs21.default.rmSync(backupDataPath(pageDir, id2, backup.format), { force: true });
144842
+ import_node_fs21.default.rmSync(backupMetaPath(pageDir, id2), { force: true });
144834
144843
  });
144835
144844
  }
144836
144845
  async function restoreAppBackup(pageDir, id2, options2 = {}) {
@@ -144840,7 +144849,7 @@ async function restoreAppBackup(pageDir, id2, options2 = {}) {
144840
144849
  await importAppData({ pageDir, application, archivePath: getAppBackupPath(pageDir, id2), reason: `restore:${id2}`, limits: options2.limits, storage: options2.storage });
144841
144850
  return;
144842
144851
  }
144843
- await replaceAppDatabase(pageDir, import_node_fs20.default.readFileSync(getAppBackupPath(pageDir, id2)), `restore:${id2}`, { ...options2, application });
144852
+ await replaceAppDatabase(pageDir, import_node_fs21.default.readFileSync(getAppBackupPath(pageDir, id2)), `restore:${id2}`, { ...options2, application });
144844
144853
  }
144845
144854
  async function restoreAppBackupExact(pageDir, id2, options2) {
144846
144855
  const backup = getAppBackup(pageDir, id2);
@@ -144848,14 +144857,14 @@ async function restoreAppBackupExact(pageDir, id2, options2) {
144848
144857
  const storage2 = options2.storage ?? defaultStorage;
144849
144858
  await withAppDataMaintenance(pageDir, async () => {
144850
144859
  if (backup.format === "legacy-db") {
144851
- const bytes = import_node_fs20.default.readFileSync(getAppBackupPath(pageDir, id2));
144860
+ const bytes = import_node_fs21.default.readFileSync(getAppBackupPath(pageDir, id2));
144852
144861
  await validateSqlite(bytes);
144853
144862
  const candidatePath = import_node_path27.default.join(operationDir(pageDir), `exact-restore-${import_node_crypto23.default.randomUUID()}.db`);
144854
144863
  try {
144855
- import_node_fs20.default.writeFileSync(candidatePath, bytes, { mode: 384 });
144864
+ import_node_fs21.default.writeFileSync(candidatePath, bytes, { mode: 384 });
144856
144865
  swapDatabaseFile(pageDir, candidatePath);
144857
144866
  } finally {
144858
- import_node_fs20.default.rmSync(candidatePath, { force: true });
144867
+ import_node_fs21.default.rmSync(candidatePath, { force: true });
144859
144868
  }
144860
144869
  return;
144861
144870
  }
@@ -144869,7 +144878,7 @@ async function restoreAppBackupExact(pageDir, id2, options2) {
144869
144878
  });
144870
144879
  await applyPreparedData({ pageDir, application: options2.application, ...prepared, storage: storage2 });
144871
144880
  } finally {
144872
- import_node_fs20.default.rmSync(stagingDir, { recursive: true, force: true });
144881
+ import_node_fs21.default.rmSync(stagingDir, { recursive: true, force: true });
144873
144882
  }
144874
144883
  });
144875
144884
  }
@@ -144894,12 +144903,12 @@ async function replaceAppDatabase(pageDir, candidate, reason, options2 = {}) {
144894
144903
  await withAppDataMaintenance(pageDir, async () => {
144895
144904
  await createManagedBackupUnlocked({ pageDir, application, limits, storage: storage2, source: "automatic", reason });
144896
144905
  const candidatePath = import_node_path27.default.join(operationDir(pageDir), `legacy-${import_node_crypto23.default.randomUUID()}.db`);
144897
- import_node_fs20.default.mkdirSync(import_node_path27.default.dirname(candidatePath), { recursive: true });
144906
+ import_node_fs21.default.mkdirSync(import_node_path27.default.dirname(candidatePath), { recursive: true });
144898
144907
  try {
144899
- import_node_fs20.default.writeFileSync(candidatePath, candidate, { mode: 384 });
144908
+ import_node_fs21.default.writeFileSync(candidatePath, candidate, { mode: 384 });
144900
144909
  swapDatabaseFile(pageDir, candidatePath);
144901
144910
  } finally {
144902
- import_node_fs20.default.rmSync(candidatePath, { force: true });
144911
+ import_node_fs21.default.rmSync(candidatePath, { force: true });
144903
144912
  }
144904
144913
  });
144905
144914
  }
@@ -144933,8 +144942,8 @@ async function resetApplicationData(input) {
144933
144942
  }
144934
144943
  throw caught;
144935
144944
  } finally {
144936
- import_node_fs20.default.rmSync(candidatePath, { force: true });
144937
- import_node_fs20.default.rmSync(rollbackDir, { recursive: true, force: true });
144945
+ import_node_fs21.default.rmSync(candidatePath, { force: true });
144946
+ import_node_fs21.default.rmSync(rollbackDir, { recursive: true, force: true });
144938
144947
  }
144939
144948
  });
144940
144949
  }
@@ -145086,7 +145095,7 @@ async function appSettingsRoutes(app) {
145086
145095
  const dbPath2 = import_node_path28.default.join(owned.pageDir, "app.db");
145087
145096
  const database = await (0, app_db_exports.withDbQueue)(dbPath2, async () => {
145088
145097
  (0, app_db_exports.closeConnectionsForPage)(owned.pageDir);
145089
- return import_node_fs21.default.existsSync(dbPath2) ? { exists: true, size: import_node_fs21.default.statSync(dbPath2).size } : { exists: false, size: 0 };
145098
+ return import_node_fs22.default.existsSync(dbPath2) ? { exists: true, size: import_node_fs22.default.statSync(dbPath2).size } : { exists: false, size: 0 };
145090
145099
  });
145091
145100
  const objects = await listAppObjects(owned.meta.userId, owned.meta.name);
145092
145101
  return {
@@ -145113,7 +145122,7 @@ async function appSettingsRoutes(app) {
145113
145122
  reply.header("Content-Type", "application/zip");
145114
145123
  reply.header("Content-Disposition", `attachment; filename="${attachmentName(owned.meta.name, stamp, "zip")}"`);
145115
145124
  reply.header("Cache-Control", "no-store");
145116
- return reply.send(import_node_fs21.default.createReadStream(exported.archivePath));
145125
+ return reply.send(import_node_fs22.default.createReadStream(exported.archivePath));
145117
145126
  } catch (caught) {
145118
145127
  return dataError(reply, caught);
145119
145128
  }
@@ -145143,7 +145152,7 @@ async function appSettingsRoutes(app) {
145143
145152
  reply.header("Content-Type", backup.format === "zip" ? "application/zip" : "application/vnd.sqlite3");
145144
145153
  reply.header("Content-Disposition", `attachment; filename="${attachmentName(owned.meta.name, `backup-${req.params.backupId}`, extension2)}"`);
145145
145154
  reply.header("Cache-Control", "no-store");
145146
- return reply.send(import_node_fs21.default.createReadStream(backupPath));
145155
+ return reply.send(import_node_fs22.default.createReadStream(backupPath));
145147
145156
  } catch (caught) {
145148
145157
  return dataError(reply, caught);
145149
145158
  }
@@ -145176,7 +145185,7 @@ async function appSettingsRoutes(app) {
145176
145185
  const owned = resolveOwnedApp(app, req, reply);
145177
145186
  if (!owned) return;
145178
145187
  let confirmName = "";
145179
- import_node_fs21.default.mkdirSync(import_node_path28.default.join(owned.pageDir, ".data-operations"), { recursive: true });
145188
+ import_node_fs22.default.mkdirSync(import_node_path28.default.join(owned.pageDir, ".data-operations"), { recursive: true });
145180
145189
  const archivePath = import_node_path28.default.join(owned.pageDir, ".data-operations", `upload-${import_node_crypto24.default.randomUUID()}.zip`);
145181
145190
  let archiveReceived = false;
145182
145191
  try {
@@ -145184,12 +145193,12 @@ async function appSettingsRoutes(app) {
145184
145193
  if (part.type === "field" && part.fieldname === "confirmName") confirmName = String(part.value);
145185
145194
  if (part.type === "file" && part.fieldname === "archive") {
145186
145195
  archiveReceived = true;
145187
- await (0, import_promises6.pipeline)(part.file, import_node_fs21.default.createWriteStream(archivePath, { mode: 384 }));
145196
+ await (0, import_promises6.pipeline)(part.file, import_node_fs22.default.createWriteStream(archivePath, { mode: 384 }));
145188
145197
  if (part.file.truncated) throw new AppDataError("APP_ARCHIVE_LIMIT_EXCEEDED", "Compressed archive exceeds size limit");
145189
145198
  }
145190
145199
  }
145191
145200
  } catch (caught) {
145192
- import_node_fs21.default.rmSync(archivePath, { force: true });
145201
+ import_node_fs22.default.rmSync(archivePath, { force: true });
145193
145202
  if (caught instanceof AppDataError) return dataError(reply, caught);
145194
145203
  return error3(reply, 413, "APP_ARCHIVE_LIMIT_EXCEEDED", "Compressed archive exceeds size limit");
145195
145204
  }
@@ -145207,7 +145216,7 @@ async function appSettingsRoutes(app) {
145207
145216
  } catch (caught) {
145208
145217
  return dataError(reply, caught);
145209
145218
  } finally {
145210
- import_node_fs21.default.rmSync(archivePath, { force: true });
145219
+ import_node_fs22.default.rmSync(archivePath, { force: true });
145211
145220
  }
145212
145221
  });
145213
145222
  app.post("/api/me/pages/:name/data/factory-reset", async (req, reply) => {
@@ -145215,7 +145224,7 @@ async function appSettingsRoutes(app) {
145215
145224
  if (!owned) return;
145216
145225
  if (!confirmationMatches(req.body, owned.meta.name)) return error3(reply, 400, "APP_CONFIRMATION_MISMATCH", "Application name confirmation does not match");
145217
145226
  const platformPath = import_node_path28.default.join(owned.pageDir, "manifest.platform.json");
145218
- const platformBytes = import_node_fs21.default.existsSync(platformPath) ? import_node_fs21.default.readFileSync(platformPath) : null;
145227
+ const platformBytes = import_node_fs22.default.existsSync(platformPath) ? import_node_fs22.default.readFileSync(platformPath) : null;
145219
145228
  try {
145220
145229
  const reset = await resetApplicationData({
145221
145230
  pageDir: owned.pageDir,
@@ -145397,7 +145406,7 @@ async function configRoutes(app) {
145397
145406
 
145398
145407
  // packages/server/src/routes/admin.ts
145399
145408
  var import_node_crypto26 = require("node:crypto");
145400
- var import_node_fs22 = __toESM(require("node:fs"));
145409
+ var import_node_fs23 = __toESM(require("node:fs"));
145401
145410
  var import_node_path29 = __toESM(require("node:path"));
145402
145411
  init_meta_sqlite();
145403
145412
 
@@ -145427,9 +145436,9 @@ async function adminRoutes(app) {
145427
145436
  const userDir = import_node_path29.default.join(dataDir2, u.id);
145428
145437
  let pages = 0;
145429
145438
  let storageUsed = 0;
145430
- if (import_node_fs22.default.existsSync(userDir)) {
145431
- const entries = import_node_fs22.default.readdirSync(userDir, { withFileTypes: true });
145432
- pages = entries.filter((e5) => e5.isDirectory() && import_node_fs22.default.existsSync(import_node_path29.default.join(userDir, e5.name, "meta.json"))).length;
145439
+ if (import_node_fs23.default.existsSync(userDir)) {
145440
+ const entries = import_node_fs23.default.readdirSync(userDir, { withFileTypes: true });
145441
+ pages = entries.filter((e5) => e5.isDirectory() && import_node_fs23.default.existsSync(import_node_path29.default.join(userDir, e5.name, "meta.json"))).length;
145433
145442
  storageUsed = getUserTotalSize(dataDir2, u.id);
145434
145443
  }
145435
145444
  return {
@@ -145525,8 +145534,8 @@ async function adminRoutes(app) {
145525
145534
  }
145526
145535
  const userDir = import_node_path29.default.join(dataDir2, id2);
145527
145536
  const pageList = [];
145528
- if (import_node_fs22.default.existsSync(userDir)) {
145529
- const entries = import_node_fs22.default.readdirSync(userDir, { withFileTypes: true });
145537
+ if (import_node_fs23.default.existsSync(userDir)) {
145538
+ const entries = import_node_fs23.default.readdirSync(userDir, { withFileTypes: true });
145530
145539
  for (const entry of entries) {
145531
145540
  if (!entry.isDirectory()) continue;
145532
145541
  const meta = readPageMeta(dataDir2, id2, entry.name);
@@ -145560,8 +145569,8 @@ async function adminRoutes(app) {
145560
145569
  return reply.status(404).send({ success: false, error: "User not found" });
145561
145570
  }
145562
145571
  const userDir = import_node_path29.default.join(dataDir2, id2);
145563
- if (import_node_fs22.default.existsSync(userDir)) {
145564
- const appNames = import_node_fs22.default.readdirSync(userDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
145572
+ if (import_node_fs23.default.existsSync(userDir)) {
145573
+ const appNames = import_node_fs23.default.readdirSync(userDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
145565
145574
  const deleteWithReservations = async (index3) => {
145566
145575
  if (index3 >= appNames.length) {
145567
145576
  removeDirRecursive(userDir);
@@ -145587,13 +145596,13 @@ async function adminRoutes(app) {
145587
145596
  const page = Math.max(1, parseInt(req.query.page || "1", 10));
145588
145597
  const limit = Math.min(100, Math.max(1, parseInt(req.query.limit || "20", 10)));
145589
145598
  const allPages = [];
145590
- if (!import_node_fs22.default.existsSync(dataDir2)) {
145599
+ if (!import_node_fs23.default.existsSync(dataDir2)) {
145591
145600
  return { success: true, data: [], pagination: { page, limit, total: 0 } };
145592
145601
  }
145593
- const userDirs = import_node_fs22.default.readdirSync(dataDir2, { withFileTypes: true }).filter((e5) => e5.isDirectory() && (!filterUserId || e5.name === filterUserId));
145602
+ const userDirs = import_node_fs23.default.readdirSync(dataDir2, { withFileTypes: true }).filter((e5) => e5.isDirectory() && (!filterUserId || e5.name === filterUserId));
145594
145603
  for (const userDir of userDirs) {
145595
145604
  const userPath = import_node_path29.default.join(dataDir2, userDir.name);
145596
- const pageDirs = import_node_fs22.default.readdirSync(userPath, { withFileTypes: true });
145605
+ const pageDirs = import_node_fs23.default.readdirSync(userPath, { withFileTypes: true });
145597
145606
  for (const pageDir of pageDirs) {
145598
145607
  if (!pageDir.isDirectory()) continue;
145599
145608
  const meta = readPageMeta(dataDir2, userDir.name, pageDir.name);
@@ -145624,7 +145633,7 @@ async function adminRoutes(app) {
145624
145633
  return reply.status(404).send({ success: false, error: "Page not found" });
145625
145634
  }
145626
145635
  const pageDir = getPageDir(dataDir2, userId, name);
145627
- const storageUsed = import_node_fs22.default.existsSync(pageDir) ? getDirectorySize(pageDir) : 0;
145636
+ const storageUsed = import_node_fs23.default.existsSync(pageDir) ? getDirectorySize(pageDir) : 0;
145628
145637
  return {
145629
145638
  success: true,
145630
145639
  data: {
@@ -145655,13 +145664,13 @@ async function adminRoutes(app) {
145655
145664
  let totalSchemas = 0;
145656
145665
  const recentDeploys = [];
145657
145666
  totalUsers = listUsers(1, 1).total;
145658
- if (import_node_fs22.default.existsSync(dataDir2)) {
145659
- const userDirs = import_node_fs22.default.readdirSync(dataDir2, { withFileTypes: true });
145667
+ if (import_node_fs23.default.existsSync(dataDir2)) {
145668
+ const userDirs = import_node_fs23.default.readdirSync(dataDir2, { withFileTypes: true });
145660
145669
  for (const userDir of userDirs) {
145661
145670
  if (!userDir.isDirectory()) continue;
145662
145671
  totalStorage += getUserTotalSize(dataDir2, userDir.name);
145663
145672
  const userPath = import_node_path29.default.join(dataDir2, userDir.name);
145664
- const pageDirs = import_node_fs22.default.readdirSync(userPath, { withFileTypes: true });
145673
+ const pageDirs = import_node_fs23.default.readdirSync(userPath, { withFileTypes: true });
145665
145674
  for (const pageDir of pageDirs) {
145666
145675
  if (!pageDir.isDirectory()) continue;
145667
145676
  const meta = readPageMeta(dataDir2, userDir.name, pageDir.name);
@@ -145847,7 +145856,7 @@ async function adminRoutes(app) {
145847
145856
  }
145848
145857
 
145849
145858
  // packages/server/src/routes/my-serve.ts
145850
- var import_node_fs23 = __toESM(require("node:fs"));
145859
+ var import_node_fs24 = __toESM(require("node:fs"));
145851
145860
  var import_node_path30 = __toESM(require("node:path"));
145852
145861
  init_meta_sqlite();
145853
145862
  var HTML_4042 = `<!DOCTYPE html><html><head><meta charset="utf-8"><title>Not Found</title></head><body style="display:flex;justify-content:center;align-items:center;height:100vh;margin:0;font-family:system-ui;background:#f8f9fa"><div style="text-align:center"><h1 style="font-size:2rem;color:#1a1d23">404</h1><p style="color:#6b7280">Page not found.</p><a href="/" style="color:#2563eb">Back to home</a></div></body></html>`;
@@ -145855,7 +145864,7 @@ function serveNextHtml(webOutDir, page) {
145855
145864
  const filePath = import_node_path30.default.join(webOutDir, `${page}.html`);
145856
145865
  return async (_req, reply) => {
145857
145866
  try {
145858
- const html = import_node_fs23.default.readFileSync(filePath, "utf-8");
145867
+ const html = import_node_fs24.default.readFileSync(filePath, "utf-8");
145859
145868
  reply.type("text/html").send(html);
145860
145869
  } catch {
145861
145870
  reply.status(404).type("text/html").send(HTML_4042);
@@ -145900,7 +145909,7 @@ async function myServeRoutes(app, options2 = {}) {
145900
145909
  return reply.status(404).send("");
145901
145910
  }
145902
145911
  try {
145903
- const body = import_node_fs23.default.readFileSync(target, "utf-8");
145912
+ const body = import_node_fs24.default.readFileSync(target, "utf-8");
145904
145913
  return reply.type("text/plain; charset=utf-8").send(body);
145905
145914
  } catch {
145906
145915
  return reply.status(404).send("");
@@ -145911,7 +145920,7 @@ async function myServeRoutes(app, options2 = {}) {
145911
145920
  }
145912
145921
 
145913
145922
  // packages/server/src/routes/issues.ts
145914
- var import_node_fs24 = __toESM(require("node:fs"));
145923
+ var import_node_fs25 = __toESM(require("node:fs"));
145915
145924
  var import_node_crypto27 = require("node:crypto");
145916
145925
  init_meta_sqlite();
145917
145926
 
@@ -146252,7 +146261,7 @@ async function issuesRoutes(app) {
146252
146261
  return null;
146253
146262
  }
146254
146263
  const pageDir = getPageDir(app.config.dataDir, userId, name);
146255
- if (!import_node_fs24.default.existsSync(pageDir)) return null;
146264
+ if (!import_node_fs25.default.existsSync(pageDir)) return null;
146256
146265
  return { dbPath: (0, app_db_exports.getDbPath)(pageDir), pageDir, userId, name };
146257
146266
  }
146258
146267
  function ensureAppAccess(reply, resolved, visitorId, anonymousDeniedStatus = 401) {
@@ -148196,7 +148205,7 @@ function requirePlatformAccess(req, reply) {
148196
148205
  }
148197
148206
 
148198
148207
  // packages/server/src/routes/db.ts
148199
- var import_node_fs25 = __toESM(require("node:fs"));
148208
+ var import_node_fs26 = __toESM(require("node:fs"));
148200
148209
  var import_node_path32 = __toESM(require("node:path"));
148201
148210
  async function dbRoutes(app) {
148202
148211
  app.get("/api/db/snapshot", async (req, reply) => {
@@ -148210,7 +148219,7 @@ async function dbRoutes(app) {
148210
148219
  return reply.status(404).send({ success: false, error: "Page not found" });
148211
148220
  }
148212
148221
  const dbPath2 = import_node_path32.default.join(pageDir, "app.db");
148213
- const bytes = import_node_fs25.default.existsSync(dbPath2) ? import_node_fs25.default.readFileSync(dbPath2) : Buffer.alloc(0);
148222
+ const bytes = import_node_fs26.default.existsSync(dbPath2) ? import_node_fs26.default.readFileSync(dbPath2) : Buffer.alloc(0);
148214
148223
  return reply.type("application/octet-stream").send(bytes);
148215
148224
  });
148216
148225
  app.post("/api/db/restore", async (req, reply) => {
@@ -148227,14 +148236,14 @@ async function dbRoutes(app) {
148227
148236
  return reply.status(404).send({ success: false, error: "Page not found" });
148228
148237
  }
148229
148238
  const backupPath = import_node_path32.default.join(pageDir, `app.db.backup.${backup}`);
148230
- if (!import_node_fs25.default.existsSync(backupPath)) {
148239
+ if (!import_node_fs26.default.existsSync(backupPath)) {
148231
148240
  return reply.status(404).send({ success: false, error: `Backup ${backup} not found` });
148232
148241
  }
148233
148242
  const dbPath2 = import_node_path32.default.join(pageDir, "app.db");
148234
148243
  await (0, app_db_exports.withDbQueue)(dbPath2, async () => {
148235
148244
  assertAppDataWritable(pageDir);
148236
148245
  (0, app_db_exports.closeConnectionsForPage)(pageDir);
148237
- import_node_fs25.default.copyFileSync(backupPath, dbPath2);
148246
+ import_node_fs26.default.copyFileSync(backupPath, dbPath2);
148238
148247
  });
148239
148248
  return { success: true, data: { name, backup } };
148240
148249
  });
@@ -148352,7 +148361,7 @@ function unwrapData(value) {
148352
148361
  }
148353
148362
 
148354
148363
  // packages/server/src/lib/device-action-executor.ts
148355
- var import_node_fs26 = __toESM(require("node:fs"));
148364
+ var import_node_fs27 = __toESM(require("node:fs"));
148356
148365
  var import_promises7 = require("node:fs/promises");
148357
148366
  var import_node_path33 = __toESM(require("node:path"));
148358
148367
  var import_node_child_process = require("node:child_process");
@@ -148409,13 +148418,13 @@ function findRunnerPath() {
148409
148418
  import_node_path33.default.resolve(__dirname, "../../runner/localapp-runner.mjs"),
148410
148419
  import_node_path33.default.resolve(__dirname, "../runner/localapp-runner.mjs")
148411
148420
  ].filter((candidate) => Boolean(candidate));
148412
- const found = candidates.find((candidate) => import_node_fs26.default.existsSync(candidate));
148421
+ const found = candidates.find((candidate) => import_node_fs27.default.existsSync(candidate));
148413
148422
  if (!found) throw new DeviceActionExecutionError("DEVICE_ACTION_RUNNER_UNAVAILABLE");
148414
148423
  return found;
148415
148424
  }
148416
148425
  function permissionArguments(permissions, runnerPath, nodeExecutable, dataDirectory, actionDirectory, workingDirectory, environmentPath) {
148417
- const realNodeExecutable = import_node_fs26.default.realpathSync(nodeExecutable);
148418
- const realRunnerPath = import_node_fs26.default.realpathSync(runnerPath);
148426
+ const realNodeExecutable = import_node_fs27.default.realpathSync(nodeExecutable);
148427
+ const realRunnerPath = import_node_fs27.default.realpathSync(runnerPath);
148419
148428
  const realDataDirectory = realPermissionPath(dataDirectory);
148420
148429
  const realActionDirectory = realPermissionPath(actionDirectory);
148421
148430
  const realWorkingDirectory = realPermissionPath(workingDirectory);
@@ -148467,11 +148476,11 @@ function permissionArguments(permissions, runnerPath, nodeExecutable, dataDirect
148467
148476
  function realPermissionPath(candidate) {
148468
148477
  let existing = import_node_path33.default.resolve(candidate);
148469
148478
  const suffix = [];
148470
- while (!import_node_fs26.default.existsSync(existing)) {
148479
+ while (!import_node_fs27.default.existsSync(existing)) {
148471
148480
  suffix.unshift(import_node_path33.default.basename(existing));
148472
148481
  existing = import_node_path33.default.dirname(existing);
148473
148482
  }
148474
- return import_node_path33.default.join(import_node_fs26.default.realpathSync(existing), ...suffix);
148483
+ return import_node_path33.default.join(import_node_fs27.default.realpathSync(existing), ...suffix);
148475
148484
  }
148476
148485
  function minimalEnvironment() {
148477
148486
  const environment = {};
@@ -148608,7 +148617,7 @@ async function stopChild(child) {
148608
148617
  }
148609
148618
 
148610
148619
  // packages/server/src/lib/device-action-local-store.ts
148611
- var import_node_fs27 = __toESM(require("node:fs"));
148620
+ var import_node_fs28 = __toESM(require("node:fs"));
148612
148621
  var import_node_path34 = __toESM(require("node:path"));
148613
148622
  var import_node_crypto28 = require("node:crypto");
148614
148623
  var TERMINAL = /* @__PURE__ */ new Set(["succeeded", "failed", "cancelled", "expired", "interrupted"]);
@@ -148631,7 +148640,7 @@ var DeviceActionLocalStore = class {
148631
148640
  logs;
148632
148641
  constructor(dataDir2) {
148633
148642
  const directory = import_node_path34.default.join(dataDir2, "device-actions");
148634
- import_node_fs27.default.mkdirSync(directory, { recursive: true, mode: 448 });
148643
+ import_node_fs28.default.mkdirSync(directory, { recursive: true, mode: 448 });
148635
148644
  this.filePath = import_node_path34.default.join(directory, "actions.json");
148636
148645
  this.installationPath = import_node_path34.default.join(directory, "installation-id");
148637
148646
  const loaded = this.load();
@@ -148639,12 +148648,12 @@ var DeviceActionLocalStore = class {
148639
148648
  this.logs = loaded.logs;
148640
148649
  }
148641
148650
  installationId() {
148642
- if (import_node_fs27.default.existsSync(this.installationPath)) {
148643
- const current = import_node_fs27.default.readFileSync(this.installationPath, "utf8").trim();
148651
+ if (import_node_fs28.default.existsSync(this.installationPath)) {
148652
+ const current = import_node_fs28.default.readFileSync(this.installationPath, "utf8").trim();
148644
148653
  if (/^[0-9a-f-]{36}$/.test(current)) return current;
148645
148654
  }
148646
148655
  const value = (0, import_node_crypto28.randomUUID)();
148647
- import_node_fs27.default.writeFileSync(this.installationPath, `${value}
148656
+ import_node_fs28.default.writeFileSync(this.installationPath, `${value}
148648
148657
  `, { mode: 384 });
148649
148658
  return value;
148650
148659
  }
@@ -148732,9 +148741,9 @@ var DeviceActionLocalStore = class {
148732
148741
  if (this.logs.length > 5e3) this.logs = this.logs.slice(-5e3);
148733
148742
  }
148734
148743
  load() {
148735
- if (!import_node_fs27.default.existsSync(this.filePath)) return { records: [], logs: [] };
148744
+ if (!import_node_fs28.default.existsSync(this.filePath)) return { records: [], logs: [] };
148736
148745
  try {
148737
- const parsed = JSON.parse(import_node_fs27.default.readFileSync(this.filePath, "utf8"));
148746
+ const parsed = JSON.parse(import_node_fs28.default.readFileSync(this.filePath, "utf8"));
148738
148747
  const records = Array.isArray(parsed.records) ? parsed.records : [];
148739
148748
  const logs = Array.isArray(parsed.logs) ? parsed.logs : [];
148740
148749
  return { records, logs };
@@ -148744,9 +148753,9 @@ var DeviceActionLocalStore = class {
148744
148753
  }
148745
148754
  persist() {
148746
148755
  const temporary = `${this.filePath}.${process.pid}.tmp`;
148747
- import_node_fs27.default.writeFileSync(temporary, `${JSON.stringify({ records: this.records, logs: this.logs }, null, 2)}
148756
+ import_node_fs28.default.writeFileSync(temporary, `${JSON.stringify({ records: this.records, logs: this.logs }, null, 2)}
148748
148757
  `, { mode: 384 });
148749
- import_node_fs27.default.renameSync(temporary, this.filePath);
148758
+ import_node_fs28.default.renameSync(temporary, this.filePath);
148750
148759
  }
148751
148760
  };
148752
148761
  function toSnapshot2(record) {
@@ -148755,7 +148764,7 @@ function toSnapshot2(record) {
148755
148764
  }
148756
148765
 
148757
148766
  // packages/server/src/lib/device-action-trust-store.ts
148758
- var import_node_fs28 = __toESM(require("node:fs"));
148767
+ var import_node_fs29 = __toESM(require("node:fs"));
148759
148768
  var import_node_path35 = __toESM(require("node:path"));
148760
148769
  var DeviceActionTrustStore = class {
148761
148770
  filePath;
@@ -148796,9 +148805,9 @@ var DeviceActionTrustStore = class {
148796
148805
  return this.grants.map((grant) => ({ ...grant, permissions: { ...grant.permissions } }));
148797
148806
  }
148798
148807
  load() {
148799
- if (!this.filePath || !import_node_fs28.default.existsSync(this.filePath)) return [];
148808
+ if (!this.filePath || !import_node_fs29.default.existsSync(this.filePath)) return [];
148800
148809
  try {
148801
- const parsed = JSON.parse(import_node_fs28.default.readFileSync(this.filePath, "utf8"));
148810
+ const parsed = JSON.parse(import_node_fs29.default.readFileSync(this.filePath, "utf8"));
148802
148811
  if (!Array.isArray(parsed)) return [];
148803
148812
  return parsed.flatMap((candidate) => {
148804
148813
  try {
@@ -148828,11 +148837,11 @@ var DeviceActionTrustStore = class {
148828
148837
  }
148829
148838
  persist() {
148830
148839
  if (!this.filePath) return;
148831
- import_node_fs28.default.mkdirSync(import_node_path35.default.dirname(this.filePath), { recursive: true, mode: 448 });
148840
+ import_node_fs29.default.mkdirSync(import_node_path35.default.dirname(this.filePath), { recursive: true, mode: 448 });
148832
148841
  const temporary = `${this.filePath}.${process.pid}.tmp`;
148833
- import_node_fs28.default.writeFileSync(temporary, `${JSON.stringify(this.grants, null, 2)}
148842
+ import_node_fs29.default.writeFileSync(temporary, `${JSON.stringify(this.grants, null, 2)}
148834
148843
  `, { mode: 384 });
148835
- import_node_fs28.default.renameSync(temporary, this.filePath);
148844
+ import_node_fs29.default.renameSync(temporary, this.filePath);
148836
148845
  }
148837
148846
  };
148838
148847
  function sameIdentity(left, right) {
@@ -149207,7 +149216,7 @@ init_meta_sqlite();
149207
149216
 
149208
149217
  // packages/server/src/lib/platform-migrations.ts
149209
149218
  var import_node_crypto30 = __toESM(require("node:crypto"));
149210
- var import_node_fs29 = __toESM(require("node:fs"));
149219
+ var import_node_fs30 = __toESM(require("node:fs"));
149211
149220
  var import_node_path37 = __toESM(require("node:path"));
149212
149221
  var import_sql4 = __toESM(require("sql.js"));
149213
149222
  var import_server_core11 = __toESM(require_dist5());
@@ -149222,7 +149231,7 @@ async function getSqlJs() {
149222
149231
  async function applyPlatformMigrationsToAllApps(options2) {
149223
149232
  const migrationsDir = options2.migrationsDir ?? import_node_path37.default.resolve(__dirname, "../../platform-migrations");
149224
149233
  const migrations = readPlatformMigrationFiles(migrationsDir);
149225
- if (migrations.length === 0 || !import_node_fs29.default.existsSync(options2.dataDir)) return;
149234
+ if (migrations.length === 0 || !import_node_fs30.default.existsSync(options2.dataDir)) return;
149226
149235
  for (const { userId, pageName, pageDir } of listAppDirs(options2.dataDir)) {
149227
149236
  try {
149228
149237
  await applyPlatformMigrationsToApp(import_node_path37.default.join(pageDir, "app.db"), migrations);
@@ -149237,14 +149246,14 @@ async function applyPlatformMigrationsToAllApps(options2) {
149237
149246
  }
149238
149247
  }
149239
149248
  function readPlatformMigrationFiles(migrationsDir) {
149240
- if (!import_node_fs29.default.existsSync(migrationsDir)) return [];
149241
- const filenames = import_node_fs29.default.readdirSync(migrationsDir).filter((filename) => filename.endsWith(".sql"));
149249
+ if (!import_node_fs30.default.existsSync(migrationsDir)) return [];
149250
+ const filenames = import_node_fs30.default.readdirSync(migrationsDir).filter((filename) => filename.endsWith(".sql"));
149242
149251
  const validation = (0, import_server_core11.validateMigrationFilenames)(filenames);
149243
149252
  if (!validation.valid) {
149244
149253
  throw new Error(validation.errors.join("\n"));
149245
149254
  }
149246
149255
  return filenames.sort().map((filename) => {
149247
- const sql = import_node_fs29.default.readFileSync(import_node_path37.default.join(migrationsDir, filename), "utf8");
149256
+ const sql = import_node_fs30.default.readFileSync(import_node_path37.default.join(migrationsDir, filename), "utf8");
149248
149257
  return {
149249
149258
  filename,
149250
149259
  sql,
@@ -149253,9 +149262,9 @@ function readPlatformMigrationFiles(migrationsDir) {
149253
149262
  });
149254
149263
  }
149255
149264
  async function applyPlatformMigrationsToApp(dbPath2, migrations) {
149256
- if (!import_node_fs29.default.existsSync(dbPath2)) return;
149265
+ if (!import_node_fs30.default.existsSync(dbPath2)) return;
149257
149266
  const SQL = await getSqlJs();
149258
- const db2 = new SQL.Database(import_node_fs29.default.readFileSync(dbPath2));
149267
+ const db2 = new SQL.Database(import_node_fs30.default.readFileSync(dbPath2));
149259
149268
  const applied = [];
149260
149269
  try {
149261
149270
  ensureAppliedPlatformMigrationsTable(db2);
@@ -149282,7 +149291,7 @@ async function applyPlatformMigrationsToApp(dbPath2, migrations) {
149282
149291
  applied.push(migration.filename);
149283
149292
  }
149284
149293
  if (applied.length > 0) {
149285
- import_node_fs29.default.writeFileSync(dbPath2, Buffer.from(db2.export()));
149294
+ import_node_fs30.default.writeFileSync(dbPath2, Buffer.from(db2.export()));
149286
149295
  }
149287
149296
  } finally {
149288
149297
  db2.close();
@@ -149308,13 +149317,13 @@ function getAppliedChecksums(db2) {
149308
149317
  }
149309
149318
  function listAppDirs(dataDir2) {
149310
149319
  const apps = [];
149311
- for (const userEntry of import_node_fs29.default.readdirSync(dataDir2, { withFileTypes: true })) {
149320
+ for (const userEntry of import_node_fs30.default.readdirSync(dataDir2, { withFileTypes: true })) {
149312
149321
  if (!userEntry.isDirectory()) continue;
149313
149322
  const userDir = import_node_path37.default.join(dataDir2, userEntry.name);
149314
- for (const pageEntry of import_node_fs29.default.readdirSync(userDir, { withFileTypes: true })) {
149323
+ for (const pageEntry of import_node_fs30.default.readdirSync(userDir, { withFileTypes: true })) {
149315
149324
  if (!pageEntry.isDirectory()) continue;
149316
149325
  const pageDir = import_node_path37.default.join(userDir, pageEntry.name);
149317
- if (import_node_fs29.default.existsSync(import_node_path37.default.join(pageDir, "meta.json"))) {
149326
+ if (import_node_fs30.default.existsSync(import_node_path37.default.join(pageDir, "meta.json"))) {
149318
149327
  apps.push({ userId: userEntry.name, pageName: pageEntry.name, pageDir });
149319
149328
  }
149320
149329
  }
@@ -149553,7 +149562,7 @@ async function systemRoutes(app, options2) {
149553
149562
 
149554
149563
  // packages/server/src/routes/apps.ts
149555
149564
  var import_node_crypto33 = __toESM(require("node:crypto"));
149556
- var import_node_fs30 = __toESM(require("node:fs"));
149565
+ var import_node_fs31 = __toESM(require("node:fs"));
149557
149566
  var import_node_path39 = __toESM(require("node:path"));
149558
149567
  var import_promises9 = require("node:stream/promises");
149559
149568
  init_meta_sqlite();
@@ -149561,7 +149570,7 @@ async function appsRoutes(app) {
149561
149570
  app.post("/api/me/apps/install", async (req, reply) => {
149562
149571
  const uploadDir = import_node_path39.default.join(app.config.dataDir, ".staging", "app-uploads", import_node_crypto33.default.randomUUID());
149563
149572
  const packagePath = import_node_path39.default.join(uploadDir, "application.localapp");
149564
- import_node_fs30.default.mkdirSync(uploadDir, { recursive: true });
149573
+ import_node_fs31.default.mkdirSync(uploadDir, { recursive: true });
149565
149574
  try {
149566
149575
  let received = false;
149567
149576
  const parts = req.parts({ limits: { files: 1, fileSize: MAX_APP_PACKAGE_BYTES } });
@@ -149576,7 +149585,7 @@ async function appsRoutes(app) {
149576
149585
  throw new AppInstallError("APP_PACKAGE_REQUIRED", "Application package filename must end in .localapp", 400);
149577
149586
  }
149578
149587
  received = true;
149579
- await (0, import_promises9.pipeline)(part.file, import_node_fs30.default.createWriteStream(packagePath, { flags: "wx", mode: 384 }));
149588
+ await (0, import_promises9.pipeline)(part.file, import_node_fs31.default.createWriteStream(packagePath, { flags: "wx", mode: 384 }));
149580
149589
  if (part.file.truncated) {
149581
149590
  throw new AppInstallError("APP_PACKAGE_TOO_LARGE", `Application package exceeds ${MAX_APP_PACKAGE_BYTES} bytes`, 413);
149582
149591
  }
@@ -149593,7 +149602,7 @@ async function appsRoutes(app) {
149593
149602
  } catch (error5) {
149594
149603
  return sendInstallError(reply, error5);
149595
149604
  } finally {
149596
- import_node_fs30.default.rmSync(uploadDir, { recursive: true, force: true });
149605
+ import_node_fs31.default.rmSync(uploadDir, { recursive: true, force: true });
149597
149606
  }
149598
149607
  });
149599
149608
  app.get("/api/me/apps/:name/versions", async (req, reply) => {
@@ -149661,7 +149670,7 @@ function sendInstallError(reply, error5) {
149661
149670
  // packages/server/src/lib/workspace-store.ts
149662
149671
  var import_node_crypto34 = require("node:crypto");
149663
149672
  var import_node_child_process3 = require("node:child_process");
149664
- var import_node_fs32 = __toESM(require("node:fs"));
149673
+ var import_node_fs33 = __toESM(require("node:fs"));
149665
149674
  var import_node_path41 = __toESM(require("node:path"));
149666
149675
  var import_node_stream13 = require("node:stream");
149667
149676
  var import_promises10 = require("node:stream/promises");
@@ -149669,7 +149678,7 @@ var import_yauzl3 = __toESM(require_yauzl());
149669
149678
  init_meta_sqlite();
149670
149679
 
149671
149680
  // packages/server/src/lib/workspace-path.ts
149672
- var import_node_fs31 = __toESM(require("node:fs"));
149681
+ var import_node_fs32 = __toESM(require("node:fs"));
149673
149682
  var import_node_path40 = __toESM(require("node:path"));
149674
149683
  function isConfined(root5, candidate) {
149675
149684
  const relative = import_node_path40.default.relative(root5, candidate);
@@ -149679,20 +149688,20 @@ function boundaryError(relativePath2) {
149679
149688
  return new Error(`Path crosses workspace boundary: ${relativePath2}`);
149680
149689
  }
149681
149690
  function resolveWorkspacePath(workspaceRoot, relativePath2) {
149682
- const realRoot = import_node_fs31.default.realpathSync(import_node_path40.default.resolve(workspaceRoot));
149691
+ const realRoot = import_node_fs32.default.realpathSync(import_node_path40.default.resolve(workspaceRoot));
149683
149692
  if (import_node_path40.default.isAbsolute(relativePath2)) throw boundaryError(relativePath2);
149684
149693
  const candidate = import_node_path40.default.resolve(realRoot, relativePath2 || ".");
149685
149694
  if (!isConfined(realRoot, candidate)) throw boundaryError(relativePath2);
149686
149695
  let existingAncestor = candidate;
149687
- while (!import_node_fs31.default.existsSync(existingAncestor)) {
149696
+ while (!import_node_fs32.default.existsSync(existingAncestor)) {
149688
149697
  const parent = import_node_path40.default.dirname(existingAncestor);
149689
149698
  if (parent === existingAncestor) throw boundaryError(relativePath2);
149690
149699
  existingAncestor = parent;
149691
149700
  }
149692
- const realAncestor = import_node_fs31.default.realpathSync(existingAncestor);
149701
+ const realAncestor = import_node_fs32.default.realpathSync(existingAncestor);
149693
149702
  if (!isConfined(realRoot, realAncestor)) throw boundaryError(relativePath2);
149694
- if (import_node_fs31.default.existsSync(candidate)) {
149695
- const realCandidate = import_node_fs31.default.realpathSync(candidate);
149703
+ if (import_node_fs32.default.existsSync(candidate)) {
149704
+ const realCandidate = import_node_fs32.default.realpathSync(candidate);
149696
149705
  if (!isConfined(realRoot, realCandidate)) throw boundaryError(relativePath2);
149697
149706
  }
149698
149707
  return candidate;
@@ -149803,12 +149812,12 @@ var WorkspaceStore = class {
149803
149812
  const workspaceDir = import_node_path41.default.resolve(options2.workspaceDir);
149804
149813
  this.archiveLimits = { ...DEFAULT_ARCHIVE_LIMITS2, ...options2.archiveLimits };
149805
149814
  this.fileOperations = {
149806
- openSync: options2.fileOperations?.openSync ?? import_node_fs32.default.openSync,
149807
- renameSync: options2.fileOperations?.renameSync ?? import_node_fs32.default.renameSync
149815
+ openSync: options2.fileOperations?.openSync ?? import_node_fs33.default.openSync,
149816
+ renameSync: options2.fileOperations?.renameSync ?? import_node_fs33.default.renameSync
149808
149817
  };
149809
149818
  this.processController = options2.processController ?? new ProcessTreeController();
149810
- import_node_fs32.default.mkdirSync(workspaceDir, { recursive: true });
149811
- this.workspaceDir = import_node_fs32.default.realpathSync(workspaceDir);
149819
+ import_node_fs33.default.mkdirSync(workspaceDir, { recursive: true });
149820
+ this.workspaceDir = import_node_fs33.default.realpathSync(workspaceDir);
149812
149821
  }
149813
149822
  workspaceDir;
149814
149823
  archiveLimits;
@@ -149824,13 +149833,13 @@ var WorkspaceStore = class {
149824
149833
  const id2 = (0, import_node_crypto34.randomUUID)();
149825
149834
  const temporary = this.temporaryPath(id2);
149826
149835
  const destination = this.pathFor(id2);
149827
- import_node_fs32.default.mkdirSync(temporary, { recursive: true });
149836
+ import_node_fs33.default.mkdirSync(temporary, { recursive: true });
149828
149837
  try {
149829
- import_node_fs32.default.renameSync(temporary, destination);
149838
+ import_node_fs33.default.renameSync(temporary, destination);
149830
149839
  return this.insert({ id: id2, ownerId: input.ownerId, name });
149831
149840
  } catch (error5) {
149832
- import_node_fs32.default.rmSync(temporary, { recursive: true, force: true });
149833
- import_node_fs32.default.rmSync(destination, { recursive: true, force: true });
149841
+ import_node_fs33.default.rmSync(temporary, { recursive: true, force: true });
149842
+ import_node_fs33.default.rmSync(destination, { recursive: true, force: true });
149834
149843
  throw error5;
149835
149844
  }
149836
149845
  }
@@ -149850,30 +149859,30 @@ var WorkspaceStore = class {
149850
149859
  const destination = this.pathFor(id2);
149851
149860
  try {
149852
149861
  await this.runGitClone(repositoryUrl, temporary, input.signal, input.timeoutMs);
149853
- import_node_fs32.default.renameSync(temporary, destination);
149862
+ import_node_fs33.default.renameSync(temporary, destination);
149854
149863
  return this.insert({ id: id2, ownerId: input.ownerId, name });
149855
149864
  } catch (error5) {
149856
- import_node_fs32.default.rmSync(temporary, { recursive: true, force: true });
149857
- import_node_fs32.default.rmSync(destination, { recursive: true, force: true });
149865
+ import_node_fs33.default.rmSync(temporary, { recursive: true, force: true });
149866
+ import_node_fs33.default.rmSync(destination, { recursive: true, force: true });
149858
149867
  throw error5;
149859
149868
  }
149860
149869
  }
149861
149870
  async importArchive(input) {
149862
149871
  const name = requireName(input.name);
149863
149872
  const archivePath = import_node_path41.default.resolve(input.archivePath);
149864
- const archiveSize = import_node_fs32.default.statSync(archivePath).size;
149873
+ const archiveSize = import_node_fs33.default.statSync(archivePath).size;
149865
149874
  if (archiveSize > this.archiveLimits.maxCompressedBytes) throw archiveLimitError("compressed size");
149866
149875
  const id2 = (0, import_node_crypto34.randomUUID)();
149867
149876
  const temporary = this.temporaryPath(id2);
149868
149877
  const destination = this.pathFor(id2);
149869
- import_node_fs32.default.mkdirSync(temporary, { recursive: true });
149878
+ import_node_fs33.default.mkdirSync(temporary, { recursive: true });
149870
149879
  try {
149871
149880
  await extractArchive(archivePath, temporary, this.archiveLimits);
149872
- import_node_fs32.default.renameSync(temporary, destination);
149881
+ import_node_fs33.default.renameSync(temporary, destination);
149873
149882
  return this.insert({ id: id2, ownerId: input.ownerId, name });
149874
149883
  } catch (error5) {
149875
- import_node_fs32.default.rmSync(temporary, { recursive: true, force: true });
149876
- import_node_fs32.default.rmSync(destination, { recursive: true, force: true });
149884
+ import_node_fs33.default.rmSync(temporary, { recursive: true, force: true });
149885
+ import_node_fs33.default.rmSync(destination, { recursive: true, force: true });
149877
149886
  throw error5;
149878
149887
  }
149879
149888
  }
@@ -149903,9 +149912,9 @@ var WorkspaceStore = class {
149903
149912
  requireOwnedPath(id2, ownerId) {
149904
149913
  if (!this.getOwned(id2, ownerId)) throw new Error("WORKSPACE_NOT_FOUND");
149905
149914
  const workspacePath = this.pathFor(id2);
149906
- const workspaceStat = import_node_fs32.default.lstatSync(workspacePath, { throwIfNoEntry: false });
149915
+ const workspaceStat = import_node_fs33.default.lstatSync(workspacePath, { throwIfNoEntry: false });
149907
149916
  if (!workspaceStat?.isDirectory() || workspaceStat.isSymbolicLink()) throw new Error("WORKSPACE_NOT_FOUND");
149908
- if (import_node_fs32.default.realpathSync(workspacePath) !== workspacePath) throw new Error("WORKSPACE_NOT_FOUND");
149917
+ if (import_node_fs33.default.realpathSync(workspacePath) !== workspacePath) throw new Error("WORKSPACE_NOT_FOUND");
149909
149918
  return workspacePath;
149910
149919
  }
149911
149920
  async readFile(id2, ownerId, relativePath2) {
@@ -149913,7 +149922,7 @@ var WorkspaceStore = class {
149913
149922
  const filePath = resolveWorkspacePath(workspacePath, relativePath2);
149914
149923
  let descriptor;
149915
149924
  try {
149916
- descriptor = this.fileOperations.openSync(filePath, import_node_fs32.default.constants.O_RDONLY | noFollowFlag());
149925
+ descriptor = this.fileOperations.openSync(filePath, import_node_fs33.default.constants.O_RDONLY | noFollowFlag());
149917
149926
  } catch (error5) {
149918
149927
  const code = error5.code;
149919
149928
  if (code === "ELOOP") throw workspaceBoundaryChanged();
@@ -149921,40 +149930,40 @@ var WorkspaceStore = class {
149921
149930
  throw error5;
149922
149931
  }
149923
149932
  try {
149924
- const identity = import_node_fs32.default.fstatSync(descriptor);
149933
+ const identity = import_node_fs33.default.fstatSync(descriptor);
149925
149934
  if (!identity.isFile()) throw new Error("WORKSPACE_FILE_NOT_FOUND");
149926
149935
  assertStableWorkspaceFile(workspacePath, relativePath2, filePath, identity);
149927
- return import_node_fs32.default.readFileSync(descriptor, "utf8");
149936
+ return import_node_fs33.default.readFileSync(descriptor, "utf8");
149928
149937
  } finally {
149929
- import_node_fs32.default.closeSync(descriptor);
149938
+ import_node_fs33.default.closeSync(descriptor);
149930
149939
  }
149931
149940
  }
149932
149941
  async writeFile(id2, ownerId, relativePath2, content3) {
149933
149942
  const workspacePath = this.requireOwnedPath(id2, ownerId);
149934
149943
  const filePath = resolveWorkspacePath(workspacePath, relativePath2);
149935
149944
  const parentPath = import_node_path41.default.dirname(filePath);
149936
- import_node_fs32.default.mkdirSync(parentPath, { recursive: true });
149945
+ import_node_fs33.default.mkdirSync(parentPath, { recursive: true });
149937
149946
  assertStableWorkspaceDirectory(workspacePath, import_node_path41.default.relative(workspacePath, parentPath), parentPath);
149938
149947
  const temporaryPath = import_node_path41.default.join(parentPath, `.localapp-write-${(0, import_node_crypto34.randomUUID)()}.tmp`);
149939
149948
  const descriptor = this.fileOperations.openSync(
149940
149949
  temporaryPath,
149941
- import_node_fs32.default.constants.O_WRONLY | import_node_fs32.default.constants.O_CREAT | import_node_fs32.default.constants.O_EXCL | noFollowFlag(),
149950
+ import_node_fs33.default.constants.O_WRONLY | import_node_fs33.default.constants.O_CREAT | import_node_fs33.default.constants.O_EXCL | noFollowFlag(),
149942
149951
  384
149943
149952
  );
149944
149953
  let published = false;
149945
149954
  try {
149946
- import_node_fs32.default.writeFileSync(descriptor, content3);
149947
- import_node_fs32.default.fsyncSync(descriptor);
149948
- const identity = import_node_fs32.default.fstatSync(descriptor);
149955
+ import_node_fs33.default.writeFileSync(descriptor, content3);
149956
+ import_node_fs33.default.fsyncSync(descriptor);
149957
+ const identity = import_node_fs33.default.fstatSync(descriptor);
149949
149958
  assertStableWorkspaceFile(workspacePath, import_node_path41.default.relative(workspacePath, temporaryPath), temporaryPath, identity);
149950
- const target = import_node_fs32.default.lstatSync(filePath, { throwIfNoEntry: false });
149959
+ const target = import_node_fs33.default.lstatSync(filePath, { throwIfNoEntry: false });
149951
149960
  if (target?.isSymbolicLink()) throw workspaceBoundaryChanged();
149952
149961
  this.fileOperations.renameSync(temporaryPath, filePath);
149953
149962
  published = true;
149954
149963
  assertStableWorkspaceFile(workspacePath, relativePath2, filePath, identity);
149955
149964
  } finally {
149956
- import_node_fs32.default.closeSync(descriptor);
149957
- if (!published) import_node_fs32.default.rmSync(temporaryPath, { force: true });
149965
+ import_node_fs33.default.closeSync(descriptor);
149966
+ if (!published) import_node_fs33.default.rmSync(temporaryPath, { force: true });
149958
149967
  }
149959
149968
  const now = (/* @__PURE__ */ new Date()).toISOString();
149960
149969
  getDb().run("UPDATE workspaces SET updated_at = ? WHERE id = ? AND owner_id = ?", [now, id2, ownerId]);
@@ -149964,16 +149973,16 @@ var WorkspaceStore = class {
149964
149973
  const record = this.getOwned(id2, ownerId);
149965
149974
  if (!record) return false;
149966
149975
  const workspacePath = this.requireOwnedPath(id2, ownerId);
149967
- const identity = import_node_fs32.default.lstatSync(workspacePath);
149976
+ const identity = import_node_fs33.default.lstatSync(workspacePath);
149968
149977
  const tombstone = import_node_path41.default.join(this.workspaceDir, `.delete-${id2}-${(0, import_node_crypto34.randomUUID)()}`);
149969
149978
  this.fileOperations.renameSync(workspacePath, tombstone);
149970
- const moved = import_node_fs32.default.lstatSync(tombstone, { throwIfNoEntry: false });
149979
+ const moved = import_node_fs33.default.lstatSync(tombstone, { throwIfNoEntry: false });
149971
149980
  if (!moved || moved.isSymbolicLink() || moved.dev !== identity.dev || moved.ino !== identity.ino) {
149972
- if (moved?.isSymbolicLink()) import_node_fs32.default.unlinkSync(tombstone);
149981
+ if (moved?.isSymbolicLink()) import_node_fs33.default.unlinkSync(tombstone);
149973
149982
  throw workspaceBoundaryChanged();
149974
149983
  }
149975
- if (import_node_path41.default.dirname(import_node_fs32.default.realpathSync(tombstone)) !== this.workspaceDir) throw workspaceBoundaryChanged();
149976
- import_node_fs32.default.rmSync(tombstone, { recursive: true, force: true });
149984
+ if (import_node_path41.default.dirname(import_node_fs33.default.realpathSync(tombstone)) !== this.workspaceDir) throw workspaceBoundaryChanged();
149985
+ import_node_fs33.default.rmSync(tombstone, { recursive: true, force: true });
149977
149986
  getDb().run("DELETE FROM workspaces WHERE id = ? AND owner_id = ?", [id2, ownerId]);
149978
149987
  flushMetaDb();
149979
149988
  return true;
@@ -150024,7 +150033,7 @@ var WorkspaceStore = class {
150024
150033
  if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 15 * 6e4) throw new Error("Invalid Git clone timeout");
150025
150034
  if (signal?.aborted) throw new Error("Git clone aborted");
150026
150035
  const environmentDirectory = import_node_path41.default.join(this.workspaceDir, `.git-env-${(0, import_node_crypto34.randomUUID)()}`);
150027
- import_node_fs32.default.mkdirSync(environmentDirectory, { mode: 448 });
150036
+ import_node_fs33.default.mkdirSync(environmentDirectory, { mode: 448 });
150028
150037
  return new Promise((resolve3, reject) => {
150029
150038
  const child = (0, import_node_child_process3.spawn)(this.options.gitExecutable ?? "git", ["clone", "--", repositoryUrl, destination], {
150030
150039
  shell: false,
@@ -150059,14 +150068,14 @@ var WorkspaceStore = class {
150059
150068
  clearTimeout(timer2);
150060
150069
  signal?.removeEventListener("abort", onAbort);
150061
150070
  this.cloneProcesses.delete(active);
150062
- import_node_fs32.default.rmSync(environmentDirectory, { recursive: true, force: true });
150071
+ import_node_fs33.default.rmSync(environmentDirectory, { recursive: true, force: true });
150063
150072
  closeActive();
150064
150073
  };
150065
150074
  child.stderr.on("data", (chunk) => {
150066
150075
  if (stderr.length < 64 * 1024) stderr += String(chunk);
150067
150076
  });
150068
150077
  child.once("error", (error5) => {
150069
- import_node_fs32.default.rmSync(destination, { recursive: true, force: true });
150078
+ import_node_fs33.default.rmSync(destination, { recursive: true, force: true });
150070
150079
  cleanup();
150071
150080
  if (!settled) {
150072
150081
  settled = true;
@@ -150074,7 +150083,7 @@ var WorkspaceStore = class {
150074
150083
  }
150075
150084
  });
150076
150085
  child.once("close", (code, signal2) => {
150077
- if (requestedError || code !== 0) import_node_fs32.default.rmSync(destination, { recursive: true, force: true });
150086
+ if (requestedError || code !== 0) import_node_fs33.default.rmSync(destination, { recursive: true, force: true });
150078
150087
  cleanup();
150079
150088
  if (settled) return;
150080
150089
  settled = true;
@@ -150086,7 +150095,7 @@ var WorkspaceStore = class {
150086
150095
  }
150087
150096
  };
150088
150097
  function noFollowFlag() {
150089
- return typeof import_node_fs32.default.constants.O_NOFOLLOW === "number" ? import_node_fs32.default.constants.O_NOFOLLOW : 0;
150098
+ return typeof import_node_fs33.default.constants.O_NOFOLLOW === "number" ? import_node_fs33.default.constants.O_NOFOLLOW : 0;
150090
150099
  }
150091
150100
  function workspaceBoundaryChanged() {
150092
150101
  return new Error("Workspace boundary changed during filesystem operation");
@@ -150094,7 +150103,7 @@ function workspaceBoundaryChanged() {
150094
150103
  function assertStableWorkspaceDirectory(workspacePath, relativePath2, expectedPath) {
150095
150104
  try {
150096
150105
  const resolved = resolveWorkspacePath(workspacePath, relativePath2 || ".");
150097
- const stat2 = import_node_fs32.default.lstatSync(resolved);
150106
+ const stat2 = import_node_fs33.default.lstatSync(resolved);
150098
150107
  if (resolved !== expectedPath || stat2.isSymbolicLink() || !stat2.isDirectory()) throw workspaceBoundaryChanged();
150099
150108
  } catch {
150100
150109
  throw workspaceBoundaryChanged();
@@ -150103,7 +150112,7 @@ function assertStableWorkspaceDirectory(workspacePath, relativePath2, expectedPa
150103
150112
  function assertStableWorkspaceFile(workspacePath, relativePath2, expectedPath, identity) {
150104
150113
  try {
150105
150114
  const resolved = resolveWorkspacePath(workspacePath, relativePath2);
150106
- const stat2 = import_node_fs32.default.lstatSync(resolved);
150115
+ const stat2 = import_node_fs33.default.lstatSync(resolved);
150107
150116
  if (resolved !== expectedPath || stat2.isSymbolicLink() || stat2.dev !== identity.dev || stat2.ino !== identity.ino) {
150108
150117
  throw workspaceBoundaryChanged();
150109
150118
  }
@@ -150195,9 +150204,9 @@ async function extractArchive(archivePath, destination, limits) {
150195
150204
  if (fileType === 40960) throw new Error(`Path crosses workspace boundary: ${entryName}`);
150196
150205
  const outputPath = resolveWorkspacePath(destination, normalized.replace(/\/$/, ""));
150197
150206
  if (entryName.endsWith("/")) {
150198
- import_node_fs32.default.mkdirSync(outputPath, { recursive: true });
150207
+ import_node_fs33.default.mkdirSync(outputPath, { recursive: true });
150199
150208
  } else {
150200
- import_node_fs32.default.mkdirSync(import_node_path41.default.dirname(outputPath), { recursive: true });
150209
+ import_node_fs33.default.mkdirSync(import_node_path41.default.dirname(outputPath), { recursive: true });
150201
150210
  let actualBytes = 0;
150202
150211
  const counter = new import_node_stream13.Transform({
150203
150212
  transform(chunk, _encoding, callback) {
@@ -150209,7 +150218,7 @@ async function extractArchive(archivePath, destination, limits) {
150209
150218
  }
150210
150219
  }
150211
150220
  });
150212
- await (0, import_promises10.pipeline)(await openEntry3(zipFile, entry), counter, import_node_fs32.default.createWriteStream(outputPath, { mode: 384 }));
150221
+ await (0, import_promises10.pipeline)(await openEntry3(zipFile, entry), counter, import_node_fs33.default.createWriteStream(outputPath, { mode: 384 }));
150213
150222
  }
150214
150223
  zipFile.readEntry();
150215
150224
  })().catch(fail2);
@@ -150360,7 +150369,7 @@ function taskFromRow(row) {
150360
150369
  var import_node_events2 = require("node:events");
150361
150370
  var import_node_child_process4 = require("node:child_process");
150362
150371
  var import_node_crypto36 = require("node:crypto");
150363
- var import_node_fs33 = __toESM(require("node:fs"));
150372
+ var import_node_fs34 = __toESM(require("node:fs"));
150364
150373
  var import_node_path42 = __toESM(require("node:path"));
150365
150374
  var import_node_string_decoder = require("node:string_decoder");
150366
150375
  init_meta_sqlite();
@@ -150373,7 +150382,7 @@ var TaskRunner = class {
150373
150382
  this.options = options2;
150374
150383
  this.platform = options2.platform ?? process.platform;
150375
150384
  this.processController = options2.processController ?? new ProcessTreeController();
150376
- import_node_fs33.default.mkdirSync(options2.taskDir, { recursive: true });
150385
+ import_node_fs34.default.mkdirSync(options2.taskDir, { recursive: true });
150377
150386
  for (const executable of DEFAULT_EXECUTABLES) {
150378
150387
  const resolved = executable === "node" ? process.execPath : findExecutable(executable, { platform: this.platform });
150379
150388
  if (resolved) this.allowedExecutables.set(executable, resolved);
@@ -150389,13 +150398,13 @@ var TaskRunner = class {
150389
150398
  platform;
150390
150399
  setAllowedExecutable(name, executablePath) {
150391
150400
  if (!/^[a-z0-9][a-z0-9._-]*$/i.test(name)) throw new Error("Invalid executable allowlist name");
150392
- const resolved = import_node_fs33.default.realpathSync(executablePath);
150393
- if (!import_node_fs33.default.statSync(resolved).isFile()) throw new Error("Allowlisted executable is not a file");
150401
+ const resolved = import_node_fs34.default.realpathSync(executablePath);
150402
+ if (!import_node_fs34.default.statSync(resolved).isFile()) throw new Error("Allowlisted executable is not a file");
150394
150403
  if (this.platform === "win32") {
150395
150404
  if (!isDirectWindowsExecutable(resolved)) throw new Error("Allowlisted Windows executable cannot be launched with shell:false");
150396
150405
  } else {
150397
150406
  try {
150398
- import_node_fs33.default.accessSync(resolved, import_node_fs33.default.constants.X_OK);
150407
+ import_node_fs34.default.accessSync(resolved, import_node_fs34.default.constants.X_OK);
150399
150408
  } catch {
150400
150409
  throw new Error("Allowlisted executable is not executable");
150401
150410
  }
@@ -150414,17 +150423,17 @@ var TaskRunner = class {
150414
150423
  if (!executablePath) throw new Error(`Executable is not an allowlisted executable: ${input.executable}`);
150415
150424
  const id2 = (0, import_node_crypto36.randomUUID)();
150416
150425
  const outputPath = import_node_path42.default.join(this.options.taskDir, `${id2}.log`);
150417
- import_node_fs33.default.writeFileSync(outputPath, "", { mode: 384 });
150426
+ import_node_fs34.default.writeFileSync(outputPath, "", { mode: 384 });
150418
150427
  let record;
150419
150428
  try {
150420
150429
  record = this.options.taskStore.create({ ...input, id: id2, outputPath, status: "running" });
150421
150430
  } catch (error5) {
150422
- import_node_fs33.default.rmSync(outputPath, { force: true });
150431
+ import_node_fs34.default.rmSync(outputPath, { force: true });
150423
150432
  throw error5;
150424
150433
  }
150425
150434
  const emitter = new import_node_events2.EventEmitter();
150426
150435
  this.emitters.set(record.id, emitter);
150427
- const output = input.logParser ? null : import_node_fs33.default.openSync(outputPath, "a");
150436
+ const output = input.logParser ? null : import_node_fs34.default.openSync(outputPath, "a");
150428
150437
  const identityToken = (0, import_node_crypto36.randomUUID)();
150429
150438
  const readyPath = import_node_path42.default.join(this.options.taskDir, `${id2}.supervisor-ready`);
150430
150439
  const startPath = import_node_path42.default.join(this.options.taskDir, `${id2}.supervisor-start`);
@@ -150447,12 +150456,12 @@ var TaskRunner = class {
150447
150456
  windowsHide: true
150448
150457
  });
150449
150458
  } catch (error5) {
150450
- if (output !== null) import_node_fs33.default.closeSync(output);
150459
+ if (output !== null) import_node_fs34.default.closeSync(output);
150451
150460
  const failure = this.finishSpawnFailure(record.id, error5);
150452
150461
  setImmediate(() => this.emitters.delete(record.id));
150453
150462
  return Promise.reject(failure);
150454
150463
  }
150455
- if (output !== null) import_node_fs33.default.closeSync(output);
150464
+ if (output !== null) import_node_fs34.default.closeSync(output);
150456
150465
  if (input.logParser) {
150457
150466
  this.attachParsedOutput(record.id, child.stdout, input.logParser, outputPath);
150458
150467
  this.attachParsedOutput(record.id, child.stderr, input.logParser, outputPath);
@@ -150534,9 +150543,9 @@ var TaskRunner = class {
150534
150543
  logs(id2, cursor2) {
150535
150544
  const outputPath = this.options.taskStore.outputPath(id2);
150536
150545
  if (!outputPath) throw new Error("TASK_NOT_FOUND");
150537
- const size2 = import_node_fs33.default.statSync(outputPath, { throwIfNoEntry: false })?.size ?? 0;
150546
+ const size2 = import_node_fs34.default.statSync(outputPath, { throwIfNoEntry: false })?.size ?? 0;
150538
150547
  let safeCursor = Number.isSafeInteger(cursor2) && cursor2 >= 0 ? Math.min(cursor2, size2) : 0;
150539
- const descriptor = import_node_fs33.default.openSync(outputPath, "r");
150548
+ const descriptor = import_node_fs34.default.openSync(outputPath, "r");
150540
150549
  try {
150541
150550
  while (safeCursor < size2 && isUtf8Continuation(readByte(descriptor, safeCursor))) safeCursor += 1;
150542
150551
  let end = Math.min(safeCursor + MAX_LOG_CHUNK_BYTES, size2);
@@ -150547,10 +150556,10 @@ var TaskRunner = class {
150547
150556
  }
150548
150557
  const length2 = end - safeCursor;
150549
150558
  const buffer = Buffer.alloc(length2);
150550
- if (length2 > 0) import_node_fs33.default.readSync(descriptor, buffer, 0, length2, safeCursor);
150559
+ if (length2 > 0) import_node_fs34.default.readSync(descriptor, buffer, 0, length2, safeCursor);
150551
150560
  return { cursor: safeCursor, nextCursor: end, content: buffer.toString("utf8"), eof: end >= size2 };
150552
150561
  } finally {
150553
- import_node_fs33.default.closeSync(descriptor);
150562
+ import_node_fs34.default.closeSync(descriptor);
150554
150563
  }
150555
150564
  }
150556
150565
  events(id2) {
@@ -150614,8 +150623,8 @@ var TaskRunner = class {
150614
150623
  if (!text3) return;
150615
150624
  const content3 = `${text3}
150616
150625
  `;
150617
- const cursor2 = import_node_fs33.default.statSync(outputPath).size;
150618
- import_node_fs33.default.appendFileSync(outputPath, content3);
150626
+ const cursor2 = import_node_fs34.default.statSync(outputPath).size;
150627
+ import_node_fs34.default.appendFileSync(outputPath, content3);
150619
150628
  const task = this.options.taskStore.get(id2);
150620
150629
  if (task) {
150621
150630
  this.emitters.get(id2)?.emit("event", {
@@ -150643,7 +150652,7 @@ var TaskRunner = class {
150643
150652
  };
150644
150653
  function readByte(descriptor, position2) {
150645
150654
  const byte = Buffer.allocUnsafe(1);
150646
- return import_node_fs33.default.readSync(descriptor, byte, 0, 1, position2) === 1 ? byte[0] : 0;
150655
+ return import_node_fs34.default.readSync(descriptor, byte, 0, 1, position2) === 1 ? byte[0] : 0;
150647
150656
  }
150648
150657
  function isUtf8Continuation(byte) {
150649
150658
  return (byte & 192) === 128;
@@ -150696,9 +150705,9 @@ function findExecutable(name, options2 = {}) {
150696
150705
  for (const extension2 of extensions) {
150697
150706
  const candidate = import_node_path42.default.join(directory, `${name}${extension2}`);
150698
150707
  try {
150699
- if (!import_node_fs33.default.statSync(candidate).isFile()) continue;
150700
- if (platform2 !== "win32") import_node_fs33.default.accessSync(candidate, import_node_fs33.default.constants.X_OK);
150701
- return import_node_fs33.default.realpathSync(candidate);
150708
+ if (!import_node_fs34.default.statSync(candidate).isFile()) continue;
150709
+ if (platform2 !== "win32") import_node_fs34.default.accessSync(candidate, import_node_fs34.default.constants.X_OK);
150710
+ return import_node_fs34.default.realpathSync(candidate);
150702
150711
  } catch {
150703
150712
  }
150704
150713
  }
@@ -150712,15 +150721,15 @@ function isDirectWindowsExecutable(executablePath) {
150712
150721
  return isDirectWindowsExtension(import_node_path42.default.extname(executablePath));
150713
150722
  }
150714
150723
  function cleanupSupervisorHandshake(active) {
150715
- import_node_fs33.default.rmSync(active.readyPath, { force: true });
150716
- import_node_fs33.default.rmSync(active.startPath, { force: true });
150724
+ import_node_fs34.default.rmSync(active.readyPath, { force: true });
150725
+ import_node_fs34.default.rmSync(active.startPath, { force: true });
150717
150726
  }
150718
150727
  async function waitForSupervisorReady(child, readyPath, token) {
150719
150728
  const deadline = Date.now() + 2e3;
150720
150729
  while (Date.now() < deadline) {
150721
150730
  if (child.exitCode !== null || child.signalCode !== null) throw new Error("Task supervisor exited before becoming ready");
150722
150731
  try {
150723
- const ready = JSON.parse(import_node_fs33.default.readFileSync(readyPath, "utf8"));
150732
+ const ready = JSON.parse(import_node_fs34.default.readFileSync(readyPath, "utf8"));
150724
150733
  if (ready.pid !== child.pid || ready.token !== token) throw new Error("Task supervisor ready identity did not match");
150725
150734
  return;
150726
150735
  } catch (error5) {
@@ -150731,12 +150740,12 @@ async function waitForSupervisorReady(child, readyPath, token) {
150731
150740
  throw new Error("Task supervisor did not become ready");
150732
150741
  }
150733
150742
  function writeDurableExclusive(filePath, content3) {
150734
- const descriptor = import_node_fs33.default.openSync(filePath, "wx", 384);
150743
+ const descriptor = import_node_fs34.default.openSync(filePath, "wx", 384);
150735
150744
  try {
150736
- import_node_fs33.default.writeFileSync(descriptor, content3);
150737
- import_node_fs33.default.fsyncSync(descriptor);
150745
+ import_node_fs34.default.writeFileSync(descriptor, content3);
150746
+ import_node_fs34.default.fsyncSync(descriptor);
150738
150747
  } finally {
150739
- import_node_fs33.default.closeSync(descriptor);
150748
+ import_node_fs34.default.closeSync(descriptor);
150740
150749
  }
150741
150750
  }
150742
150751
  async function waitBounded(promise, milliseconds) {
@@ -150878,7 +150887,7 @@ var AgentRunner = class {
150878
150887
 
150879
150888
  // packages/server/src/routes/workspaces.ts
150880
150889
  var import_node_crypto37 = require("node:crypto");
150881
- var import_node_fs34 = __toESM(require("node:fs"));
150890
+ var import_node_fs35 = __toESM(require("node:fs"));
150882
150891
  var import_node_path43 = __toESM(require("node:path"));
150883
150892
  var import_node_stream14 = require("node:stream");
150884
150893
  var import_promises11 = require("node:stream/promises");
@@ -150922,7 +150931,7 @@ async function workspacesRoutes(app, workspaceStore) {
150922
150931
  });
150923
150932
  app.post("/api/workspaces/import", async (request, reply) => {
150924
150933
  const uploadDirectory = import_node_path43.default.join(workspaceStore.workspaceDir, ".uploads");
150925
- import_node_fs34.default.mkdirSync(uploadDirectory, { recursive: true });
150934
+ import_node_fs35.default.mkdirSync(uploadDirectory, { recursive: true });
150926
150935
  const archivePath = import_node_path43.default.join(uploadDirectory, `${(0, import_node_crypto37.randomUUID)()}.zip`);
150927
150936
  try {
150928
150937
  const query = request.query;
@@ -150946,7 +150955,7 @@ async function workspacesRoutes(app, workspaceStore) {
150946
150955
  else callback(null, chunk);
150947
150956
  }
150948
150957
  });
150949
- await (0, import_promises11.pipeline)(part.file, limiter, import_node_fs34.default.createWriteStream(archivePath, { flags: "wx", mode: 384 }));
150958
+ await (0, import_promises11.pipeline)(part.file, limiter, import_node_fs35.default.createWriteStream(archivePath, { flags: "wx", mode: 384 }));
150950
150959
  if (part.file.truncated) throw new Error("Workspace archive limit exceeded: compressed size");
150951
150960
  }
150952
150961
  if (!archiveReceived) throw new Error("Workspace archive is required");
@@ -150956,7 +150965,7 @@ async function workspacesRoutes(app, workspaceStore) {
150956
150965
  } catch (error5) {
150957
150966
  return workspaceError(reply, error5);
150958
150967
  } finally {
150959
- import_node_fs34.default.rmSync(archivePath, { force: true });
150968
+ import_node_fs35.default.rmSync(archivePath, { force: true });
150960
150969
  }
150961
150970
  });
150962
150971
  app.get("/api/workspaces/:id/file", async (request, reply) => {
@@ -151206,7 +151215,7 @@ function requireExecutionAdmin2(userId, reply) {
151206
151215
 
151207
151216
  // packages/server/src/lib/secret-box.ts
151208
151217
  var import_node_crypto38 = require("node:crypto");
151209
- var import_node_fs35 = __toESM(require("node:fs"));
151218
+ var import_node_fs36 = __toESM(require("node:fs"));
151210
151219
  var import_node_path44 = __toESM(require("node:path"));
151211
151220
  var VERSION = "v1";
151212
151221
  var KEY_BYTES = 32;
@@ -151245,26 +151254,26 @@ var SecretBox = class {
151245
151254
  loadKey() {
151246
151255
  if (this.key) return this.key;
151247
151256
  const directory = import_node_path44.default.dirname(this.keyFile);
151248
- import_node_fs35.default.mkdirSync(directory, { recursive: true, mode: 448 });
151257
+ import_node_fs36.default.mkdirSync(directory, { recursive: true, mode: 448 });
151249
151258
  const temporaryPath = import_node_path44.default.join(directory, `.${import_node_path44.default.basename(this.keyFile)}.${process.pid}.${(0, import_node_crypto38.randomBytes)(8).toString("hex")}.tmp`);
151250
151259
  let published = false;
151251
151260
  let adopting = false;
151252
151261
  try {
151253
151262
  const generated = (0, import_node_crypto38.randomBytes)(KEY_BYTES);
151254
- const descriptor = import_node_fs35.default.openSync(temporaryPath, "wx", 384);
151263
+ const descriptor = import_node_fs36.default.openSync(temporaryPath, "wx", 384);
151255
151264
  try {
151256
- import_node_fs35.default.writeFileSync(descriptor, generated);
151257
- import_node_fs35.default.fsyncSync(descriptor);
151265
+ import_node_fs36.default.writeFileSync(descriptor, generated);
151266
+ import_node_fs36.default.fsyncSync(descriptor);
151258
151267
  } finally {
151259
- import_node_fs35.default.closeSync(descriptor);
151268
+ import_node_fs36.default.closeSync(descriptor);
151260
151269
  }
151261
- if (process.platform !== "win32") import_node_fs35.default.chmodSync(temporaryPath, 384);
151270
+ if (process.platform !== "win32") import_node_fs36.default.chmodSync(temporaryPath, 384);
151262
151271
  try {
151263
- import_node_fs35.default.linkSync(temporaryPath, this.keyFile);
151272
+ import_node_fs36.default.linkSync(temporaryPath, this.keyFile);
151264
151273
  } catch (error5) {
151265
151274
  const code = error5 instanceof Error ? error5.code : void 0;
151266
151275
  if (code === "EEXIST") {
151267
- import_node_fs35.default.rmSync(temporaryPath, { force: true });
151276
+ import_node_fs36.default.rmSync(temporaryPath, { force: true });
151268
151277
  adopting = true;
151269
151278
  this.key = adoptCompleteKey(this.keyFile, directory);
151270
151279
  return this.key;
@@ -151275,26 +151284,26 @@ var SecretBox = class {
151275
151284
  throw error5;
151276
151285
  }
151277
151286
  published = true;
151278
- import_node_fs35.default.unlinkSync(temporaryPath);
151287
+ import_node_fs36.default.unlinkSync(temporaryPath);
151279
151288
  syncDirectory6(directory);
151280
151289
  this.key = generated;
151281
151290
  } catch (error5) {
151282
- import_node_fs35.default.rmSync(temporaryPath, { force: true });
151283
- if (!published && !adopting && import_node_fs35.default.existsSync(this.keyFile)) {
151291
+ import_node_fs36.default.rmSync(temporaryPath, { force: true });
151292
+ if (!published && !adopting && import_node_fs36.default.existsSync(this.keyFile)) {
151284
151293
  adopting = true;
151285
151294
  this.key = adoptCompleteKey(this.keyFile, directory);
151286
151295
  } else {
151287
151296
  throw error5;
151288
151297
  }
151289
151298
  }
151290
- if (process.platform !== "win32") import_node_fs35.default.chmodSync(this.keyFile, 384);
151299
+ if (process.platform !== "win32") import_node_fs36.default.chmodSync(this.keyFile, 384);
151291
151300
  return this.key;
151292
151301
  }
151293
151302
  };
151294
151303
  function readCompleteKey(keyFile) {
151295
- const stored = import_node_fs35.default.readFileSync(keyFile);
151304
+ const stored = import_node_fs36.default.readFileSync(keyFile);
151296
151305
  if (stored.length !== KEY_BYTES) throw new Error("Peer master key must contain exactly 32 bytes");
151297
- if (process.platform !== "win32") import_node_fs35.default.chmodSync(keyFile, 384);
151306
+ if (process.platform !== "win32") import_node_fs36.default.chmodSync(keyFile, 384);
151298
151307
  return stored;
151299
151308
  }
151300
151309
  function adoptCompleteKey(keyFile, directory) {
@@ -151304,11 +151313,11 @@ function adoptCompleteKey(keyFile, directory) {
151304
151313
  }
151305
151314
  function syncDirectory6(directory) {
151306
151315
  try {
151307
- const descriptor = import_node_fs35.default.openSync(directory, "r");
151316
+ const descriptor = import_node_fs36.default.openSync(directory, "r");
151308
151317
  try {
151309
- import_node_fs35.default.fsyncSync(descriptor);
151318
+ import_node_fs36.default.fsyncSync(descriptor);
151310
151319
  } finally {
151311
- import_node_fs35.default.closeSync(descriptor);
151320
+ import_node_fs36.default.closeSync(descriptor);
151312
151321
  }
151313
151322
  } catch (error5) {
151314
151323
  const code = error5 instanceof Error ? error5.code : void 0;
@@ -151593,7 +151602,7 @@ async function peerProtocolRoutes(app) {
151593
151602
 
151594
151603
  // packages/server/src/lib/sync-session-store.ts
151595
151604
  var import_node_crypto40 = __toESM(require("node:crypto"));
151596
- var import_node_fs36 = __toESM(require("node:fs"));
151605
+ var import_node_fs37 = __toESM(require("node:fs"));
151597
151606
  var import_node_path45 = __toESM(require("node:path"));
151598
151607
  var MAX_SYNC_DATA_ARCHIVE_BYTES = 4 * 1024 * 1024 * 1024;
151599
151608
  var SyncSessionError = class extends Error {
@@ -151610,7 +151619,7 @@ var SyncSessionStore = class {
151610
151619
  constructor(options2) {
151611
151620
  this.rootDir = import_node_path45.default.resolve(options2.rootDir ?? import_node_path45.default.join(options2.dataDir, ".staging", "sync"));
151612
151621
  this.retentionMs = options2.retentionMs ?? 24 * 60 * 60 * 1e3;
151613
- import_node_fs36.default.mkdirSync(this.rootDir, { recursive: true, mode: 448 });
151622
+ import_node_fs37.default.mkdirSync(this.rootDir, { recursive: true, mode: 448 });
151614
151623
  }
151615
151624
  sessionDir(id2) {
151616
151625
  assertSessionId(id2);
@@ -151640,10 +151649,10 @@ var SyncSessionStore = class {
151640
151649
  const session2 = { ...normalized, status: "created", outcome: null, error: null, createdAt: now, updatedAt: now };
151641
151650
  const stagingDirectory = import_node_path45.default.join(this.rootDir, `.session-${normalized.id}-${import_node_crypto40.default.randomUUID()}.partial`);
151642
151651
  try {
151643
- import_node_fs36.default.mkdirSync(stagingDirectory, { mode: 448 });
151652
+ import_node_fs37.default.mkdirSync(stagingDirectory, { mode: 448 });
151644
151653
  this.writeInDirectory(session2, stagingDirectory);
151645
151654
  try {
151646
- import_node_fs36.default.renameSync(stagingDirectory, directory);
151655
+ import_node_fs37.default.renameSync(stagingDirectory, directory);
151647
151656
  } catch (error5) {
151648
151657
  const code = error5.code;
151649
151658
  if (!["EEXIST", "ENOTEMPTY"].includes(code ?? "")) throw error5;
@@ -151662,8 +151671,8 @@ var SyncSessionStore = class {
151662
151671
  }
151663
151672
  get(id2) {
151664
151673
  const metadataPath = import_node_path45.default.join(this.sessionDir(id2), "session.json");
151665
- if (!import_node_fs36.default.existsSync(metadataPath)) return null;
151666
- const value = JSON.parse(import_node_fs36.default.readFileSync(metadataPath, "utf8"));
151674
+ if (!import_node_fs37.default.existsSync(metadataPath)) return null;
151675
+ const value = JSON.parse(import_node_fs37.default.readFileSync(metadataPath, "utf8"));
151667
151676
  if (value.dataDigest === void 0) value.dataDigest = null;
151668
151677
  if (value.dataSize === void 0) value.dataSize = null;
151669
151678
  validateStored(value, id2);
@@ -151675,7 +151684,7 @@ var SyncSessionStore = class {
151675
151684
  }
151676
151685
  list() {
151677
151686
  const sessions = [];
151678
- for (const entry of import_node_fs36.default.readdirSync(this.rootDir, { withFileTypes: true })) {
151687
+ for (const entry of import_node_fs37.default.readdirSync(this.rootDir, { withFileTypes: true })) {
151679
151688
  if (!entry.isDirectory()) continue;
151680
151689
  try {
151681
151690
  const session2 = this.get(entry.name);
@@ -151697,15 +151706,15 @@ var SyncSessionStore = class {
151697
151706
  if (input.contentLength !== session2.packageSize) throw new SyncSessionError("SYNC_PACKAGE_SIZE_MISMATCH", "Package size does not match session metadata", 400);
151698
151707
  if (input.contentLength > MAX_APP_PACKAGE_BYTES) throw new SyncSessionError("SYNC_PACKAGE_TOO_LARGE", "Package exceeds transfer limit", 413);
151699
151708
  const finalPath = this.packagePath(input.id);
151700
- if ((session2.status === "uploaded" || session2.status === "completed") && import_node_fs36.default.existsSync(finalPath)) {
151701
- const stat2 = import_node_fs36.default.statSync(finalPath);
151709
+ if ((session2.status === "uploaded" || session2.status === "completed") && import_node_fs37.default.existsSync(finalPath)) {
151710
+ const stat2 = import_node_fs37.default.statSync(finalPath);
151702
151711
  if (stat2.size === session2.packageSize && await sha256File3(finalPath) === session2.packageDigest) return session2;
151703
151712
  throw new SyncSessionError("SYNC_PACKAGE_CONFLICT", "Staged package does not match session metadata", 409);
151704
151713
  }
151705
151714
  if (session2.status === "committing") throw new SyncSessionError("SYNC_COMMIT_IN_PROGRESS", "Synchronization commit is in progress", 409);
151706
151715
  if (session2.status === "recovery-required") throw new SyncSessionError("SYNC_RECOVERY_REQUIRED", "Synchronization requires operator recovery", 409);
151707
151716
  const partialPath = import_node_path45.default.join(this.sessionDir(input.id), `package.${process.pid}.${import_node_crypto40.default.randomUUID()}.partial`);
151708
- const handle = await import_node_fs36.default.promises.open(partialPath, "wx", 384);
151717
+ const handle = await import_node_fs37.default.promises.open(partialPath, "wx", 384);
151709
151718
  const hash2 = import_node_crypto40.default.createHash("sha256");
151710
151719
  let size2 = 0;
151711
151720
  try {
@@ -151723,12 +151732,12 @@ var SyncSessionStore = class {
151723
151732
  if (hash2.digest("hex") !== session2.packageDigest) throw new SyncSessionError("SYNC_PACKAGE_DIGEST_MISMATCH", "Uploaded package digest mismatch", 400);
151724
151733
  await handle.sync();
151725
151734
  await handle.close();
151726
- import_node_fs36.default.renameSync(partialPath, finalPath);
151735
+ import_node_fs37.default.renameSync(partialPath, finalPath);
151727
151736
  syncDirectory7(this.sessionDir(input.id));
151728
151737
  return this.transition(input.id, input.ownerId, "uploaded");
151729
151738
  } catch (error5) {
151730
151739
  await handle.close().catch(() => void 0);
151731
- import_node_fs36.default.rmSync(partialPath, { force: true });
151740
+ import_node_fs37.default.rmSync(partialPath, { force: true });
151732
151741
  throw error5;
151733
151742
  }
151734
151743
  }
@@ -151738,21 +151747,21 @@ var SyncSessionStore = class {
151738
151747
  if (session2.mode !== "app-and-data" || session2.dataDigest === null || session2.dataSize === null) {
151739
151748
  throw new SyncSessionError("SYNC_DATA_NOT_EXPECTED", "This synchronization session does not include application data", 409);
151740
151749
  }
151741
- if (!import_node_fs36.default.existsSync(this.packagePath(input.id))) {
151750
+ if (!import_node_fs37.default.existsSync(this.packagePath(input.id))) {
151742
151751
  throw new SyncSessionError("SYNC_PACKAGE_REQUIRED", "A verified package upload is required before application data", 409);
151743
151752
  }
151744
151753
  if (input.contentLength !== session2.dataSize) throw new SyncSessionError("SYNC_DATA_SIZE_MISMATCH", "Data archive size does not match session metadata", 400);
151745
151754
  if (input.contentLength > MAX_SYNC_DATA_ARCHIVE_BYTES) throw new SyncSessionError("SYNC_DATA_TOO_LARGE", "Data archive exceeds transfer limit", 413);
151746
151755
  const finalPath = this.dataPath(input.id);
151747
- if ((session2.status === "uploaded" || session2.status === "completed") && import_node_fs36.default.existsSync(finalPath)) {
151748
- const stat2 = import_node_fs36.default.statSync(finalPath);
151756
+ if ((session2.status === "uploaded" || session2.status === "completed") && import_node_fs37.default.existsSync(finalPath)) {
151757
+ const stat2 = import_node_fs37.default.statSync(finalPath);
151749
151758
  if (stat2.size === session2.dataSize && await sha256File3(finalPath) === session2.dataDigest) return session2;
151750
151759
  throw new SyncSessionError("SYNC_DATA_CONFLICT", "Staged data archive does not match session metadata", 409);
151751
151760
  }
151752
151761
  if (session2.status === "committing") throw new SyncSessionError("SYNC_COMMIT_IN_PROGRESS", "Synchronization commit is in progress", 409);
151753
151762
  if (session2.status === "recovery-required") throw new SyncSessionError("SYNC_RECOVERY_REQUIRED", "Synchronization requires operator recovery", 409);
151754
151763
  const partialPath = import_node_path45.default.join(this.sessionDir(input.id), `data.${process.pid}.${import_node_crypto40.default.randomUUID()}.partial`);
151755
- const handle = await import_node_fs36.default.promises.open(partialPath, "wx", 384);
151764
+ const handle = await import_node_fs37.default.promises.open(partialPath, "wx", 384);
151756
151765
  const hash2 = import_node_crypto40.default.createHash("sha256");
151757
151766
  let size2 = 0;
151758
151767
  try {
@@ -151770,12 +151779,12 @@ var SyncSessionStore = class {
151770
151779
  if (hash2.digest("hex") !== session2.dataDigest) throw new SyncSessionError("SYNC_DATA_DIGEST_MISMATCH", "Uploaded data archive digest mismatch", 400);
151771
151780
  await handle.sync();
151772
151781
  await handle.close();
151773
- import_node_fs36.default.renameSync(partialPath, finalPath);
151782
+ import_node_fs37.default.renameSync(partialPath, finalPath);
151774
151783
  syncDirectory7(this.sessionDir(input.id));
151775
151784
  return this.transition(input.id, input.ownerId, "uploaded");
151776
151785
  } catch (error5) {
151777
151786
  await handle.close().catch(() => void 0);
151778
- import_node_fs36.default.rmSync(partialPath, { force: true });
151787
+ import_node_fs37.default.rmSync(partialPath, { force: true });
151779
151788
  throw error5;
151780
151789
  }
151781
151790
  }
@@ -151805,10 +151814,10 @@ var SyncSessionStore = class {
151805
151814
  }
151806
151815
  prune(now = Date.now()) {
151807
151816
  let removed = 0;
151808
- for (const entry of import_node_fs36.default.readdirSync(this.rootDir, { withFileTypes: true })) {
151817
+ for (const entry of import_node_fs37.default.readdirSync(this.rootDir, { withFileTypes: true })) {
151809
151818
  if (!entry.isDirectory()) continue;
151810
151819
  const directory = import_node_path45.default.join(this.rootDir, entry.name);
151811
- const age = now - import_node_fs36.default.statSync(directory).mtimeMs;
151820
+ const age = now - import_node_fs37.default.statSync(directory).mtimeMs;
151812
151821
  if (entry.name.startsWith(".session-") && entry.name.endsWith(".partial")) {
151813
151822
  if (age > this.retentionMs) {
151814
151823
  removeDirRecursive(directory);
@@ -151843,33 +151852,33 @@ var SyncSessionStore = class {
151843
151852
  }
151844
151853
  write(session2) {
151845
151854
  const directory = this.sessionDir(session2.id);
151846
- import_node_fs36.default.mkdirSync(directory, { recursive: true, mode: 448 });
151855
+ import_node_fs37.default.mkdirSync(directory, { recursive: true, mode: 448 });
151847
151856
  this.writeInDirectory(session2, directory);
151848
151857
  }
151849
151858
  writeInDirectory(session2, directory) {
151850
151859
  const finalPath = import_node_path45.default.join(directory, "session.json");
151851
151860
  const tempPath = import_node_path45.default.join(directory, `.session.${process.pid}.${import_node_crypto40.default.randomUUID()}.partial`);
151852
151861
  try {
151853
- const descriptor = import_node_fs36.default.openSync(tempPath, "wx", 384);
151862
+ const descriptor = import_node_fs37.default.openSync(tempPath, "wx", 384);
151854
151863
  try {
151855
- import_node_fs36.default.writeFileSync(descriptor, `${JSON.stringify(session2)}
151864
+ import_node_fs37.default.writeFileSync(descriptor, `${JSON.stringify(session2)}
151856
151865
  `);
151857
- import_node_fs36.default.fsyncSync(descriptor);
151866
+ import_node_fs37.default.fsyncSync(descriptor);
151858
151867
  } finally {
151859
- import_node_fs36.default.closeSync(descriptor);
151868
+ import_node_fs37.default.closeSync(descriptor);
151860
151869
  }
151861
- import_node_fs36.default.renameSync(tempPath, finalPath);
151870
+ import_node_fs37.default.renameSync(tempPath, finalPath);
151862
151871
  syncDirectory7(directory);
151863
151872
  } finally {
151864
- import_node_fs36.default.rmSync(tempPath, { force: true });
151873
+ import_node_fs37.default.rmSync(tempPath, { force: true });
151865
151874
  }
151866
151875
  }
151867
151876
  };
151868
151877
  function isSafeUncommittedResidue(directory) {
151869
- if (!import_node_fs36.default.existsSync(directory)) return true;
151878
+ if (!import_node_fs37.default.existsSync(directory)) return true;
151870
151879
  let entries;
151871
151880
  try {
151872
- entries = import_node_fs36.default.readdirSync(directory, { withFileTypes: true });
151881
+ entries = import_node_fs37.default.readdirSync(directory, { withFileTypes: true });
151873
151882
  } catch {
151874
151883
  return false;
151875
151884
  }
@@ -151916,16 +151925,16 @@ function assertSessionId(id2) {
151916
151925
  }
151917
151926
  async function sha256File3(filePath) {
151918
151927
  const hash2 = import_node_crypto40.default.createHash("sha256");
151919
- for await (const chunk of import_node_fs36.default.createReadStream(filePath)) hash2.update(chunk);
151928
+ for await (const chunk of import_node_fs37.default.createReadStream(filePath)) hash2.update(chunk);
151920
151929
  return hash2.digest("hex");
151921
151930
  }
151922
151931
  function syncDirectory7(directory) {
151923
151932
  try {
151924
- const descriptor = import_node_fs36.default.openSync(directory, "r");
151933
+ const descriptor = import_node_fs37.default.openSync(directory, "r");
151925
151934
  try {
151926
- import_node_fs36.default.fsyncSync(descriptor);
151935
+ import_node_fs37.default.fsyncSync(descriptor);
151927
151936
  } finally {
151928
- import_node_fs36.default.closeSync(descriptor);
151937
+ import_node_fs37.default.closeSync(descriptor);
151929
151938
  }
151930
151939
  } catch (error5) {
151931
151940
  const code = error5.code;
@@ -152052,7 +152061,7 @@ function fromRow(row) {
152052
152061
 
152053
152062
  // packages/server/src/lib/app-sync-target.ts
152054
152063
  var import_node_crypto42 = __toESM(require("node:crypto"));
152055
- var import_node_fs37 = __toESM(require("node:fs"));
152064
+ var import_node_fs38 = __toESM(require("node:fs"));
152056
152065
  var import_node_path46 = __toESM(require("node:path"));
152057
152066
  var import_sql5 = __toESM(require("sql.js"));
152058
152067
  var AppSyncTarget = class {
@@ -152228,7 +152237,7 @@ var AppSyncTarget = class {
152228
152237
  await this.restoreBackup(input.pageDir, input.safetyBackupId, {
152229
152238
  application: pageIdentity(input.previousMeta, input.ownerId, input.appName)
152230
152239
  });
152231
- if (!input.previousDatabaseExisted) import_node_fs37.default.rmSync(import_node_path46.default.join(input.pageDir, "app.db"), { force: true });
152240
+ if (!input.previousDatabaseExisted) import_node_fs38.default.rmSync(import_node_path46.default.join(input.pageDir, "app.db"), { force: true });
152232
152241
  } else if (!input.previousMeta) {
152233
152242
  if (input.safetyBackupId) {
152234
152243
  await this.restoreBackup(input.pageDir, input.safetyBackupId, {
@@ -152255,7 +152264,7 @@ var AppSyncTarget = class {
152255
152264
  const SQL = await (0, import_sql5.default)();
152256
152265
  const database = new SQL.Database();
152257
152266
  try {
152258
- import_node_fs37.default.writeFileSync(databasePath, Buffer.from(database.export()), { mode: 384 });
152267
+ import_node_fs38.default.writeFileSync(databasePath, Buffer.from(database.export()), { mode: 384 });
152259
152268
  } finally {
152260
152269
  database.close();
152261
152270
  }
@@ -152267,7 +152276,7 @@ var AppSyncTarget = class {
152267
152276
  reason: "peer-data-sync"
152268
152277
  });
152269
152278
  } finally {
152270
- if (!databaseExisted) import_node_fs37.default.rmSync(databasePath, { force: true });
152279
+ if (!databaseExisted) import_node_fs38.default.rmSync(databasePath, { force: true });
152271
152280
  }
152272
152281
  }
152273
152282
  };
@@ -152300,21 +152309,21 @@ function pageIdentity(meta, owner, name) {
152300
152309
  return { owner, name, version: meta.currentVersion };
152301
152310
  }
152302
152311
  function fsExists(filePath) {
152303
- return import_node_fs37.default.existsSync(filePath);
152312
+ return import_node_fs38.default.existsSync(filePath);
152304
152313
  }
152305
152314
  function fsStatSize(filePath) {
152306
- return import_node_fs37.default.statSync(filePath).size;
152315
+ return import_node_fs38.default.statSync(filePath).size;
152307
152316
  }
152308
152317
  async function sha256File4(filePath) {
152309
152318
  const hash2 = import_node_crypto42.default.createHash("sha256");
152310
- for await (const chunk of import_node_fs37.default.createReadStream(filePath)) hash2.update(chunk);
152319
+ for await (const chunk of import_node_fs38.default.createReadStream(filePath)) hash2.update(chunk);
152311
152320
  return hash2.digest("hex");
152312
152321
  }
152313
152322
 
152314
152323
  // packages/server/src/lib/app-sync-source.ts
152315
152324
  var import_node_events3 = require("node:events");
152316
152325
  var import_node_crypto43 = __toESM(require("node:crypto"));
152317
- var import_node_fs38 = __toESM(require("node:fs"));
152326
+ var import_node_fs39 = __toESM(require("node:fs"));
152318
152327
  var import_node_path47 = __toESM(require("node:path"));
152319
152328
  var import_node_crypto44 = require("node:crypto");
152320
152329
  var TERMINAL3 = /* @__PURE__ */ new Set(["completed", "rolled-back", "failed", "recovery-required"]);
@@ -152406,7 +152415,7 @@ var AppSyncSource = class {
152406
152415
  archiveApplication: { owner: target.verifiedUserId, name: input.appName, version: active.localVersion }
152407
152416
  });
152408
152417
  dataDigest = await sha256File5(dataExport.archivePath);
152409
- dataSize = import_node_fs38.default.statSync(dataExport.archivePath).size;
152418
+ dataSize = import_node_fs39.default.statSync(dataExport.archivePath).size;
152410
152419
  this.jobs.setData(job.id, { dataDigest, dataSize });
152411
152420
  }
152412
152421
  const response = await peerFetch(`${target.baseUrl}/api/peer/sync-sessions`, target.apiKey, {
@@ -152491,7 +152500,7 @@ var AppSyncSource = class {
152491
152500
  upload = await peerFetch(`${baseUrl}/api/peer/sync-sessions/${encodeURIComponent(job.syncId)}/package`, apiKey, {
152492
152501
  method: "PUT",
152493
152502
  headers: { "Content-Type": "application/octet-stream", "Content-Length": String(job.packageSize) },
152494
- body: import_node_fs38.default.createReadStream(packagePath),
152503
+ body: import_node_fs39.default.createReadStream(packagePath),
152495
152504
  signal: uploadDeadline.signal,
152496
152505
  duplex: "half"
152497
152506
  });
@@ -152511,7 +152520,7 @@ var AppSyncSource = class {
152511
152520
  dataUpload = await peerFetch(`${baseUrl}/api/peer/sync-sessions/${encodeURIComponent(current.syncId)}/data`, apiKey, {
152512
152521
  method: "PUT",
152513
152522
  headers: { "Content-Type": "application/octet-stream", "Content-Length": String(current.dataSize) },
152514
- body: import_node_fs38.default.createReadStream(dataPath),
152523
+ body: import_node_fs39.default.createReadStream(dataPath),
152515
152524
  signal: dataDeadline.signal,
152516
152525
  duplex: "half"
152517
152526
  });
@@ -152617,14 +152626,14 @@ async function activePackage(dataDir2, ownerId, appName) {
152617
152626
  const pageDir = import_node_path47.default.resolve(getPageDir(dataDir2, ownerId, appName));
152618
152627
  const packageRoot = import_node_path47.default.join(pageDir, ".packages");
152619
152628
  const packagePath = import_node_path47.default.resolve(pageDir, active.packagePath);
152620
- if (import_node_path47.default.dirname(packagePath) !== packageRoot || !import_node_fs38.default.existsSync(packagePath)) {
152629
+ if (import_node_path47.default.dirname(packagePath) !== packageRoot || !import_node_fs39.default.existsSync(packagePath)) {
152621
152630
  throw new SyncSourceError(409, "Active application package is unavailable", "APP_PACKAGE_NOT_RETAINED");
152622
152631
  }
152623
152632
  const inspected = await inspectAppPackage(packagePath);
152624
152633
  if (inspected.name !== appName || inspected.version !== active.appVersion || inspected.digest !== active.digest) {
152625
152634
  throw new SyncSourceError(409, "Retained application package does not match active metadata", "APP_PACKAGE_MISMATCH");
152626
152635
  }
152627
- return { path: packagePath, appVersion: active.appVersion, localVersion: active.version, digest: active.digest, size: import_node_fs38.default.statSync(packagePath).size };
152636
+ return { path: packagePath, appVersion: active.appVersion, localVersion: active.version, digest: active.digest, size: import_node_fs39.default.statSync(packagePath).size };
152628
152637
  }
152629
152638
  async function peerFetch(url, apiKey, init) {
152630
152639
  return fetch(url, {
@@ -152640,7 +152649,7 @@ async function sourceResponseError(response) {
152640
152649
  }
152641
152650
  async function sha256File5(filePath) {
152642
152651
  const hash2 = import_node_crypto43.default.createHash("sha256");
152643
- for await (const chunk of import_node_fs38.default.createReadStream(filePath)) hash2.update(chunk);
152652
+ for await (const chunk of import_node_fs39.default.createReadStream(filePath)) hash2.update(chunk);
152644
152653
  return hash2.digest("hex");
152645
152654
  }
152646
152655
  function createDeadlineSignal(parent, timeoutMs) {