@narumitw/pi-sync 0.54.2 → 0.56.0

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 (194) hide show
  1. package/README.md +40 -15
  2. package/dist/chunks/agent-candidate-3JN6DJKT.ts +26 -0
  3. package/dist/chunks/agent-plan-QCUJWBP4.ts +99 -0
  4. package/dist/chunks/agent-plan-QCUJWBP4.ts.map +7 -0
  5. package/dist/chunks/agent-runner-E2JU2VZ6.ts +182 -0
  6. package/dist/chunks/agent-runner-E2JU2VZ6.ts.map +7 -0
  7. package/dist/chunks/agent-store-A3F6IYWZ.ts +152 -0
  8. package/dist/chunks/agent-store-A3F6IYWZ.ts.map +7 -0
  9. package/dist/chunks/chunk-5Q5SSKNG.ts +128 -0
  10. package/dist/chunks/chunk-5Q5SSKNG.ts.map +7 -0
  11. package/dist/chunks/chunk-5XZOC7FD.ts +215 -0
  12. package/dist/chunks/chunk-5XZOC7FD.ts.map +7 -0
  13. package/dist/chunks/{chunk-IJ6VV6FN.ts → chunk-AAEEHR7H.ts} +31 -87
  14. package/dist/chunks/chunk-AAEEHR7H.ts.map +7 -0
  15. package/dist/chunks/{chunk-CHSIAC4N.ts → chunk-B4QZBDBT.ts} +2 -2
  16. package/dist/chunks/{chunk-CL7BZRRQ.ts → chunk-CRKTAPSL.ts} +8 -8
  17. package/dist/chunks/chunk-DT7M4VQS.ts +69 -0
  18. package/dist/chunks/chunk-DT7M4VQS.ts.map +7 -0
  19. package/dist/chunks/chunk-ED3TYIVW.ts +229 -0
  20. package/dist/chunks/chunk-ED3TYIVW.ts.map +7 -0
  21. package/dist/chunks/{chunk-VHXBCEVF.ts → chunk-EUMINX7L.ts} +6 -6
  22. package/dist/chunks/chunk-FQOSHGJ7.ts +215 -0
  23. package/dist/chunks/chunk-FQOSHGJ7.ts.map +7 -0
  24. package/dist/chunks/chunk-GNH73BJ5.ts +153 -0
  25. package/dist/chunks/chunk-GNH73BJ5.ts.map +7 -0
  26. package/dist/chunks/{chunk-UQ3ALBIB.ts → chunk-GP5DU62N.ts} +8 -9
  27. package/dist/chunks/chunk-GP5DU62N.ts.map +7 -0
  28. package/dist/chunks/{chunk-5RZPINUQ.ts → chunk-GSNPASKB.ts} +2 -2
  29. package/dist/chunks/{chunk-QE7NZZWT.ts → chunk-IWZH5KYS.ts} +23 -7
  30. package/dist/chunks/chunk-IWZH5KYS.ts.map +7 -0
  31. package/dist/chunks/{chunk-5ZWQ33XL.ts → chunk-JJTARUSO.ts} +15 -14
  32. package/dist/chunks/chunk-JJTARUSO.ts.map +7 -0
  33. package/dist/chunks/{chunk-2DI6PDZV.ts → chunk-NLWS55B6.ts} +15 -2
  34. package/dist/chunks/chunk-NLWS55B6.ts.map +7 -0
  35. package/dist/chunks/{chunk-SDZCTCYQ.ts → chunk-OEWQVWLC.ts} +4 -4
  36. package/dist/chunks/{chunk-MYPSMJHJ.ts → chunk-OTZRCKYP.ts} +380 -510
  37. package/dist/chunks/chunk-OTZRCKYP.ts.map +7 -0
  38. package/dist/chunks/{chunk-WFKUKVCP.ts → chunk-OWBAZA6J.ts} +24 -12
  39. package/dist/chunks/chunk-OWBAZA6J.ts.map +7 -0
  40. package/dist/chunks/chunk-PRUEIIK7.ts +24 -0
  41. package/dist/chunks/chunk-PRUEIIK7.ts.map +7 -0
  42. package/dist/chunks/chunk-QGK445K7.ts +21 -0
  43. package/dist/chunks/chunk-QGK445K7.ts.map +7 -0
  44. package/dist/chunks/{chunk-3B4Z2SKV.ts → chunk-QO333NM4.ts} +49 -21
  45. package/dist/chunks/chunk-QO333NM4.ts.map +7 -0
  46. package/dist/chunks/{chunk-4SBTAVFL.ts → chunk-QSHMOL3I.ts} +22 -24
  47. package/dist/chunks/chunk-QSHMOL3I.ts.map +7 -0
  48. package/dist/chunks/chunk-S2FMH5FT.ts +97 -0
  49. package/dist/chunks/chunk-S2FMH5FT.ts.map +7 -0
  50. package/dist/chunks/{chunk-BVVP33U5.ts → chunk-SWRVXVFD.ts} +12 -9
  51. package/dist/chunks/chunk-SWRVXVFD.ts.map +7 -0
  52. package/dist/chunks/{chunk-ZX2Q6THB.ts → chunk-UBV24CG4.ts} +4 -5
  53. package/dist/chunks/chunk-UBV24CG4.ts.map +7 -0
  54. package/dist/chunks/chunk-UOHR7LRO.ts +70 -0
  55. package/dist/chunks/chunk-UOHR7LRO.ts.map +7 -0
  56. package/dist/chunks/{chunk-4QVPTIZB.ts → chunk-UPNVIUBN.ts} +3 -3
  57. package/dist/chunks/chunk-UZPMDLTL.ts +54 -0
  58. package/dist/chunks/chunk-UZPMDLTL.ts.map +7 -0
  59. package/dist/chunks/chunk-VJN7KU4J.ts +350 -0
  60. package/dist/chunks/chunk-VJN7KU4J.ts.map +7 -0
  61. package/dist/chunks/chunk-YHT4YTYG.ts +31 -0
  62. package/dist/chunks/chunk-YHT4YTYG.ts.map +7 -0
  63. package/dist/chunks/{chunk-V6VZ5TLG.ts → chunk-YK52VDXG.ts} +6 -5
  64. package/dist/chunks/chunk-YK52VDXG.ts.map +7 -0
  65. package/dist/chunks/config-KGIYTTXQ.ts +37 -0
  66. package/dist/chunks/{conflict-artifacts-BB2FZMIE.ts → conflict-artifacts-FXFIIBCB.ts} +8 -7
  67. package/dist/chunks/{conflict-review-4PLVLMRO.ts → conflict-review-6WIEQLXW.ts} +31 -24
  68. package/dist/chunks/{conflict-review-4PLVLMRO.ts.map → conflict-review-6WIEQLXW.ts.map} +1 -1
  69. package/dist/chunks/continuous-record-LFRVXQBD.ts +30 -0
  70. package/dist/chunks/continuous-sync-AWAAOXK2.ts +545 -0
  71. package/dist/chunks/continuous-sync-AWAAOXK2.ts.map +7 -0
  72. package/dist/chunks/{file-selection-WZX7HAY2.ts → file-selection-3JJYOVNR.ts} +5 -5
  73. package/dist/chunks/{git-backend-FD7AVSK6.ts → git-backend-KYDZ673X.ts} +28 -32
  74. package/dist/chunks/git-backend-KYDZ673X.ts.map +7 -0
  75. package/dist/chunks/{manager-result-dispatcher-6MQKFCWB.ts → manager-result-dispatcher-AGBBVDDS.ts} +10 -9
  76. package/dist/chunks/{manager-ui-IURS4WXY.ts → manager-ui-KRAW3NE2.ts} +464 -164
  77. package/dist/chunks/manager-ui-KRAW3NE2.ts.map +7 -0
  78. package/dist/chunks/{merge-baseline-store-EVQAAML6.ts → merge-baseline-store-RFCAH7KL.ts} +7 -5
  79. package/dist/chunks/{remote-selection-ui-6LJJ4IMQ.ts → remote-selection-ui-5725JDNC.ts} +9 -8
  80. package/dist/chunks/remote-selection-ui-5725JDNC.ts.map +7 -0
  81. package/dist/chunks/{s3-backend-AQGV6LFT.ts → s3-backend-Y7WSCLJI.ts} +38 -38
  82. package/dist/chunks/s3-backend-Y7WSCLJI.ts.map +7 -0
  83. package/dist/chunks/{setup-switch-KTUWL6DE.ts → setup-switch-E7PHKI6J.ts} +7 -6
  84. package/dist/chunks/setup-switch-E7PHKI6J.ts.map +7 -0
  85. package/dist/chunks/{setup-wizard-GSDPDFC4.ts → setup-wizard-65DROCIJ.ts} +14 -13
  86. package/dist/chunks/setup-wizard-65DROCIJ.ts.map +7 -0
  87. package/dist/chunks/{sync-inspection-K45QVLHB.ts → sync-inspection-XFJOAMJD.ts} +9 -8
  88. package/dist/chunks/sync-inspection-XFJOAMJD.ts.map +7 -0
  89. package/dist/chunks/{sync-operations-47OUX76C.ts → sync-operations-HDUDT5PD.ts} +188 -73
  90. package/dist/chunks/sync-operations-HDUDT5PD.ts.map +7 -0
  91. package/dist/chunks/{webdav-backend-TBILVEQK.ts → webdav-backend-6K26F6LT.ts} +39 -48
  92. package/dist/chunks/webdav-backend-6K26F6LT.ts.map +7 -0
  93. package/dist/index.ts +246 -131
  94. package/dist/index.ts.map +3 -3
  95. package/docs/agent-mode-verification.md +99 -0
  96. package/docs/continuous-sync-verification.md +87 -0
  97. package/docs/settings.md +131 -11
  98. package/docs/tui-contract.md +61 -0
  99. package/package.json +3 -2
  100. package/src/backends/git/git-backend.ts +1 -4
  101. package/src/backends/git/git-runner.ts +1 -5
  102. package/src/backends/s3/s3-backend.ts +3 -25
  103. package/src/backends/s3/s3-client.ts +14 -2
  104. package/src/backends/snapshot-pointer.ts +27 -0
  105. package/src/backends/webdav/webdav-backend.ts +3 -29
  106. package/src/backends/webdav/webdav-client.ts +11 -7
  107. package/src/commands/command-execution.ts +7 -3
  108. package/src/commands/command-handler.ts +15 -3
  109. package/src/commands/command-types.ts +10 -0
  110. package/src/commands/command.ts +4 -1
  111. package/src/settings/config.ts +20 -10
  112. package/src/settings/settings-store.ts +1 -34
  113. package/src/settings/settings-types.ts +10 -0
  114. package/src/settings/settings-validation.ts +4 -1
  115. package/src/snapshot/snapshot-codec.ts +1 -5
  116. package/src/state/lock.ts +13 -10
  117. package/src/state/merge-baseline-store.ts +19 -1
  118. package/src/state/state-directory.ts +8 -1
  119. package/src/sync/agent-candidate.ts +251 -0
  120. package/src/sync/agent-plan.ts +87 -0
  121. package/src/sync/agent-policy.ts +13 -0
  122. package/src/sync/agent-request.ts +17 -0
  123. package/src/sync/agent-runner.ts +188 -0
  124. package/src/sync/agent-store.ts +151 -0
  125. package/src/sync/agent-sync.ts +91 -0
  126. package/src/sync/apply-review.ts +63 -0
  127. package/src/sync/automatic-sync.ts +46 -33
  128. package/src/sync/continuous-errors.ts +85 -0
  129. package/src/sync/continuous-lease.ts +221 -0
  130. package/src/sync/continuous-record.ts +179 -0
  131. package/src/sync/continuous-storage.ts +55 -0
  132. package/src/sync/continuous-sync.ts +516 -0
  133. package/src/sync/continuous-watch.ts +59 -0
  134. package/src/sync/merged-sync.ts +268 -112
  135. package/src/sync/remote-snapshot.ts +2 -3
  136. package/src/sync/settings-merge.ts +19 -3
  137. package/src/sync/setup-switch.ts +1 -5
  138. package/src/sync/startup-check.ts +51 -29
  139. package/src/sync/startup-timings.ts +90 -0
  140. package/src/sync/sync-inspection.ts +16 -5
  141. package/src/sync/sync-mutations.ts +55 -28
  142. package/src/sync/sync-queries.ts +19 -3
  143. package/src/sync/text-merge.ts +3 -3
  144. package/src/sync-extension.ts +75 -19
  145. package/src/ui/agent-mode-setting.ts +91 -0
  146. package/src/ui/manager-state.ts +12 -6
  147. package/src/ui/manager-ui.ts +57 -7
  148. package/src/ui/merge-review.ts +3 -3
  149. package/src/ui/merged-sync-summary.ts +2 -18
  150. package/src/ui/remote-selection-ui.ts +5 -5
  151. package/src/ui/settings-frame.ts +55 -0
  152. package/src/ui/settings-ui.ts +223 -43
  153. package/src/ui/setup/s3-credentials-ui.ts +1 -5
  154. package/src/ui/setup/setup-name-ui.ts +2 -5
  155. package/src/ui/setup/setup-prompts.ts +4 -3
  156. package/src/ui/setup/setup-switcher.ts +2 -0
  157. package/src/ui/sync-behavior.ts +15 -0
  158. package/src/ui/sync-format.ts +69 -38
  159. package/src/ui/sync-setups-ui.ts +3 -5
  160. package/src/ui/transfer-changes.ts +33 -0
  161. package/src/ui/transfer-review.ts +27 -0
  162. package/dist/chunks/chunk-2DI6PDZV.ts.map +0 -7
  163. package/dist/chunks/chunk-3B4Z2SKV.ts.map +0 -7
  164. package/dist/chunks/chunk-4SBTAVFL.ts.map +0 -7
  165. package/dist/chunks/chunk-5ZWQ33XL.ts.map +0 -7
  166. package/dist/chunks/chunk-BVVP33U5.ts.map +0 -7
  167. package/dist/chunks/chunk-IJ6VV6FN.ts.map +0 -7
  168. package/dist/chunks/chunk-MYPSMJHJ.ts.map +0 -7
  169. package/dist/chunks/chunk-ORQRHEEO.ts +0 -362
  170. package/dist/chunks/chunk-ORQRHEEO.ts.map +0 -7
  171. package/dist/chunks/chunk-QE7NZZWT.ts.map +0 -7
  172. package/dist/chunks/chunk-UQ3ALBIB.ts.map +0 -7
  173. package/dist/chunks/chunk-V6VZ5TLG.ts.map +0 -7
  174. package/dist/chunks/chunk-WFKUKVCP.ts.map +0 -7
  175. package/dist/chunks/chunk-ZX2Q6THB.ts.map +0 -7
  176. package/dist/chunks/git-backend-FD7AVSK6.ts.map +0 -7
  177. package/dist/chunks/manager-ui-IURS4WXY.ts.map +0 -7
  178. package/dist/chunks/s3-backend-AQGV6LFT.ts.map +0 -7
  179. package/dist/chunks/setup-wizard-GSDPDFC4.ts.map +0 -7
  180. package/dist/chunks/sync-operations-47OUX76C.ts.map +0 -7
  181. package/dist/chunks/webdav-backend-TBILVEQK.ts.map +0 -7
  182. /package/dist/chunks/{conflict-artifacts-BB2FZMIE.ts.map → agent-candidate-3JN6DJKT.ts.map} +0 -0
  183. /package/dist/chunks/{chunk-CHSIAC4N.ts.map → chunk-B4QZBDBT.ts.map} +0 -0
  184. /package/dist/chunks/{chunk-CL7BZRRQ.ts.map → chunk-CRKTAPSL.ts.map} +0 -0
  185. /package/dist/chunks/{chunk-VHXBCEVF.ts.map → chunk-EUMINX7L.ts.map} +0 -0
  186. /package/dist/chunks/{chunk-5RZPINUQ.ts.map → chunk-GSNPASKB.ts.map} +0 -0
  187. /package/dist/chunks/{chunk-SDZCTCYQ.ts.map → chunk-OEWQVWLC.ts.map} +0 -0
  188. /package/dist/chunks/{chunk-4QVPTIZB.ts.map → chunk-UPNVIUBN.ts.map} +0 -0
  189. /package/dist/chunks/{manager-result-dispatcher-6MQKFCWB.ts.map → config-KGIYTTXQ.ts.map} +0 -0
  190. /package/dist/chunks/{merge-baseline-store-EVQAAML6.ts.map → conflict-artifacts-FXFIIBCB.ts.map} +0 -0
  191. /package/dist/chunks/{remote-selection-ui-6LJJ4IMQ.ts.map → continuous-record-LFRVXQBD.ts.map} +0 -0
  192. /package/dist/chunks/{file-selection-WZX7HAY2.ts.map → file-selection-3JJYOVNR.ts.map} +0 -0
  193. /package/dist/chunks/{setup-switch-KTUWL6DE.ts.map → manager-result-dispatcher-AGBBVDDS.ts.map} +0 -0
  194. /package/dist/chunks/{sync-inspection-K45QVLHB.ts.map → merge-baseline-store-RFCAH7KL.ts.map} +0 -0
@@ -1,13 +1,13 @@
1
1
  // @generated by scripts/build-runtime.mjs; do not edit.
2
2
  // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
3
3
  import {
4
- SyncBackendConflictError,
5
- SyncBackendPublicationOutcomeUnknownError
6
- } from "./chunk-YDVQYUHE.ts";
4
+ createLatestPointer,
5
+ remoteHistoryEntry
6
+ } from "./chunk-YHT4YTYG.ts";
7
7
  import {
8
8
  decodeSnapshot,
9
9
  encodeSnapshot
10
- } from "./chunk-ZX2Q6THB.ts";
10
+ } from "./chunk-UBV24CG4.ts";
11
11
  import {
12
12
  syncErrorGuidance
13
13
  } from "./chunk-G4RUXRWZ.ts";
@@ -15,6 +15,18 @@ import "./chunk-7D5SF7P3.ts";
15
15
  import {
16
16
  validatePortableSnapshot
17
17
  } from "./chunk-A6HU4ERM.ts";
18
+ import {
19
+ throwIfAborted
20
+ } from "./chunk-PWMWOJP4.ts";
21
+ import {
22
+ ContinuousError,
23
+ continuousFailure,
24
+ retryAfter
25
+ } from "./chunk-DT7M4VQS.ts";
26
+ import {
27
+ SyncBackendConflictError,
28
+ SyncBackendPublicationOutcomeUnknownError
29
+ } from "./chunk-YDVQYUHE.ts";
18
30
  import {
19
31
  portableSnapshotSelection
20
32
  } from "./chunk-QOFMXPM5.ts";
@@ -33,12 +45,14 @@ var XML_LIMIT = 1024 * 1024;
33
45
  var REQUEST_TIMEOUT_MS = 3e4;
34
46
  var MAX_REDIRECTS = 3;
35
47
  var WebDavHttpError = class extends Error {
36
- constructor(message, status, options) {
48
+ constructor(message, status, options, retryAfterMs) {
37
49
  super(message, options);
38
50
  this.status = status;
51
+ this.retryAfterMs = retryAfterMs;
39
52
  this.name = "WebDavHttpError";
40
53
  }
41
54
  status;
55
+ retryAfterMs;
42
56
  };
43
57
  var WebDavPreconditionError = class extends WebDavHttpError {
44
58
  constructor(message = "WebDAV precondition failed.") {
@@ -219,7 +233,12 @@ var WebDavClient = class {
219
233
  if (response.ok) return;
220
234
  const body = (await readBounded(response, ERROR_LIMIT, "WebDAV error body is too large")).toString("utf8").replace(/[\u0000-\u001f\u007f-\u009f]/gu, " ").trim();
221
235
  const detail = body ? `: ${redactText(body, this.config)}` : "";
222
- throw new WebDavHttpError(`WebDAV ${action} failed with HTTP ${response.status}${detail}`, response.status);
236
+ throw new WebDavHttpError(
237
+ `WebDAV ${action} failed with HTTP ${response.status}${detail}`,
238
+ response.status,
239
+ void 0,
240
+ retryAfter(response)
241
+ );
223
242
  }
224
243
  };
225
244
  function assertSafeAuthenticatedUrl(url) {
@@ -304,7 +323,8 @@ function safeUrl(url) {
304
323
  }
305
324
  function redactError(error, config) {
306
325
  const message = error instanceof Error ? error.message : String(error);
307
- return new Error(redactText(message, config));
326
+ const failure = continuousFailure(error);
327
+ return new ContinuousError(failure.kind, redactText(message, config), failure.delay);
308
328
  }
309
329
  function redactText(value, config) {
310
330
  let result = value;
@@ -319,10 +339,6 @@ function redactText(value, config) {
319
339
  function escapeRegExp(value) {
320
340
  return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
321
341
  }
322
- function throwIfAborted(signal) {
323
- if (!signal?.aborted) return;
324
- throw signal.reason instanceof Error ? signal.reason : new DOMException("The operation was aborted", "AbortError");
325
- }
326
342
 
327
343
  // src/backends/webdav/webdav-backend.ts
328
344
  var VERSION = 1;
@@ -350,7 +366,7 @@ var WebDavSyncBackend = class {
350
366
  }
351
367
  async readHead(signal) {
352
368
  const object = await new WebDavClient(this.config, signal).getJson(latestPath(this.config));
353
- throwIfAborted2(signal);
369
+ throwIfAborted(signal);
354
370
  if (object.missing) return void 0;
355
371
  const pointer = requirePointer(object.value, this.config.destination.namespace);
356
372
  this.registerChecksum(pointer.snapshot, pointer.sha256);
@@ -360,7 +376,7 @@ var WebDavSyncBackend = class {
360
376
  requireSnapshotReference(reference);
361
377
  const expectedChecksum = this.checksums.get(reference) ?? await this.resolveChecksum(reference, signal);
362
378
  const object = await new WebDavClient(this.config, signal).getBuffer(snapshotPath(this.config, reference));
363
- throwIfAborted2(signal);
379
+ throwIfAborted(signal);
364
380
  if (!object.value) throw new Error(`Snapshot not found: ${reference}`);
365
381
  if (!expectedChecksum || sha256(object.value) !== expectedChecksum) {
366
382
  throw new Error("Remote snapshot checksum mismatch.");
@@ -373,15 +389,15 @@ var WebDavSyncBackend = class {
373
389
  return snapshot;
374
390
  }
375
391
  async publishSnapshot(snapshot, expected, options = {}) {
376
- throwIfAborted2(options.signal);
392
+ throwIfAborted(options.signal);
377
393
  assertSnapshotIdentity(snapshot, this.config.destination.namespace);
378
394
  await this.ensureAtomicConditions(options.signal);
379
- throwIfAborted2(options.signal);
395
+ throwIfAborted(options.signal);
380
396
  const client = new WebDavClient(this.config, options.signal);
381
397
  await client.ensureCollection(snapshotsPath(this.config));
382
398
  const encoded = await encodeSnapshot(snapshot);
383
- throwIfAborted2(options.signal);
384
- const pointer = pointerFor(this.config, snapshot, sha256(encoded));
399
+ throwIfAborted(options.signal);
400
+ const pointer = createLatestPointer(this.config.destination.namespace, snapshot, sha256(encoded));
385
401
  const stagedPath = snapshotPath(this.config, snapshot.id);
386
402
  try {
387
403
  await client.putBuffer(stagedPath, encoded, "application/gzip", { ifAbsent: true });
@@ -395,7 +411,7 @@ var WebDavSyncBackend = class {
395
411
  }
396
412
  }
397
413
  const currentObject = await client.getJson(latestPath(this.config));
398
- throwIfAborted2(options.signal);
414
+ throwIfAborted(options.signal);
399
415
  const current = currentObject.missing ? void 0 : remoteHead(
400
416
  requirePointer(currentObject.value, this.config.destination.namespace),
401
417
  this.identity,
@@ -407,7 +423,7 @@ var WebDavSyncBackend = class {
407
423
  });
408
424
  }
409
425
  const condition = publicationCondition(currentObject, expected, this.identity);
410
- throwIfAborted2(options.signal);
426
+ throwIfAborted(options.signal);
411
427
  options.onCommit?.();
412
428
  const commitClient = new WebDavClient(
413
429
  this.config,
@@ -468,7 +484,7 @@ var WebDavSyncBackend = class {
468
484
  }
469
485
  async listHistory(signal) {
470
486
  const object = await new WebDavClient(this.config, signal).getJson(historyPath(this.config));
471
- throwIfAborted2(signal);
487
+ throwIfAborted(signal);
472
488
  if (object.missing) return [];
473
489
  const pointers = requireHistory(object.value, this.config.destination.namespace);
474
490
  for (const pointer of pointers) this.registerChecksum(pointer.snapshot, pointer.sha256);
@@ -535,7 +551,7 @@ var WebDavSyncBackend = class {
535
551
  return check;
536
552
  }
537
553
  async runCapabilityProbe(signal) {
538
- throwIfAborted2(signal);
554
+ throwIfAborted(signal);
539
555
  const probeCollection = joinRemote(rootPath(this.config), ".pi-sync-probes", randomUUID());
540
556
  const probe = `${probeCollection}/conditional.txt`;
541
557
  const client = new WebDavClient(this.config, signal);
@@ -609,7 +625,7 @@ var WebDavSyncBackend = class {
609
625
  async reconcileActiveHistory(signal) {
610
626
  const client = new WebDavClient(this.config, signal);
611
627
  const object = await client.getJson(latestPath(this.config));
612
- throwIfAborted2(signal);
628
+ throwIfAborted(signal);
613
629
  if (object.missing) return "webdav history: no active snapshot";
614
630
  const pointer = requirePointer(object.value, this.config.destination.namespace);
615
631
  this.registerChecksum(pointer.snapshot, pointer.sha256);
@@ -663,18 +679,6 @@ function webDavStorageLocation(config) {
663
679
  const url = new URL(secretFreeUrl(config.profile.url));
664
680
  return `${url.host} \xB7 ${config.destination.path}`;
665
681
  }
666
- function pointerFor(config, snapshot, checksum) {
667
- return {
668
- version: VERSION,
669
- profile: config.destination.namespace,
670
- snapshot: snapshot.id,
671
- sha256: checksum,
672
- createdAt: snapshot.createdAt,
673
- machine: snapshot.machine,
674
- syncSessions: snapshot.syncSessions === true || snapshot.files.some((file) => file.path.startsWith("sessions/")),
675
- ...snapshot.selection === void 0 ? {} : { selection: snapshot.selection }
676
- };
677
- }
678
682
  function remoteHead(pointer, identity, etag) {
679
683
  return {
680
684
  snapshotRef: pointer.snapshot,
@@ -739,15 +743,6 @@ function requireHistory(value, expectedProfile) {
739
743
  }
740
744
  return pointers;
741
745
  }
742
- function remoteHistoryEntry(pointer) {
743
- return {
744
- snapshotRef: pointer.snapshot,
745
- snapshotId: pointer.snapshot,
746
- createdAt: pointer.createdAt,
747
- machine: pointer.machine,
748
- syncSessions: pointer.syncSessions === true
749
- };
750
- }
751
746
  function assertSnapshotIdentity(snapshot, namespace) {
752
747
  validatePortableSnapshot(snapshot);
753
748
  if (snapshot.profile !== namespace || !isSafeReference(snapshot.id) || !isSafeMetadata(snapshot.createdAt, 64) || !isSafeMetadata(snapshot.machine, 256) || !Array.isArray(snapshot.files)) {
@@ -837,10 +832,6 @@ function secretFreeUrl(value) {
837
832
  function sha256(value) {
838
833
  return createHash("sha256").update(value).digest("hex");
839
834
  }
840
- function throwIfAborted2(signal) {
841
- if (!signal?.aborted) return;
842
- throw signal.reason instanceof Error ? signal.reason : new DOMException("The operation was aborted", "AbortError");
843
- }
844
835
  function errorMessage(error) {
845
836
  if (error instanceof WebDavHttpError) return error.message;
846
837
  return error instanceof Error ? error.message : String(error);
@@ -854,4 +845,4 @@ export {
854
845
  snapshotsPath,
855
846
  webDavBackendIdentity
856
847
  };
857
- //# sourceMappingURL=webdav-backend-TBILVEQK.ts.map
848
+ //# sourceMappingURL=webdav-backend-6K26F6LT.ts.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/backends/webdav/webdav-backend.ts", "../../src/backends/webdav/webdav-client.ts"],
4
+ "sourcesContent": ["import { createHash, randomUUID } from \"node:crypto\";\nimport { decodeSnapshot, encodeSnapshot } from \"../../snapshot/snapshot-codec.js\";\nimport type { Snapshot } from \"../../snapshot/snapshot-types.js\";\nimport { validatePortableSnapshot } from \"../../sync/local-fields.js\";\nimport { throwIfAborted } from \"../../sync/signals.js\";\nimport { syncErrorGuidance } from \"../../sync/sync-error-guidance.js\";\nimport { portableSnapshotSelection } from \"../../sync/sync-policy.js\";\nimport type { LatestPointer, RemoteObject, ResolvedWebDavBackend } from \"../backend-types.js\";\nimport { createLatestPointer, remoteHistoryEntry } from \"../snapshot-pointer.js\";\nimport {\n type BackendDiagnostic,\n type ExpectedRemoteHead,\n type PublishSnapshotOptions,\n type PublishSnapshotResult,\n type RemoteHead,\n type RemoteHistoryEntry,\n type SyncBackend,\n SyncBackendConflictError,\n SyncBackendPublicationOutcomeUnknownError,\n} from \"../sync-backend.js\";\nimport { WebDavClient, WebDavHttpError, WebDavPreconditionError } from \"./webdav-client.js\";\n\nconst VERSION = 1;\nconst POST_COMMIT_TIMEOUT_MS = 30_000;\n\nexport class WebDavSyncBackend implements SyncBackend {\n readonly identity: string;\n readonly destination: string;\n private conditionalVerified = false;\n private readonly checksums = new Map<string, string>();\n private capabilityCheck?: Promise<void>;\n\n constructor(\n private readonly config: ResolvedWebDavBackend,\n private readonly postCommitTimeoutMs = POST_COMMIT_TIMEOUT_MS,\n ) {\n assertSafeDestination(config);\n this.identity = webDavBackendIdentity(config);\n this.destination = webDavStorageLocation(config);\n }\n\n get capability() {\n return this.conditionalVerified ? (\"atomic-conditional\" as const) : (\"conditional-required\" as const);\n }\n\n sameRevision(left: string, right: string) {\n return left === right;\n }\n\n async readHead(signal?: AbortSignal): Promise<RemoteHead | undefined> {\n const object = await new WebDavClient(this.config, signal).getJson<LatestPointer>(latestPath(this.config));\n throwIfAborted(signal);\n if (object.missing) return undefined;\n const pointer = requirePointer(object.value, this.config.destination.namespace);\n this.registerChecksum(pointer.snapshot, pointer.sha256);\n return remoteHead(pointer, this.identity, object.etag);\n }\n\n async readSnapshot(reference: string, signal?: AbortSignal): Promise<Snapshot> {\n requireSnapshotReference(reference);\n const expectedChecksum = this.checksums.get(reference) ?? (await this.resolveChecksum(reference, signal));\n const object = await new WebDavClient(this.config, signal).getBuffer(snapshotPath(this.config, reference));\n throwIfAborted(signal);\n if (!object.value) throw new Error(`Snapshot not found: ${reference}`);\n if (!expectedChecksum || sha256(object.value) !== expectedChecksum) {\n throw new Error(\"Remote snapshot checksum mismatch.\");\n }\n const snapshot = await decodeSnapshot(object.value, { signal });\n if (snapshot.id !== reference || snapshot.profile !== this.config.destination.namespace) {\n throw new Error(\"Remote snapshot identity mismatch.\");\n }\n validateSnapshotBundle(snapshot);\n return snapshot;\n }\n\n async publishSnapshot(\n snapshot: Snapshot,\n expected: ExpectedRemoteHead,\n options: PublishSnapshotOptions = {},\n ): Promise<PublishSnapshotResult> {\n throwIfAborted(options.signal);\n assertSnapshotIdentity(snapshot, this.config.destination.namespace);\n await this.ensureAtomicConditions(options.signal);\n throwIfAborted(options.signal);\n const client = new WebDavClient(this.config, options.signal);\n await client.ensureCollection(snapshotsPath(this.config));\n const encoded = await encodeSnapshot(snapshot);\n throwIfAborted(options.signal);\n const pointer = createLatestPointer(this.config.destination.namespace, snapshot, sha256(encoded));\n const stagedPath = snapshotPath(this.config, snapshot.id);\n try {\n await client.putBuffer(stagedPath, encoded, \"application/gzip\", { ifAbsent: true });\n } catch (error) {\n if (!(error instanceof WebDavPreconditionError)) throw error;\n const existing = await client.getBuffer(stagedPath);\n if (!existing.value || sha256(existing.value) !== pointer.sha256) {\n throw new SyncBackendConflictError(\n `Immutable snapshot id already exists with different content: ${snapshot.id}`,\n );\n }\n }\n const currentObject = await client.getJson<LatestPointer>(latestPath(this.config));\n throwIfAborted(options.signal);\n const current = currentObject.missing\n ? undefined\n : remoteHead(\n requirePointer(currentObject.value, this.config.destination.namespace),\n this.identity,\n currentObject.etag,\n );\n if (!matchesExpected(current, expected)) {\n throw new SyncBackendConflictError(\"Remote changed while pushing. Run /sync pull first, then retry.\", {\n currentHead: current,\n });\n }\n const condition = publicationCondition(currentObject, expected, this.identity);\n throwIfAborted(options.signal);\n options.onCommit?.();\n const commitClient = new WebDavClient(\n this.config,\n AbortSignal.timeout(this.postCommitTimeoutMs),\n this.postCommitTimeoutMs,\n );\n try {\n await commitClient.putJson(latestPath(this.config), pointer, condition);\n } catch (error) {\n if (error instanceof WebDavPreconditionError) {\n const latest = await this.readHeadAfterCommit(commitClient).catch(() => undefined);\n throw new SyncBackendConflictError(\"Remote changed while publishing the WebDAV pointer.\", {\n currentHead: latest,\n });\n }\n throw new SyncBackendPublicationOutcomeUnknownError(\n `Remote publication outcome is unknown: ${errorMessage(error)}`,\n { cause: error },\n );\n }\n let verifiedObject: RemoteObject<LatestPointer>;\n try {\n verifiedObject = await commitClient.getJson<LatestPointer>(latestPath(this.config));\n } catch (error) {\n throw new SyncBackendPublicationOutcomeUnknownError(\n `Remote snapshot may be active, but publication could not be verified: ${errorMessage(error)}`,\n { cause: error },\n );\n }\n let verified: LatestPointer;\n try {\n verified = requirePointer(verifiedObject.value, this.config.destination.namespace);\n } catch (error) {\n throw new SyncBackendPublicationOutcomeUnknownError(\n `Remote snapshot may be active, but publication verification was malformed: ${errorMessage(error)}`,\n { cause: error },\n );\n }\n if (!samePointer(pointer, verified)) {\n throw new SyncBackendConflictError(\n \"Remote latest changed immediately after push. Run /sync status before continuing.\",\n {\n phase: \"after-commit\",\n currentHead: remoteHead(verified, this.identity, verifiedObject.etag),\n candidateMayHaveBeenActive: true,\n },\n );\n }\n if (!strongEtag(verifiedObject.etag)) {\n throw new SyncBackendPublicationOutcomeUnknownError(\n \"Remote snapshot is active, but the WebDAV server returned no strong ETag.\",\n );\n }\n this.registerChecksum(verified.snapshot, verified.sha256);\n const head = remoteHead(verified, this.identity, verifiedObject.etag);\n const warning = await this.updateHistorySafely(commitClient, pointer);\n return { head, warnings: warning ? [warning] : [] };\n }\n\n async listHistory(signal?: AbortSignal): Promise<RemoteHistoryEntry[]> {\n const object = await new WebDavClient(this.config, signal).getJson<{\n version: number;\n snapshots: LatestPointer[];\n }>(historyPath(this.config));\n throwIfAborted(signal);\n if (object.missing) return [];\n const pointers = requireHistory(object.value, this.config.destination.namespace);\n for (const pointer of pointers) this.registerChecksum(pointer.snapshot, pointer.sha256);\n return pointers.map(remoteHistoryEntry);\n }\n\n async diagnose(signal?: AbortSignal): Promise<BackendDiagnostic[]> {\n const diagnostics: BackendDiagnostic[] = [\n {\n key: \"webdav-url\",\n level: \"info\",\n message: `webdav URL/TLS/auth: configured (${webDavStorageLocation(this.config)})`,\n },\n {\n key: \"webdav-scope\",\n level: \"info\",\n message:\n \"webdav check scope: temporary write/delete probe; repair the active snapshot's history entry if missing. No local content is applied.\",\n },\n ];\n try {\n await this.runCapabilityProbe(signal);\n diagnostics.push(\n { key: \"webdav-collection\", level: \"info\", message: \"webdav collection read/write: ok\" },\n {\n key: \"webdav-conditional\",\n level: \"info\",\n message: \"webdav conditional publication: atomic-conditional (verified)\",\n },\n { key: \"webdav-cleanup\", level: \"info\", message: \"webdav probe cleanup: ok\" },\n );\n } catch (error) {\n this.capabilityCheck = undefined;\n this.conditionalVerified = false;\n if (error instanceof Error && error.name === \"AbortError\") throw error;\n diagnostics.push({\n key: \"webdav-probe\",\n level: \"error\",\n message: `webdav publication is read-only until diagnostics pass: ${syncErrorGuidance(error)}`,\n });\n return diagnostics;\n }\n try {\n diagnostics.push({\n key: \"webdav-history\",\n level: \"info\",\n message: await this.reconcileActiveHistory(signal),\n });\n } catch (error) {\n if (error instanceof Error && error.name === \"AbortError\") throw error;\n diagnostics.push({\n key: \"webdav-history\",\n level: \"error\",\n message: `webdav history repair failed: ${syncErrorGuidance(error)}`,\n });\n }\n return diagnostics;\n }\n\n private ensureAtomicConditions(signal?: AbortSignal) {\n if (this.capabilityCheck) return this.capabilityCheck;\n this.conditionalVerified = false;\n const check = this.runCapabilityProbe(signal).finally(() => {\n if (this.capabilityCheck === check) this.capabilityCheck = undefined;\n });\n this.capabilityCheck = check;\n return check;\n }\n\n private async runCapabilityProbe(signal?: AbortSignal) {\n throwIfAborted(signal);\n const probeCollection = joinRemote(rootPath(this.config), \".pi-sync-probes\", randomUUID());\n const probe = `${probeCollection}/conditional.txt`;\n const client = new WebDavClient(this.config, signal);\n let created = false;\n let operationError: unknown;\n try {\n created = true;\n await client.ensureCollection(probeCollection);\n await client.listCollection(probeCollection);\n await client.putBuffer(probe, Buffer.from(\"first\"), \"text/plain\", { ifAbsent: true });\n const read = await client.getBuffer(probe);\n const etag = strongEtag(read.etag);\n if (!read.value || !etag) {\n throw new Error(\"WebDAV server did not return a strong ETag for the capability probe.\");\n }\n await expectPrecondition(\n client.putBuffer(probe, Buffer.from(\"replace\"), \"text/plain\", { ifAbsent: true }),\n \"If-None-Match\",\n );\n await expectPrecondition(\n client.putBuffer(probe, Buffer.from(\"replace\"), \"text/plain\", {\n ifMatch: '\"pi-sync-deliberately-stale\"',\n }),\n \"If-Match\",\n );\n const unchanged = await client.getBuffer(probe);\n if (!unchanged.value?.equals(Buffer.from(\"first\"))) {\n throw new Error(\"WebDAV server changed a probe despite a failed precondition.\");\n }\n await client.putBuffer(probe, Buffer.from(\"second\"), \"text/plain\", { ifMatch: etag });\n const changed = await client.getBuffer(probe);\n const changedEtag = strongEtag(changed.etag);\n if (!changed.value?.equals(Buffer.from(\"second\")) || !changedEtag || changedEtag === etag) {\n throw new Error(\"WebDAV server did not rotate its strong ETag after changing the capability probe.\");\n }\n } catch (error) {\n operationError = error;\n }\n if (created) {\n try {\n await new WebDavClient(this.config, undefined).delete(probeCollection);\n } catch (cleanupError) {\n const operationDetail = operationError ? `WebDAV probe failed: ${errorMessage(operationError)}; ` : \"\";\n throw new Error(\n `${operationDetail}probe cleanup also failed; remove ${probeCollection}: ${errorMessage(cleanupError)}`,\n { cause: operationError ?? cleanupError },\n );\n }\n }\n if (operationError) throw operationError;\n this.conditionalVerified = true;\n }\n\n private async resolveChecksum(reference: string, signal?: AbortSignal) {\n await this.readHead(signal);\n if (this.checksums.has(reference)) return this.checksums.get(reference);\n await this.listHistory(signal);\n return this.checksums.get(reference);\n }\n\n private registerChecksum(reference: string, checksum: string) {\n const known = this.checksums.get(reference);\n if (known && known !== checksum) {\n throw new Error(\"Remote snapshot reference was rebound to a different checksum.\");\n }\n this.checksums.set(reference, checksum);\n }\n\n private async readHeadAfterCommit(client: WebDavClient) {\n const object = await client.getJson<LatestPointer>(latestPath(this.config));\n if (object.missing) return undefined;\n return remoteHead(requirePointer(object.value, this.config.destination.namespace), this.identity, object.etag);\n }\n\n private async reconcileActiveHistory(signal?: AbortSignal) {\n const client = new WebDavClient(this.config, signal);\n const object = await client.getJson<LatestPointer>(latestPath(this.config));\n throwIfAborted(signal);\n if (object.missing) return \"webdav history: no active snapshot\";\n const pointer = requirePointer(object.value, this.config.destination.namespace);\n this.registerChecksum(pointer.snapshot, pointer.sha256);\n const repaired = await this.ensureHistoryPointer(client, pointer);\n return repaired\n ? \"webdav history: repaired active snapshot entry\"\n : \"webdav history: active snapshot entry present\";\n }\n\n private async ensureHistoryPointer(client: WebDavClient, pointer: LatestPointer) {\n const object = await client.getJson<{ version: number; snapshots: LatestPointer[] }>(historyPath(this.config));\n const snapshots = object.missing ? [] : requireHistory(object.value, this.config.destination.namespace);\n const existing = snapshots.find((entry) => entry.snapshot === pointer.snapshot);\n if (existing) {\n if (!samePointer(existing, pointer)) {\n throw new Error(\"Remote history rebound an immutable snapshot reference.\");\n }\n return false;\n }\n const next = [...snapshots, pointer].slice(-100);\n const condition = object.missing ? { ifAbsent: true } : { ifMatch: requireStrongEtag(object.etag, \"history\") };\n await client.putJson(historyPath(this.config), { version: VERSION, snapshots: next }, condition);\n return true;\n }\n\n private async updateHistorySafely(client: WebDavClient, pointer: LatestPointer) {\n try {\n await this.ensureHistoryPointer(client, pointer);\n return undefined;\n } catch (error) {\n return `Remote snapshot is active, but history could not be updated: ${errorMessage(error)}. Run /sync doctor before relying on history.`;\n }\n }\n}\n\nexport function rootPath(config: ResolvedWebDavBackend) {\n return config.destination.path === \"./\" ? \"\" : config.destination.path;\n}\n\nexport function latestPath(config: ResolvedWebDavBackend) {\n return joinRemote(rootPath(config), \"latest.json\");\n}\n\nexport function historyPath(config: ResolvedWebDavBackend) {\n return joinRemote(rootPath(config), \"history.json\");\n}\n\nexport function snapshotsPath(config: ResolvedWebDavBackend) {\n return joinRemote(rootPath(config), \"snapshots\");\n}\n\nexport function snapshotPath(config: ResolvedWebDavBackend, reference: string) {\n requireSnapshotReference(reference);\n return joinRemote(snapshotsPath(config), `${reference}.json.gz`);\n}\n\nexport function webDavBackendIdentity(config: ResolvedWebDavBackend) {\n return `webdav:${sha256(Buffer.from(JSON.stringify([secretFreeUrl(config.profile.url), config.destination.path])))}`;\n}\n\nfunction webDavStorageLocation(config: ResolvedWebDavBackend) {\n const url = new URL(secretFreeUrl(config.profile.url));\n return `${url.host} \u00B7 ${config.destination.path}`;\n}\n\nfunction remoteHead(pointer: LatestPointer, identity: string, etag?: string): RemoteHead {\n return {\n snapshotRef: pointer.snapshot,\n snapshotId: pointer.snapshot,\n revision: encodeRevision(identity, etag, pointer),\n createdAt: pointer.createdAt,\n machine: pointer.machine,\n syncSessions: pointer.syncSessions === true,\n ...(pointer.selection === undefined ? {} : { selection: pointer.selection }),\n };\n}\n\nfunction encodeRevision(identity: string, etag: string | undefined, pointer: LatestPointer) {\n return `webdav-v1:${Buffer.from(JSON.stringify({ identity, etag: etag ?? null, pointer: sha256(Buffer.from(canonicalJson(pointer))) })).toString(\"base64url\")}`;\n}\n\nfunction decodeRevision(value: string, identity: string) {\n try {\n if (!value.startsWith(\"webdav-v1:\")) return undefined;\n const parsed = JSON.parse(Buffer.from(value.slice(10), \"base64url\").toString(\"utf8\")) as {\n identity?: unknown;\n etag?: unknown;\n };\n if (parsed.identity !== identity || typeof parsed.etag !== \"string\") return undefined;\n return strongEtag(parsed.etag);\n } catch {\n return undefined;\n }\n}\n\nfunction publicationCondition(current: RemoteObject<LatestPointer>, expected: ExpectedRemoteHead, identity: string) {\n if (expected.kind === \"missing\") return { ifAbsent: true };\n const etag = decodeRevision(expected.revision, identity) ?? strongEtag(current.etag);\n if (!etag) throw new SyncBackendConflictError(\"WebDAV head has no usable strong ETag.\");\n return { ifMatch: etag };\n}\n\nasync function expectPrecondition(operation: Promise<unknown>, header: string) {\n try {\n await operation;\n } catch (error) {\n if (error instanceof WebDavPreconditionError) return;\n throw error;\n }\n throw new Error(`WebDAV server ignored ${header}; publication is read-only for safety.`);\n}\n\nfunction requireStrongEtag(value: string | undefined, resource: string) {\n const etag = strongEtag(value);\n if (!etag) throw new Error(`WebDAV ${resource} has no strong ETag.`);\n return etag;\n}\n\nfunction strongEtag(value: string | undefined) {\n return value && !value.startsWith(\"W/\") && /^\"[^\"\\r\\n]+\"$/u.test(value) ? value : undefined;\n}\n\nfunction requirePointer(value: LatestPointer | undefined, expectedProfile: string) {\n if (\n !value ||\n value.version !== VERSION ||\n value.profile !== expectedProfile ||\n !isSafeReference(value.snapshot) ||\n !/^[0-9a-f]{64}$/u.test(value.sha256) ||\n !isSafeMetadata(value.createdAt, 64) ||\n !isSafeMetadata(value.machine, 256) ||\n (value.syncSessions !== undefined && typeof value.syncSessions !== \"boolean\")\n ) {\n throw new Error(\"Remote latest pointer is malformed.\");\n }\n if (value.selection !== undefined) portableSnapshotSelection(value.selection);\n return value;\n}\n\nfunction requireHistory(value: { version: number; snapshots: LatestPointer[] } | undefined, expectedProfile: string) {\n if (!value || value.version !== VERSION || !Array.isArray(value.snapshots)) {\n throw new Error(\"Remote history is malformed.\");\n }\n const pointers = value.snapshots.map((item) => requirePointer(item, expectedProfile));\n if (new Set(pointers.map((item) => item.snapshot)).size !== pointers.length) {\n throw new Error(\"Remote history contains duplicate snapshot references.\");\n }\n return pointers;\n}\n\nfunction assertSnapshotIdentity(snapshot: Snapshot, namespace: string) {\n validatePortableSnapshot(snapshot);\n if (\n snapshot.profile !== namespace ||\n !isSafeReference(snapshot.id) ||\n !isSafeMetadata(snapshot.createdAt, 64) ||\n !isSafeMetadata(snapshot.machine, 256) ||\n !Array.isArray(snapshot.files)\n ) {\n throw new Error(\"Invalid snapshot identity for WebDAV publication.\");\n }\n}\n\nfunction validateSnapshotBundle(snapshot: Snapshot) {\n const paths = new Set<string>();\n for (const file of snapshot.files) {\n if (\n !file ||\n !isSafeSnapshotPath(file.path) ||\n paths.has(file.path) ||\n typeof file.contentBase64 !== \"string\" ||\n typeof file.sha256 !== \"string\"\n ) {\n throw new Error(\"Remote snapshot bundle is malformed.\");\n }\n const content = Buffer.from(file.contentBase64, \"base64\");\n if (content.toString(\"base64\") !== file.contentBase64 || sha256(content) !== file.sha256) {\n throw new Error(\"Remote snapshot bundle is malformed.\");\n }\n paths.add(file.path);\n }\n}\n\nfunction isSafeSnapshotPath(value: unknown): value is string {\n if (typeof value !== \"string\" || !value || value.length > 4096 || value.includes(\"\\\\\")) {\n return false;\n }\n if (\n [...value].some((character) => {\n const code = character.codePointAt(0) ?? 0;\n return code < 0x20 || (code >= 0x7f && code <= 0x9f);\n })\n ) {\n return false;\n }\n return value.split(\"/\").every((segment) => segment && segment !== \".\" && segment !== \"..\");\n}\n\nfunction assertSafeDestination(config: ResolvedWebDavBackend) {\n const url = new URL(config.profile.url);\n if (url.username || url.password || url.search || url.hash) throw new Error(\"Invalid WebDAV URL.\");\n for (const [label, value] of [\n [\"path\", config.destination.path],\n [\"namespace\", config.destination.namespace],\n ]) {\n if (label === \"path\" && value === \"./\") continue;\n if (\n !value ||\n value.includes(\"\\\\\") ||\n [...value].some((character) => {\n const code = character.codePointAt(0) ?? 0;\n return code < 0x20 || (code >= 0x7f && code <= 0x9f);\n }) ||\n value.split(\"/\").some((part) => part === \".\" || part === \"..\")\n ) {\n throw new Error(\"Invalid WebDAV storage location.\");\n }\n }\n}\n\nfunction isSafeMetadata(value: unknown, maxLength: number): value is string {\n return (\n typeof value === \"string\" &&\n value.length > 0 &&\n value.length <= maxLength &&\n ![...value].some((character) => {\n const code = character.codePointAt(0) ?? 0;\n return code < 0x20 || (code >= 0x7f && code <= 0x9f);\n })\n );\n}\n\nfunction requireSnapshotReference(reference: string) {\n if (!isSafeReference(reference)) throw new Error(\"Invalid WebDAV snapshot reference.\");\n}\n\nfunction isSafeReference(value: string) {\n return (\n !!value &&\n value.length <= 512 &&\n // biome-ignore lint/suspicious/noControlCharactersInRegex: Remote references cannot contain terminal controls.\n !/[\\\\/\\u0000-\\u001f\\u007f-\\u009f]/u.test(value) &&\n value !== \".\" &&\n value !== \"..\"\n );\n}\n\nfunction matchesExpected(head: RemoteHead | undefined, expected: ExpectedRemoteHead) {\n return expected.kind === \"missing\" ? head === undefined : head?.revision === expected.revision;\n}\n\nfunction samePointer(left: LatestPointer, right: LatestPointer) {\n return canonicalJson(left) === canonicalJson(right);\n}\n\nfunction canonicalJson(value: unknown): string {\n if (Array.isArray(value)) return JSON.stringify(value.map((item) => JSON.parse(canonicalJson(item))));\n if (!value || typeof value !== \"object\") return JSON.stringify(value);\n return JSON.stringify(\n Object.fromEntries(\n Object.keys(value)\n .sort()\n .map((key) => [key, JSON.parse(canonicalJson((value as Record<string, unknown>)[key]))]),\n ),\n );\n}\n\nfunction joinRemote(...parts: string[]) {\n return parts\n .flatMap((part) => part.split(\"/\"))\n .filter(Boolean)\n .join(\"/\");\n}\n\nfunction secretFreeUrl(value: string) {\n const url = new URL(value);\n url.username = \"\";\n url.password = \"\";\n url.search = \"\";\n url.hash = \"\";\n return url.toString();\n}\n\nfunction sha256(value: Buffer) {\n return createHash(\"sha256\").update(value).digest(\"hex\");\n}\n\nfunction errorMessage(error: unknown) {\n if (error instanceof WebDavHttpError) return error.message;\n return error instanceof Error ? error.message : String(error);\n}\n", "import { XMLParser } from \"fast-xml-parser\";\nimport { ContinuousError, continuousFailure, retryAfter } from \"../../sync/continuous-errors.js\";\nimport { throwIfAborted } from \"../../sync/signals.js\";\nimport type { RemoteObject, ResolvedWebDavBackend } from \"../backend-types.js\";\n\nconst JSON_LIMIT = 1024 * 1024;\nconst ERROR_LIMIT = 64 * 1024;\nconst SNAPSHOT_LIMIT = 256 * 1024 * 1024;\nconst XML_LIMIT = 1024 * 1024;\nconst REQUEST_TIMEOUT_MS = 30_000;\nconst MAX_REDIRECTS = 3;\n\nexport interface WebDavPutOptions {\n ifAbsent?: boolean;\n ifMatch?: string;\n}\n\nexport interface WebDavEntry {\n href: string;\n etag?: string;\n collection: boolean;\n}\n\nexport class WebDavHttpError extends Error {\n constructor(\n message: string,\n readonly status: number,\n options?: ErrorOptions,\n readonly retryAfterMs?: number,\n ) {\n super(message, options);\n this.name = \"WebDavHttpError\";\n }\n}\n\nexport class WebDavPreconditionError extends WebDavHttpError {\n constructor(message = \"WebDAV precondition failed.\") {\n super(message, 412);\n this.name = \"WebDavPreconditionError\";\n }\n}\n\nexport class WebDavClient {\n private readonly baseUrl: URL;\n private readonly authorization: string;\n\n constructor(\n private readonly config: ResolvedWebDavBackend,\n private readonly signal?: AbortSignal,\n private readonly timeoutMs = REQUEST_TIMEOUT_MS,\n ) {\n this.baseUrl = new URL(config.profile.url);\n assertSafeAuthenticatedUrl(this.baseUrl);\n if (\n !config.profile.username ||\n !config.profile.password ||\n config.profile.username.includes(\":\") ||\n hasControlCharacter(config.profile.username) ||\n hasControlCharacter(config.profile.password)\n ) {\n throw new Error(\"Invalid WebDAV credentials.\");\n }\n this.authorization = `Basic ${Buffer.from(`${config.profile.username}:${config.profile.password}`).toString(\"base64\")}`;\n }\n\n async getBuffer(remotePath: string): Promise<RemoteObject<Buffer>> {\n const response = await this.request(remotePath, { method: \"GET\" });\n if (response.status === 404) {\n await response.body?.cancel();\n return { missing: true };\n }\n await this.requireOk(response, \"read\");\n return {\n value: await readBounded(response, SNAPSHOT_LIMIT, \"WebDAV response is too large\"),\n etag: response.headers.get(\"etag\") ?? undefined,\n missing: false,\n };\n }\n\n async getJson<T>(remotePath: string): Promise<RemoteObject<T>> {\n const response = await this.request(remotePath, { method: \"GET\" });\n if (response.status === 404) {\n await response.body?.cancel();\n return { missing: true };\n }\n await this.requireOk(response, \"read\");\n const bytes = await readBounded(response, JSON_LIMIT, \"WebDAV JSON response is too large\");\n try {\n return {\n value: JSON.parse(bytes.toString(\"utf8\")) as T,\n etag: response.headers.get(\"etag\") ?? undefined,\n missing: false,\n };\n } catch (error) {\n throw new Error(\"WebDAV JSON response is malformed.\", { cause: error });\n }\n }\n\n async putBuffer(remotePath: string, body: Buffer, contentType: string, options: WebDavPutOptions = {}) {\n const headers: Record<string, string> = { \"content-type\": contentType };\n if (options.ifAbsent) headers[\"if-none-match\"] = \"*\";\n if (options.ifMatch) headers[\"if-match\"] = options.ifMatch;\n const response = await this.request(remotePath, {\n method: \"PUT\",\n headers,\n body: body as unknown as BodyInit,\n });\n if (response.status === 412) {\n await response.body?.cancel();\n throw new WebDavPreconditionError();\n }\n await this.requireOk(response, \"write\");\n await response.body?.cancel();\n return response.headers.get(\"etag\") ?? undefined;\n }\n\n async putJson(remotePath: string, value: unknown, options: WebDavPutOptions = {}) {\n return this.putBuffer(remotePath, Buffer.from(JSON.stringify(value)), \"application/json\", options);\n }\n\n async makeCollection(remotePath: string) {\n const response = await this.request(remotePath, { method: \"MKCOL\" });\n if (response.status === 405) {\n await response.body?.cancel();\n return false;\n }\n await this.requireOk(response, \"create collection\");\n await response.body?.cancel();\n return true;\n }\n\n async ensureCollection(remotePath: string) {\n const segments = safeSegments(remotePath);\n for (let index = 1; index <= segments.length; index += 1) {\n await this.makeCollection(segments.slice(0, index).join(\"/\"));\n }\n }\n\n async listCollection(remotePath: string): Promise<WebDavEntry[]> {\n const response = await this.request(remotePath, {\n method: \"PROPFIND\",\n headers: { depth: \"1\", \"content-type\": \"application/xml; charset=utf-8\" },\n body: '<?xml version=\"1.0\"?><d:propfind xmlns:d=\"DAV:\"><d:prop><d:getetag/><d:resourcetype/></d:prop></d:propfind>',\n });\n if (response.status === 404) {\n await response.body?.cancel();\n throw new WebDavHttpError(\"WebDAV collection is missing.\", 404);\n }\n if (response.status !== 207) await this.requireOk(response, \"list collection\");\n const xml = (await readBounded(response, XML_LIMIT, \"WebDAV directory response is too large\")).toString(\"utf8\");\n try {\n const parsed = new XMLParser({\n removeNSPrefix: true,\n ignoreAttributes: false,\n processEntities: false,\n }).parse(xml) as {\n multistatus?: { response?: unknown };\n };\n if (!parsed.multistatus || parsed.multistatus.response === undefined) {\n throw new Error(\"Missing DAV multistatus response.\");\n }\n const responses = asArray(parsed.multistatus.response);\n return responses.map(parseEntry);\n } catch (error) {\n throw new Error(\"WebDAV directory response is malformed.\", { cause: error });\n }\n }\n\n async delete(remotePath: string) {\n const response = await this.request(remotePath, { method: \"DELETE\" });\n if (response.status === 404) {\n await response.body?.cancel();\n return;\n }\n if (response.status === 207) {\n await response.body?.cancel();\n throw new WebDavHttpError(\"WebDAV probe cleanup returned a partial response.\", 207);\n }\n await this.requireOk(response, \"delete probe resource\");\n await response.body?.cancel();\n }\n\n private async request(remotePath: string, init: RequestInit) {\n throwIfAborted(this.signal);\n let url = appendRemotePath(this.baseUrl, remotePath);\n for (let redirects = 0; ; redirects += 1) {\n const timeout = AbortSignal.timeout(this.timeoutMs);\n const signal = this.signal ? AbortSignal.any([this.signal, timeout]) : timeout;\n let response: Response;\n try {\n response = await fetch(url, {\n ...init,\n headers: {\n accept: \"*/*\",\n authorization: this.authorization,\n ...headersObject(init.headers),\n },\n redirect: \"manual\",\n signal,\n });\n } catch (error) {\n throwIfAborted(this.signal);\n throw new Error(\n `WebDAV ${String(init.method ?? \"GET\")} request failed for ${redactText(safeUrl(url), this.config)}.`,\n {\n cause: redactError(error, this.config),\n },\n );\n }\n if (![301, 302, 303, 307, 308].includes(response.status)) return response;\n await response.body?.cancel();\n const method = String(init.method ?? \"GET\").toUpperCase();\n if ([301, 302, 303].includes(response.status) && method !== \"GET\" && method !== \"HEAD\") {\n throw new Error(\n `WebDAV refused an ambiguous HTTP ${response.status} redirect for ${method}; configure the canonical collection URL or require HTTP 307/308.`,\n );\n }\n if (redirects >= MAX_REDIRECTS) throw new Error(\"WebDAV redirect limit exceeded.\");\n const location = response.headers.get(\"location\");\n if (!location) throw new Error(\"WebDAV redirect is missing Location.\");\n const next = new URL(location, url);\n if (next.origin !== this.baseUrl.origin) {\n throw new Error(\"WebDAV refused a cross-origin authenticated redirect.\");\n }\n url = next;\n }\n }\n\n private async requireOk(response: Response, action: string) {\n if (response.ok) return;\n const body = (await readBounded(response, ERROR_LIMIT, \"WebDAV error body is too large\"))\n .toString(\"utf8\")\n // biome-ignore lint/suspicious/noControlCharactersInRegex: Remote error text is untrusted terminal input.\n .replace(/[\\u0000-\\u001f\\u007f-\\u009f]/gu, \" \")\n .trim();\n const detail = body ? `: ${redactText(body, this.config)}` : \"\";\n throw new WebDavHttpError(\n `WebDAV ${action} failed with HTTP ${response.status}${detail}`,\n response.status,\n undefined,\n retryAfter(response),\n );\n }\n}\n\nfunction assertSafeAuthenticatedUrl(url: URL) {\n const loopback =\n url.hostname === \"127.0.0.1\" || url.hostname === \"localhost\" || url.hostname === \"[::1]\" || url.hostname === \"::1\";\n if (\n url.username ||\n url.password ||\n url.search ||\n url.hash ||\n (url.protocol !== \"https:\" && !(url.protocol === \"http:\" && loopback))\n ) {\n throw new Error(\n \"Invalid WebDAV URL: HTTPS is required and embedded credentials, query, or fragment are not allowed.\",\n );\n }\n}\n\nfunction hasControlCharacter(value: string) {\n return [...value].some((character) => {\n const code = character.codePointAt(0) ?? 0;\n return code < 0x20 || (code >= 0x7f && code <= 0x9f);\n });\n}\n\nfunction appendRemotePath(base: URL, remotePath: string) {\n const url = new URL(base);\n const suffix = safeSegments(remotePath).map(encodeURIComponent).join(\"/\");\n url.pathname = `${base.pathname.replace(/\\/+$/u, \"\")}/${suffix}`;\n return url;\n}\n\nfunction safeSegments(value: string) {\n const segments = value\n .replace(/^\\/+|\\/+$/gu, \"\")\n .split(\"/\")\n .filter(Boolean);\n if (\n segments.some(\n (segment) =>\n segment === \".\" ||\n segment === \"..\" ||\n // biome-ignore lint/suspicious/noControlCharactersInRegex: Remote path segments cannot contain controls.\n /[\\u0000-\\u001f]/u.test(segment),\n )\n ) {\n throw new Error(\"Invalid WebDAV remote path.\");\n }\n return segments;\n}\n\nasync function readBounded(response: Response, limit: number, message: string) {\n const length = Number(response.headers.get(\"content-length\"));\n if (Number.isFinite(length) && length > limit) {\n await response.body?.cancel();\n throw new Error(message);\n }\n if (!response.body) return Buffer.alloc(0);\n const reader = response.body.getReader();\n const chunks: Buffer[] = [];\n let total = 0;\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n total += value.byteLength;\n if (total > limit) throw new Error(message);\n chunks.push(Buffer.from(value));\n }\n } catch (error) {\n await reader.cancel().catch(() => undefined);\n throw error;\n }\n return Buffer.concat(chunks, total);\n}\n\nfunction parseEntry(value: unknown): WebDavEntry {\n if (!value || typeof value !== \"object\") throw new Error(\"Invalid WebDAV response entry.\");\n const record = value as Record<string, unknown>;\n const href = typeof record.href === \"string\" ? record.href : undefined;\n if (!href) throw new Error(\"Invalid WebDAV response href.\");\n const propstat = asArray(record.propstat).find((item) => {\n if (!item || typeof item !== \"object\") return false;\n return String((item as Record<string, unknown>).status ?? \"\").includes(\" 200 \");\n }) as Record<string, unknown> | undefined;\n const prop = propstat?.prop as Record<string, unknown> | undefined;\n return {\n href,\n etag: typeof prop?.getetag === \"string\" ? prop.getetag : undefined,\n collection:\n !!prop?.resourcetype && typeof prop.resourcetype === \"object\" && Object.hasOwn(prop.resourcetype, \"collection\"),\n };\n}\n\nfunction asArray(value: unknown): unknown[] {\n if (value === undefined) return [];\n return Array.isArray(value) ? value : [value];\n}\n\nfunction headersObject(headers: HeadersInit | undefined) {\n return Object.fromEntries(new Headers(headers).entries());\n}\n\nfunction safeUrl(url: URL) {\n return `${url.protocol}//${url.host}${url.pathname}`;\n}\n\nfunction redactError(error: unknown, config: ResolvedWebDavBackend) {\n const message = error instanceof Error ? error.message : String(error);\n const failure = continuousFailure(error);\n return new ContinuousError(failure.kind, redactText(message, config), failure.delay);\n}\n\nfunction redactText(value: string, config: ResolvedWebDavBackend) {\n let result = value;\n for (const secret of [config.profile.username, config.profile.password, config.profile.url]) {\n if (!secret) continue;\n for (const variant of new Set([secret, encodeURIComponent(secret)])) {\n result = result.replace(new RegExp(escapeRegExp(variant), \"giu\"), \"[redacted]\");\n }\n }\n return result.replace(/basic\\s+[a-z0-9+/=]+/giu, \"Basic [redacted]\").replace(/\\?[^\\s]*/gu, \"?[redacted]\");\n}\n\nfunction escapeRegExp(value: string) {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/gu, \"\\\\$&\");\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,kBAAkB;;;ACAvC,SAAS,iBAAiB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