@gusto/baerly-storage 0.5.0 → 0.7.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 (215) hide show
  1. package/README.md +47 -124
  2. package/dist/API.md +161 -511
  3. package/dist/CHANGELOG.md +1148 -307
  4. package/dist/RECIPES.md +398 -80
  5. package/dist/THIRD-PARTY-LICENSES.txt +5 -26
  6. package/dist/{app-config-DyiFK3_k.d.ts → app-config-C6qW7m8S.d.ts} +119 -111
  7. package/dist/app-config.d.ts +31 -1
  8. package/dist/app-config.js +1 -2
  9. package/dist/app-config.js.map +1 -1
  10. package/dist/auth.d.ts +33 -28
  11. package/dist/auth.js +549 -985
  12. package/dist/auth.js.map +1 -1
  13. package/dist/baerly.js +130 -138
  14. package/dist/baerly.js.map +1 -1
  15. package/dist/baerly.spec.json +97 -22
  16. package/dist/capacity-warning-header-BlVopyiI.js +16 -0
  17. package/dist/capacity-warning-header-BlVopyiI.js.map +1 -0
  18. package/dist/{client-Fe8CwB73.d.ts → client-CHQTXpef.d.ts} +121 -36
  19. package/dist/client-react.d.ts +67 -20
  20. package/dist/client-react.js +240 -54
  21. package/dist/client-react.js.map +1 -1
  22. package/dist/client.d.ts +5 -4
  23. package/dist/client.js +51 -16
  24. package/dist/client.js.map +1 -1
  25. package/dist/{cloudflare-DzKBrUlg.js → cloudflare-CKHYXccw.js} +504 -124
  26. package/dist/cloudflare-CKHYXccw.js.map +1 -0
  27. package/dist/cloudflare.d.ts +106 -71
  28. package/dist/cloudflare.js +334 -271
  29. package/dist/cloudflare.js.map +1 -1
  30. package/dist/code-resolution-CL_7L0wS.js +22 -0
  31. package/dist/code-resolution-CL_7L0wS.js.map +1 -0
  32. package/dist/collection-api-DbyhLAY8.d.ts +1001 -0
  33. package/dist/config-DEzInG6M.js +4035 -0
  34. package/dist/config-DEzInG6M.js.map +1 -0
  35. package/dist/constants-D3GSH3tc.js +469 -0
  36. package/dist/constants-D3GSH3tc.js.map +1 -0
  37. package/dist/{context-DRZ3tZ5l.js → context-rlpSnHFA.js} +17 -17
  38. package/dist/context-rlpSnHFA.js.map +1 -0
  39. package/dist/cost-B52llVDx.js +330 -0
  40. package/dist/cost-B52llVDx.js.map +1 -0
  41. package/dist/{current-json-C6nhPOm1.js → current-json-CC6lE4Aj.js} +115 -32
  42. package/dist/current-json-CC6lE4Aj.js.map +1 -0
  43. package/dist/db-plFUNTSF.d.ts +130 -0
  44. package/dist/db-read-seams-BSs0m1z1.js +3261 -0
  45. package/dist/db-read-seams-BSs0m1z1.js.map +1 -0
  46. package/dist/{deploy-DonTr-CV.js → deploy-Obj4nE-Z.js} +12 -16
  47. package/dist/deploy-Obj4nE-Z.js.map +1 -0
  48. package/dist/{dev-banner-CWHIk8tH.d.ts → dev-banner-B5AUHmu1.d.ts} +1 -4
  49. package/dist/dev-landing-BI5UdmOb.d.ts +32 -0
  50. package/dist/dev-landing-CD-si4dW.js +50 -0
  51. package/dist/dev-landing-CD-si4dW.js.map +1 -0
  52. package/dist/dev-vite.d.ts +38 -39
  53. package/dist/dev-vite.js +67 -36
  54. package/dist/dev-vite.js.map +1 -1
  55. package/dist/dev.d.ts +3 -2
  56. package/dist/dev.js +2 -1
  57. package/dist/doctor-BA0i-YAN.js +270 -0
  58. package/dist/doctor-BA0i-YAN.js.map +1 -0
  59. package/dist/dump-D1vX8ozg.js +133 -0
  60. package/dist/dump-D1vX8ozg.js.map +1 -0
  61. package/dist/errors-7Rk1HGCE.js +160 -0
  62. package/dist/errors-7Rk1HGCE.js.map +1 -0
  63. package/dist/{validate-DtljsCh1.js → export-BVL2EvYE.js} +409 -19
  64. package/dist/export-BVL2EvYE.js.map +1 -0
  65. package/dist/fsck-BWkPgov4.js +145 -0
  66. package/dist/fsck-BWkPgov4.js.map +1 -0
  67. package/dist/gcs-admin-Dso1HWQj.d.ts +127 -0
  68. package/dist/gcs.d.ts +30 -0
  69. package/dist/gcs.js +1 -0
  70. package/dist/goog4-signer-CeLIABoE.js +331 -0
  71. package/dist/goog4-signer-CeLIABoE.js.map +1 -0
  72. package/dist/{http-DGd5tbNs.js → http-Z5rZyYMX.js} +898 -271
  73. package/dist/http-Z5rZyYMX.js.map +1 -0
  74. package/dist/http-transport-DNUM8kU-.js +1299 -0
  75. package/dist/http-transport-DNUM8kU-.js.map +1 -0
  76. package/dist/http.d.ts +366 -294
  77. package/dist/http.js +2 -2
  78. package/dist/index-JJrIu1pO.d.ts +135 -0
  79. package/dist/index-LEgHN0qJ.d.ts +50 -0
  80. package/dist/{index-CuA9Mi3K.d.ts → index-RiEYj8t0.d.ts} +291 -78
  81. package/dist/index.d.ts +27 -6
  82. package/dist/index.js +3 -5
  83. package/dist/inspect-BTsVYZKd.js +196 -0
  84. package/dist/inspect-BTsVYZKd.js.map +1 -0
  85. package/dist/{key-Di6yyxFu.js → key-C4FPZ9Io.js} +3 -4
  86. package/dist/{key-Di6yyxFu.js.map → key-C4FPZ9Io.js.map} +1 -1
  87. package/dist/ledger-Dj_bGgo0.js +192 -0
  88. package/dist/ledger-Dj_bGgo0.js.map +1 -0
  89. package/dist/legacy-names-DgZBtgOh.js +47 -0
  90. package/dist/legacy-names-DgZBtgOh.js.map +1 -0
  91. package/dist/log-C9W15Dfo.d.ts +94 -0
  92. package/dist/log-tail-DWJbneBF.js +142 -0
  93. package/dist/log-tail-DWJbneBF.js.map +1 -0
  94. package/dist/log-walk-C-vA-WGJ.js +111 -0
  95. package/dist/log-walk-C-vA-WGJ.js.map +1 -0
  96. package/dist/maintenance-Dd-Yakqj.js +1709 -0
  97. package/dist/maintenance-Dd-Yakqj.js.map +1 -0
  98. package/dist/maintenance-DevB6z4e.js +2237 -0
  99. package/dist/maintenance-DevB6z4e.js.map +1 -0
  100. package/dist/maintenance.d.ts +100 -3
  101. package/dist/maintenance.js +1 -3
  102. package/dist/node.d.ts +130 -142
  103. package/dist/node.js +4 -3
  104. package/dist/{observability-BmflLCdF.js → observability-C-ISCCLE.js} +1275 -332
  105. package/dist/observability-C-ISCCLE.js.map +1 -0
  106. package/dist/observability.d.ts +27 -3
  107. package/dist/observability.js +3 -3
  108. package/dist/path-segment-DBXG26PW.js +363 -0
  109. package/dist/path-segment-DBXG26PW.js.map +1 -0
  110. package/dist/{plan-a7PJHBCy.js → plan-BvQbaNMe.js} +19 -11
  111. package/dist/plan-BvQbaNMe.js.map +1 -0
  112. package/dist/request-CRWiTrza.js +272 -0
  113. package/dist/request-CRWiTrza.js.map +1 -0
  114. package/dist/restore-U6Im8V1V.js +1467 -0
  115. package/dist/restore-U6Im8V1V.js.map +1 -0
  116. package/dist/retry-OBtLB2GC.js +126 -0
  117. package/dist/retry-OBtLB2GC.js.map +1 -0
  118. package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
  119. package/dist/{runtime-spec-Dsw2-n8S.js → runtime-spec-B5mg3pHF.js} +189 -28
  120. package/dist/runtime-spec-B5mg3pHF.js.map +1 -0
  121. package/dist/{s3-http-B-z8th6O.d.ts → s3-http-DBC_wiCL.d.ts} +18 -10
  122. package/dist/s3.d.ts +20 -7
  123. package/dist/s3.js +4 -5
  124. package/dist/s3.js.map +1 -1
  125. package/dist/sha256-4FfGQNPw.js +22 -0
  126. package/dist/sha256-4FfGQNPw.js.map +1 -0
  127. package/dist/{shared-secret-DgEicd3x.js → shared-secret-Vkur-8r0.js} +27 -15
  128. package/dist/shared-secret-Vkur-8r0.js.map +1 -0
  129. package/dist/sigv4-sign-5IUflUD_.js +507 -0
  130. package/dist/sigv4-sign-5IUflUD_.js.map +1 -0
  131. package/dist/snapshot-CknzkDM0.js +148 -0
  132. package/dist/snapshot-CknzkDM0.js.map +1 -0
  133. package/dist/{src-BL_JoPTn.js → src-Actga-bO.js} +1004 -378
  134. package/dist/src-Actga-bO.js.map +1 -0
  135. package/dist/src-D0MQfvOp.js +812 -0
  136. package/dist/src-D0MQfvOp.js.map +1 -0
  137. package/dist/src-Dr9uo3dc.js +501 -0
  138. package/dist/src-Dr9uo3dc.js.map +1 -0
  139. package/dist/{subcommand-DoDA-K7d.js → subcommand-BLoF66dG.js} +89 -16
  140. package/dist/subcommand-BLoF66dG.js.map +1 -0
  141. package/dist/{time-DUqvFMHq.js → time-DRxTP9iv.js} +15 -34
  142. package/dist/time-DRxTP9iv.js.map +1 -0
  143. package/dist/types-suVbsEWS.d.ts +116 -0
  144. package/dist/{usage-DBV1eQHC.js → usage-CPzVhrQr.js} +40 -45
  145. package/dist/usage-CPzVhrQr.js.map +1 -0
  146. package/dist/uuid-BuT_c404.js +333 -0
  147. package/dist/uuid-BuT_c404.js.map +1 -0
  148. package/dist/verifier-Bmlmndzo.d.ts +95 -0
  149. package/dist/{wire-izfGZDvr.js → wire-DndvKU-K.js} +2 -3
  150. package/dist/wire-DndvKU-K.js.map +1 -0
  151. package/package.json +96 -69
  152. package/dist/aws4fetch.esm-p7eEzLCs.js +0 -1702
  153. package/dist/aws4fetch.esm-p7eEzLCs.js.map +0 -1
  154. package/dist/bytes-BXdamO3L.js +0 -11
  155. package/dist/bytes-BXdamO3L.js.map +0 -1
  156. package/dist/cloudflare-DzKBrUlg.js.map +0 -1
  157. package/dist/config-1tv0-Yzm.js +0 -2693
  158. package/dist/config-1tv0-Yzm.js.map +0 -1
  159. package/dist/constants-CfeMWQWk.js +0 -222
  160. package/dist/constants-CfeMWQWk.js.map +0 -1
  161. package/dist/context-DRZ3tZ5l.js.map +0 -1
  162. package/dist/cost-DSMIVqzL.js +0 -203
  163. package/dist/cost-DSMIVqzL.js.map +0 -1
  164. package/dist/current-json-C6nhPOm1.js.map +0 -1
  165. package/dist/db-DsPkOVEH.d.ts +0 -254
  166. package/dist/deploy-DonTr-CV.js.map +0 -1
  167. package/dist/doctor-DSIyCDg_.js +0 -346
  168. package/dist/doctor-DSIyCDg_.js.map +0 -1
  169. package/dist/dump-Bh5k26VQ.js +0 -94
  170. package/dist/dump-Bh5k26VQ.js.map +0 -1
  171. package/dist/errors-Dfa3p78c.js +0 -78
  172. package/dist/errors-Dfa3p78c.js.map +0 -1
  173. package/dist/export-DtF5tDIM.js +0 -401
  174. package/dist/export-DtF5tDIM.js.map +0 -1
  175. package/dist/fsck-D_djMO5D.js +0 -279
  176. package/dist/fsck-D_djMO5D.js.map +0 -1
  177. package/dist/http-DGd5tbNs.js.map +0 -1
  178. package/dist/index-0rZcMBwy.d.ts +0 -115
  179. package/dist/index-BNRh23K9.d.ts +0 -162
  180. package/dist/index-BYk9oCNf.d.ts +0 -1112
  181. package/dist/indexes-Dn9hbGQG.d.ts +0 -22
  182. package/dist/inspect-6WZ-pC7-.js +0 -133
  183. package/dist/inspect-6WZ-pC7-.js.map +0 -1
  184. package/dist/log-tail-D98U1JBo.js +0 -522
  185. package/dist/log-tail-D98U1JBo.js.map +0 -1
  186. package/dist/maintenance-B4Dki6Ig.js +0 -2157
  187. package/dist/maintenance-B4Dki6Ig.js.map +0 -1
  188. package/dist/maintenance-B_e0T99L.d.ts +0 -537
  189. package/dist/maintenance-C7coQp4c.js +0 -1418
  190. package/dist/maintenance-C7coQp4c.js.map +0 -1
  191. package/dist/normalize-rjnZLwS4.js +0 -133
  192. package/dist/normalize-rjnZLwS4.js.map +0 -1
  193. package/dist/observability-BmflLCdF.js.map +0 -1
  194. package/dist/plan-a7PJHBCy.js.map +0 -1
  195. package/dist/query-rAtXNQQB.js +0 -1773
  196. package/dist/query-rAtXNQQB.js.map +0 -1
  197. package/dist/rebuild-index-BVzQSZlm.js +0 -81
  198. package/dist/rebuild-index-BVzQSZlm.js.map +0 -1
  199. package/dist/request-u0M51mhJ.js +0 -72
  200. package/dist/request-u0M51mhJ.js.map +0 -1
  201. package/dist/restore-R-4rbciV.js +0 -778
  202. package/dist/restore-R-4rbciV.js.map +0 -1
  203. package/dist/rolldown-runtime-EAsCxrDo.js +0 -14
  204. package/dist/runtime-spec-Dsw2-n8S.js.map +0 -1
  205. package/dist/shared-secret-DgEicd3x.js.map +0 -1
  206. package/dist/src-BL_JoPTn.js.map +0 -1
  207. package/dist/src-CYHFDrKz.js +0 -536
  208. package/dist/src-CYHFDrKz.js.map +0 -1
  209. package/dist/src-DYZ4H1aF.js +0 -392
  210. package/dist/src-DYZ4H1aF.js.map +0 -1
  211. package/dist/subcommand-DoDA-K7d.js.map +0 -1
  212. package/dist/time-DUqvFMHq.js.map +0 -1
  213. package/dist/usage-DBV1eQHC.js.map +0 -1
  214. package/dist/validate-DtljsCh1.js.map +0 -1
  215. package/dist/wire-izfGZDvr.js.map +0 -1
@@ -1,10 +1,9 @@
1
- import { o as uuid, r as parseBucketUri } from "./config-1tv0-Yzm.js";
2
- import { o as BaerlyError } from "./baerly.js";
1
+ import { c as isWriteConflict, s as BaerlyError } from "./baerly.js";
2
+ import { D as SHARED_SECRET_MISSING_MESSAGE, O as CF_ACCESS_TEAM_NAME_PATTERN, l as uuid, n as parseBucketUri, r as goog4Signer } from "./config-DEzInG6M.js";
3
3
  import { resolve } from "node:path";
4
4
  import { existsSync, readFileSync } from "node:fs";
5
5
  import { spawn } from "node:child_process";
6
- //#region ../protocol/src/storage/probe-cas.ts
7
- const isConflict = (error) => error instanceof BaerlyError && error.code === "Conflict";
6
+ // ../protocol/src/storage/probe-cas.ts
8
7
  /**
9
8
  * Runtime probe that a live `Storage` backend honours the conditional
10
9
  * writes the protocol depends on. The storage conformance suite asserts
@@ -22,16 +21,16 @@ const isConflict = (error) => error instanceof BaerlyError && error.code === "Co
22
21
  * Writes throwaway sentinels under `keyPrefix` and deletes them on
23
22
  * the way out (even on failure). Three checks, mirroring the conformance
24
23
  * suite:
25
- * - `ifMatch-stale`: a PUT with a stale `ifMatch` must reject (Conflict).
24
+ * - `ifMatch-stale`: a PUT with a stale `ifMatch` must reject (WriteConflict).
26
25
  * - `ifNoneMatch-exists`: a PUT with `ifNoneMatch:"*"` over an existing
27
- * key must reject (Conflict).
26
+ * key must reject (WriteConflict).
28
27
  * - `ifNoneMatch-concurrent`: at most one of N concurrent create-if-absent
29
28
  * writes on a fresh key wins — the linearizability the writer's log-append
30
29
  * commit already relies on (`writer.ts`).
31
30
  *
32
- * A rejected write surfaces as a `BaerlyError` with `code === "Conflict"`
31
+ * A rejected write surfaces as a `BaerlyError` with `code === "WriteConflict"`
33
32
  * (the contract `Storage.put` documents); anything else — a resolved
34
- * promise, or a non-Conflict error — is reported as a failed or
33
+ * promise, or a non-WriteConflict error — is reported as a failed or
35
34
  * inconclusive check rather than thrown.
36
35
  */
37
36
  const probeCas = async (storage, opts) => {
@@ -39,12 +38,13 @@ const probeCas = async (storage, opts) => {
39
38
  const key = `${prefix}__baerly_cas_probe__/${uuid()}`;
40
39
  const enc = new TextEncoder();
41
40
  const signal = opts?.signal;
41
+ const staleEtag = opts?.staleEtag ?? "\"baerly-cas-probe-stale\"";
42
42
  const checks = [];
43
43
  try {
44
44
  await storage.put(key, enc.encode("v1"), { signal });
45
45
  try {
46
46
  await storage.put(key, enc.encode("v2"), {
47
- ifMatch: "\"baerly-cas-probe-stale\"",
47
+ ifMatch: staleEtag,
48
48
  signal
49
49
  });
50
50
  checks.push({
@@ -53,14 +53,14 @@ const probeCas = async (storage, opts) => {
53
53
  detail: "PUT with a stale If-Match was ACCEPTED — backend ignores If-Match (silent lost-update risk)."
54
54
  });
55
55
  } catch (error) {
56
- checks.push(isConflict(error) ? {
56
+ checks.push(isWriteConflict(error) ? {
57
57
  name: "ifMatch-stale",
58
58
  ok: true,
59
- detail: "stale If-Match rejected (Conflict), as required."
59
+ detail: "stale If-Match rejected (WriteConflict), as required."
60
60
  } : {
61
61
  name: "ifMatch-stale",
62
62
  ok: false,
63
- detail: `stale If-Match raised a non-Conflict error: ${error instanceof Error ? error.message : String(error)}`
63
+ detail: `stale If-Match raised a non-WriteConflict error: ${error instanceof Error ? error.message : String(error)}`
64
64
  });
65
65
  }
66
66
  try {
@@ -74,14 +74,14 @@ const probeCas = async (storage, opts) => {
74
74
  detail: "PUT with If-None-Match:\"*\" over an existing key was ACCEPTED — backend ignores If-None-Match (create-only writes unsafe)."
75
75
  });
76
76
  } catch (error) {
77
- checks.push(isConflict(error) ? {
77
+ checks.push(isWriteConflict(error) ? {
78
78
  name: "ifNoneMatch-exists",
79
79
  ok: true,
80
- detail: "If-None-Match:\"*\" over an existing key rejected (Conflict), as required."
80
+ detail: "If-None-Match:\"*\" over an existing key rejected (WriteConflict), as required."
81
81
  } : {
82
82
  name: "ifNoneMatch-exists",
83
83
  ok: false,
84
- detail: `If-None-Match:"*" raised a non-Conflict error: ${error instanceof Error ? error.message : String(error)}`
84
+ detail: `If-None-Match:"*" raised a non-WriteConflict error: ${error instanceof Error ? error.message : String(error)}`
85
85
  });
86
86
  }
87
87
  const raceKey = `${prefix}__baerly_cas_probe__/${uuid()}`;
@@ -92,23 +92,24 @@ const probeCas = async (storage, opts) => {
92
92
  signal
93
93
  })));
94
94
  const winners = outcomes.filter((o) => o.status === "fulfilled").length;
95
- const transient = outcomes.filter((o) => o.status === "rejected" && !isConflict(o.reason)).length;
95
+ const transient = outcomes.filter((o) => o.status === "rejected" && !isWriteConflict(o.reason)).length;
96
96
  if (winners > 1) checks.push({
97
97
  name: "ifNoneMatch-concurrent",
98
98
  ok: false,
99
99
  detail: `${winners} of ${RACERS} concurrent create-if-absent writes won (expected at most 1) — create-if-absent is NOT linearizable; the log-append commit would split-brain.`
100
100
  });
101
- else if (winners === 1) if (transient === 0) checks.push({
102
- name: "ifNoneMatch-concurrent",
103
- ok: true,
104
- detail: `exactly one of ${RACERS} concurrent create-if-absent writes won; the rest rejected (Conflict), as required.`
105
- });
106
- else checks.push({
107
- name: "ifNoneMatch-concurrent",
108
- ok: false,
109
- detail: `exactly one of ${RACERS} concurrent create-if-absent writes won, but ${transient} loser(s) returned a transient non-Conflict error — inconclusive; retry for a clean race.`
110
- });
111
- else checks.push({
101
+ else if (winners === 1) {
102
+ if (transient === 0) checks.push({
103
+ name: "ifNoneMatch-concurrent",
104
+ ok: true,
105
+ detail: `exactly one of ${RACERS} concurrent create-if-absent writes won; the rest rejected (WriteConflict), as required.`
106
+ });
107
+ else checks.push({
108
+ name: "ifNoneMatch-concurrent",
109
+ ok: false,
110
+ detail: `exactly one of ${RACERS} concurrent create-if-absent writes won, but ${transient} loser(s) returned a transient non-WriteConflict error — inconclusive; retry for a clean race.`
111
+ });
112
+ } else checks.push({
112
113
  name: "ifNoneMatch-concurrent",
113
114
  ok: false,
114
115
  detail: `no create-if-absent write succeeded across ${RACERS} attempts — inconclusive (transient failure or outage), not a linearizability verdict; retry.`
@@ -128,8 +129,44 @@ const probeCas = async (storage, opts) => {
128
129
  checks
129
130
  };
130
131
  };
131
- //#endregion
132
- //#region src/doctor/cas.ts
132
+ // ../adapter-node/src/gcs-admin.ts
133
+ /**
134
+ * GCS bucket-administration probes over the native XML API — read-only
135
+ * config checks that fall outside the four-verb `Storage` interface.
136
+ * Kept in the adapter so GCS wire details (endpoint/URL shape, the
137
+ * `?versioning` sub-resource, the XML response, GOOG4 signing) live
138
+ * behind the adapter boundary rather than leaking into the CLI.
139
+ */
140
+ /** Case-sensitive per the GCS `?versioning` XML shape; tolerate surrounding whitespace. */
141
+ const VERSIONING_ENABLED_RE = /<Status>\s*Enabled\s*<\/Status>/;
142
+ /**
143
+ * Read a GCS bucket's Object Versioning setting over the native XML API
144
+ * (`GET <endpoint>/<bucket>?versioning`), signed with GOOG4-HMAC-SHA256.
145
+ * Never throws — a non-2xx response or a network error resolves to
146
+ * `{ kind: "inconclusive", reason }`, so callers (e.g. `baerly doctor`)
147
+ * can degrade gracefully instead of aborting.
148
+ */
149
+ async function gcsVersioningStatus(opts) {
150
+ const endpoint = (opts.endpoint ?? "https://storage.googleapis.com").replace(/\/+$/, "");
151
+ const fetchImpl = opts.fetch ?? globalThis.fetch.bind(globalThis);
152
+ const sign = goog4Signer({ credentials: opts.credentials });
153
+ const url = `${endpoint}/${opts.bucket}?versioning`;
154
+ try {
155
+ const res = await fetchImpl(await sign(new Request(url, { method: "GET" })));
156
+ if (!res.ok) return {
157
+ kind: "inconclusive",
158
+ reason: `HTTP ${res.status}`
159
+ };
160
+ const body = await res.text();
161
+ return VERSIONING_ENABLED_RE.test(body) ? { kind: "enabled" } : { kind: "disabled" };
162
+ } catch (error) {
163
+ return {
164
+ kind: "inconclusive",
165
+ reason: error instanceof Error ? error.message : String(error)
166
+ };
167
+ }
168
+ }
169
+ // src/doctor/cas.ts
133
170
  /**
134
171
  * `baerly doctor --bucket <uri>` — live backend CAS probe.
135
172
  *
@@ -147,14 +184,22 @@ const probeCas = async (storage, opts) => {
147
184
  * Writes throwaway sentinels and deletes them; see
148
185
  * {@link probeCas}.
149
186
  */
150
- const CAS_FIX = "Point baerly at an S3-compatible store that honours conditional writes (If-Match + If-None-Match). AWS S3 and Cloudflare R2 honour them. Some S3-compatible endpoints don't enforce them on writes — notably GCS's interop endpoint, which documents these headers as read-only — and a custom gateway / proxy may strip them; this probe exists to catch exactly that. A conformant backend returns 412 on a stale If-Match.";
187
+ const CAS_FIX = "Point baerly at a store that honours conditional writes (If-Match + If-None-Match). AWS S3 and Cloudflare R2 honour them natively; for Google Cloud Storage use the native gcs:// path (baerly's GcsHttpStorage drives x-goog-if-generation-match) — GCS's S3-interop endpoint documents these headers as read-only and is not supported. A custom gateway or proxy may also strip them; this probe exists to catch exactly that. A conformant backend returns 412 on a stale If-Match.";
151
188
  /**
152
189
  * Run the live CAS round-trip against `storage` and shape the result
153
190
  * as a {@link DoctorReport}. Status is `error` iff any sub-check failed
154
191
  * (a non-conformant backend is a hard blocker, not a warning).
192
+ *
193
+ * `opts.staleEtag` overrides `probeCas`'s default S3/R2-shaped stale-etag
194
+ * sentinel — required on the native GCS path, whose generation-based
195
+ * preconditions reject a quoted-string value as malformed (400) rather
196
+ * than as a conflict (412). See `doctor.ts`'s `--bucket=gcs://` branch.
155
197
  */
156
- const doctorCas = async (storage, keyPrefix) => {
157
- const result = await probeCas(storage, { keyPrefix });
198
+ const doctorCas = async (storage, keyPrefix, opts) => {
199
+ const result = await probeCas(storage, {
200
+ keyPrefix,
201
+ ...opts?.staleEtag !== void 0 && { staleEtag: opts.staleEtag }
202
+ });
158
203
  return {
159
204
  findings: result.checks.map((c) => ({
160
205
  severity: c.ok ? "ok" : "error",
@@ -165,55 +210,7 @@ const doctorCas = async (storage, keyPrefix) => {
165
210
  status: result.ok ? "ok" : "error"
166
211
  };
167
212
  };
168
- //#endregion
169
- //#region src/runner.ts
170
- /**
171
- * `ProcessRunner` interface + default `node:child_process.spawn`-backed
172
- * implementation. Shared by `baerly deploy` and `baerly doctor`, both of
173
- * which shell out to Wrangler.
174
- *
175
- * Tests inject a mock; production uses {@link defaultRunner}. Pass
176
- * `{ tee: true }` to also write the child's stdout/stderr to the parent
177
- * process — `baerly deploy` does this so the operator sees Wrangler's
178
- * progress in real time; `baerly doctor` captures silently for parsing.
179
- */
180
- /**
181
- * Default `node:child_process.spawn`-backed runner. Inherits stdin and
182
- * captures stdout/stderr. With `tee: true` the captured bytes are also
183
- * forwarded to the parent process so the user sees the child's progress
184
- * in real time.
185
- */
186
- const defaultRunner = (opts = {}) => {
187
- const tee = opts.tee === true;
188
- return { run: (cmd, args, cwd) => new Promise((res, rej) => {
189
- const child = spawn(cmd, args, {
190
- cwd,
191
- stdio: [
192
- "inherit",
193
- "pipe",
194
- "pipe"
195
- ]
196
- });
197
- let stdout = "";
198
- let stderr = "";
199
- child.stdout?.on("data", (b) => {
200
- stdout += b.toString("utf8");
201
- if (tee) process.stdout.write(b);
202
- });
203
- child.stderr?.on("data", (b) => {
204
- stderr += b.toString("utf8");
205
- if (tee) process.stderr.write(b);
206
- });
207
- child.on("error", rej);
208
- child.on("close", (code) => res({
209
- code: code ?? 1,
210
- stdout,
211
- stderr
212
- }));
213
- }) };
214
- };
215
- //#endregion
216
- //#region ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
213
+ // ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
217
214
  /**
218
215
  * Creates a JSON scanner on the given text.
219
216
  * If ignoreTrivia is set, whitespaces or comments are ignored.
@@ -328,11 +325,13 @@ function createScanner(text, ignoreTrivia = false) {
328
325
  start = pos;
329
326
  continue;
330
327
  }
331
- if (ch >= 0 && ch <= 31) if (isLineBreak(ch)) {
332
- result += text.substring(start, pos);
333
- scanError = 2;
334
- break;
335
- } else scanError = 6;
328
+ if (ch >= 0 && ch <= 31) {
329
+ if (isLineBreak(ch)) {
330
+ result += text.substring(start, pos);
331
+ scanError = 2;
332
+ break;
333
+ } else scanError = 6;
334
+ }
336
335
  pos++;
337
336
  }
338
337
  return result;
@@ -607,8 +606,7 @@ new Array(maxCachedValues).fill(0).map((_, index) => {
607
606
  }), new Array(maxCachedValues).fill(0).map((_, index) => {
608
607
  return "\r\n" + " ".repeat(index);
609
608
  });
610
- //#endregion
611
- //#region ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/parser.js
609
+ // ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/parser.js
612
610
  var ParseOptions;
613
611
  (function(ParseOptions) {
614
612
  ParseOptions.DEFAULT = { allowTrailingComma: false };
@@ -710,9 +708,7 @@ function visit(text, visitor, options = ParseOptions.DEFAULT) {
710
708
  case 2:
711
709
  handleError(12);
712
710
  break;
713
- case 6:
714
- handleError(16);
715
- break;
711
+ case 6: handleError(16);
716
712
  }
717
713
  switch (token) {
718
714
  case 12:
@@ -856,8 +852,7 @@ function visit(text, visitor, options = ParseOptions.DEFAULT) {
856
852
  if (_scanner.getToken() !== 17) handleError(9, [], []);
857
853
  return true;
858
854
  }
859
- //#endregion
860
- //#region ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/main.js
855
+ // ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/main.js
861
856
  var ScanError;
862
857
  (function(ScanError) {
863
858
  ScanError[ScanError["None"] = 0] = "None";
@@ -912,8 +907,396 @@ var ParseErrorCode;
912
907
  ParseErrorCode[ParseErrorCode["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
913
908
  ParseErrorCode[ParseErrorCode["InvalidCharacter"] = 16] = "InvalidCharacter";
914
909
  })(ParseErrorCode || (ParseErrorCode = {}));
915
- //#endregion
916
- //#region src/wrangler-patch.ts
910
+ // src/doctor/cloudflare.ts
911
+ /**
912
+ * `baerly doctor --target=cloudflare` — walks the Cloudflare
913
+ * deploy invariants and reports. With `--fix`, remediates what
914
+ * can be safely auto-fixed (R2 bucket creation; secret prompts
915
+ * are still user-driven because `wrangler secret put` reads
916
+ * stdin interactively).
917
+ *
918
+ * Checks (each emitting one {@link DoctorFinding}):
919
+ * 1. `wrangler.jsonc` exists at the package root.
920
+ * 2. Each declared R2 binding exists in CF
921
+ * (`wrangler r2 bucket info`).
922
+ * 3. Each `requiredSecrets` entry is in `wrangler secret list`.
923
+ * 4. If `cloudflareAccess` is set in `baerly.config.ts`,
924
+ * `audienceTag` is 64 lowercase-hex chars and `teamDomain`
925
+ * is non-empty.
926
+ * 5. Report `triggers.crons` as optional. In-band write-triggered
927
+ * maintenance is the default; cron only drives an explicit
928
+ * `runScheduledMaintenance` sweep when the operator opts in.
929
+ * 6. If `baerly.config.ts:domain` is set but `wrangler.jsonc`
930
+ * doesn't declare a matching `routes` entry, warn.
931
+ *
932
+ * Output is a structured {@link DoctorReport} that
933
+ * `packages/cli/src/doctor.ts` renders as either a checklist
934
+ * (text mode) or a JSON envelope (`--json` mode).
935
+ */
936
+ const rollupStatus = (findings) => {
937
+ let worst = "ok";
938
+ for (const f of findings) {
939
+ if (f.severity === "error") return "error";
940
+ if (f.severity === "warning") worst = "warning";
941
+ }
942
+ return worst;
943
+ };
944
+ /**
945
+ * Combine several `DoctorReport`s (in order) into one: concatenate their
946
+ * findings and re-roll the overall status. Used where a single `doctor`
947
+ * run walks more than one check family — e.g. `gcs://` runs the
948
+ * backend-agnostic CAS probe plus GCS-specific bucket-config checks.
949
+ */
950
+ const mergeReports = (reports) => {
951
+ const findings = reports.flatMap((r) => [...r.findings]);
952
+ return {
953
+ findings,
954
+ status: rollupStatus(findings)
955
+ };
956
+ };
957
+ /**
958
+ * Read the declared cron schedule from `wrangler.jsonc`. Returns
959
+ * `[]` when missing — caller treats empty as ok; in-band
960
+ * write-triggered maintenance is the default and needs no cron.
961
+ */
962
+ const readDeclaredCrons = (wranglerPath) => {
963
+ const text = readFileSync(wranglerPath, "utf8");
964
+ const errors = [];
965
+ const obj = parse(text, errors, {
966
+ allowTrailingComma: true,
967
+ disallowComments: false
968
+ });
969
+ if (errors.length > 0 || obj === void 0) return [];
970
+ const crons = obj.triggers?.crons;
971
+ if (!Array.isArray(crons)) return [];
972
+ return crons.filter((c) => typeof c === "string");
973
+ };
974
+ /** Read declared `routes[].pattern` array from `wrangler.jsonc`. */
975
+ const readDeclaredRoutePatterns = (wranglerPath) => {
976
+ const text = readFileSync(wranglerPath, "utf8");
977
+ const errors = [];
978
+ const obj = parse(text, errors, {
979
+ allowTrailingComma: true,
980
+ disallowComments: false
981
+ });
982
+ if (errors.length > 0 || obj === void 0) return [];
983
+ const routes = obj.routes;
984
+ if (!Array.isArray(routes)) return [];
985
+ return routes.map((r) => r !== null && typeof r === "object" ? r.pattern : void 0).filter((p) => typeof p === "string");
986
+ };
987
+ /** Read declared `vars` keys from `wrangler.jsonc`. */
988
+ const readDeclaredVarKeys = (wranglerPath) => {
989
+ const text = readFileSync(wranglerPath, "utf8");
990
+ const errors = [];
991
+ const obj = parse(text, errors, {
992
+ allowTrailingComma: true,
993
+ disallowComments: false
994
+ });
995
+ if (errors.length > 0 || obj === void 0 || obj.vars === void 0) return [];
996
+ return Object.keys(obj.vars);
997
+ };
998
+ /**
999
+ * Walk the Cloudflare deploy invariants. With `opts.fix === true`,
1000
+ * remediate the auto-fixable issues (bucket creation). Secret
1001
+ * prompts stay user-driven.
1002
+ */
1003
+ const doctorCloudflare = async (config, opts = {}) => {
1004
+ const repoRoot = opts.cwd ?? config.repoRoot;
1005
+ const wranglerPath = resolve(repoRoot, "wrangler.jsonc");
1006
+ const findings = [];
1007
+ if (!existsSync(wranglerPath)) {
1008
+ findings.push({
1009
+ severity: "error",
1010
+ check: "wrangler.jsonc",
1011
+ message: `Expected wrangler.jsonc at the package root: ${wranglerPath}.`,
1012
+ fix: "Re-scaffold (npm create baerly@latest) or restore the file from git."
1013
+ });
1014
+ return {
1015
+ findings,
1016
+ status: rollupStatus(findings)
1017
+ };
1018
+ }
1019
+ findings.push({
1020
+ severity: "ok",
1021
+ check: "wrangler.jsonc",
1022
+ message: `${wranglerPath} found.`
1023
+ });
1024
+ let declared;
1025
+ try {
1026
+ declared = parseR2Bindings(wranglerPath);
1027
+ } catch (error) {
1028
+ if (error instanceof BaerlyError && error.code === "InvalidConfig") {
1029
+ findings.push({
1030
+ severity: "error",
1031
+ check: "wrangler.jsonc.parse",
1032
+ message: error.message
1033
+ });
1034
+ return {
1035
+ findings,
1036
+ status: rollupStatus(findings)
1037
+ };
1038
+ }
1039
+ throw error;
1040
+ }
1041
+ if (opts.fix === true && opts.runner !== void 0) try {
1042
+ await ensureBindings(opts.runner, repoRoot, wranglerPath);
1043
+ } catch (error) {
1044
+ findings.push({
1045
+ severity: "error",
1046
+ check: "r2.fix",
1047
+ message: error instanceof Error ? error.message : "unknown error during ensureBindings"
1048
+ });
1049
+ }
1050
+ if (opts.runner !== void 0) for (const { bucket_name } of declared) if ((await opts.runner.run("wrangler", [
1051
+ "r2",
1052
+ "bucket",
1053
+ "info",
1054
+ bucket_name
1055
+ ], repoRoot)).code === 0) findings.push({
1056
+ severity: "ok",
1057
+ check: `r2.${bucket_name}`,
1058
+ message: `R2 bucket "${bucket_name}" exists.`
1059
+ });
1060
+ else findings.push({
1061
+ severity: "error",
1062
+ check: `r2.${bucket_name}`,
1063
+ message: `R2 bucket "${bucket_name}" not found.`,
1064
+ fix: `wrangler r2 bucket create ${bucket_name} (or re-run with --fix)`
1065
+ });
1066
+ else findings.push({
1067
+ severity: "info",
1068
+ check: "r2.skip",
1069
+ message: "no runner supplied; skipped R2 bucket probes."
1070
+ });
1071
+ const required = config.requiredSecrets ?? ["SHARED_SECRET"];
1072
+ let configured = [];
1073
+ if (opts.runner !== void 0 && required.length > 0) {
1074
+ const r = await opts.runner.run("wrangler", ["secret", "list"], repoRoot);
1075
+ if (r.code !== 0) findings.push({
1076
+ severity: "warning",
1077
+ check: "secrets",
1078
+ message: "could not list secrets (wrangler exit non-zero); skipping check."
1079
+ });
1080
+ else {
1081
+ try {
1082
+ const parsed = JSON.parse(r.stdout);
1083
+ if (Array.isArray(parsed)) configured = parsed.map((s) => s !== null && typeof s === "object" ? s.name : void 0).filter((n) => typeof n === "string");
1084
+ } catch {}
1085
+ for (const name of required) if (configured.includes(name)) findings.push({
1086
+ severity: "ok",
1087
+ check: `secret.${name}`,
1088
+ message: `secret ${name} is set.`
1089
+ });
1090
+ else findings.push({
1091
+ severity: "warning",
1092
+ check: `secret.${name}`,
1093
+ message: `secret ${name} is required but unset.`,
1094
+ fix: `wrangler secret put ${name}`
1095
+ });
1096
+ }
1097
+ } else if (required.length > 0) findings.push({
1098
+ severity: "info",
1099
+ check: "secrets.skip",
1100
+ message: "no runner supplied; skipped secret checks."
1101
+ });
1102
+ if (config.auth === "none") findings.push({
1103
+ severity: "warning",
1104
+ check: "auth.none-on-deploy",
1105
+ message: `baerly.config.ts has auth: "none" and ships to target=${JSON.stringify(config.target)}. Every request will resolve to config.tenant with no header check. Put a network gate in front (CF Access, an upstream JWT, Cloudflare Tunnel, intranet ACL, …) or change \`auth\` to "shared-secret" or pass a custom \`verifier:\` on the adapter factory.`,
1106
+ fix: "Edit baerly.config.ts: set `auth: \"shared-secret\"` and run `wrangler secret put SHARED_SECRET`; or keep `auth: \"none\"` and wire CF Access in `wrangler.jsonc:vars` + pass a `verifier:` override in `src/server/index.ts`."
1107
+ });
1108
+ if (config.auth === "shared-secret" && opts.runner !== void 0) {
1109
+ if (!configured.includes("SHARED_SECRET")) findings.push({
1110
+ severity: "error",
1111
+ check: "auth.shared-secret-missing",
1112
+ message: SHARED_SECRET_MISSING_MESSAGE,
1113
+ fix: "wrangler secret put SHARED_SECRET (for production) or add SHARED_SECRET=<value> to .dev.vars (for `wrangler dev`)."
1114
+ });
1115
+ }
1116
+ const varKeys = new Set(readDeclaredVarKeys(wranglerPath));
1117
+ if (varKeys.has("CF_ACCESS_TEAM_DOMAIN") && varKeys.has("CF_ACCESS_AUDIENCE_TAG")) findings.push({
1118
+ severity: "info",
1119
+ check: "auth.cf-access-inert",
1120
+ message: `CF Access env vars (CF_ACCESS_TEAM_DOMAIN, CF_ACCESS_AUDIENCE_TAG) are set in ${wranglerPath} but the adapter uses config.auth=${JSON.stringify(config.auth)}. To wire CF Access, pass \`verifier: cloudflareAccess({ teamDomain, audienceTag })\` on the baerlyWorker factory.`
1121
+ });
1122
+ if (config.cloudflareAccess !== void 0) {
1123
+ const { teamDomain, audienceTag } = config.cloudflareAccess;
1124
+ const teamDomainOk = CF_ACCESS_TEAM_NAME_PATTERN.test(teamDomain);
1125
+ if (!teamDomainOk) findings.push({
1126
+ severity: "error",
1127
+ check: "cloudflareAccess.teamDomain",
1128
+ message: `cloudflareAccess.teamDomain in baerly.config.ts must be a bare team name of lowercase letters, digits and "-" (got ${JSON.stringify(teamDomain)}).`,
1129
+ fix: "Use the team name only, e.g. \"acme\" for acme.cloudflareaccess.com."
1130
+ });
1131
+ if (!/^[0-9a-f]{64}$/.test(audienceTag)) findings.push({
1132
+ severity: "error",
1133
+ check: "cloudflareAccess.audienceTag",
1134
+ message: `cloudflareAccess.audienceTag must be 64 lowercase-hex chars (got ${JSON.stringify(audienceTag)}).`,
1135
+ fix: "Copy the AUD tag from the Cloudflare Access app's configuration tab."
1136
+ });
1137
+ else if (teamDomainOk) findings.push({
1138
+ severity: "ok",
1139
+ check: "cloudflareAccess",
1140
+ message: `cloudflareAccess audience tag is well-formed; team domain "${teamDomain}".`
1141
+ });
1142
+ }
1143
+ const crons = readDeclaredCrons(wranglerPath);
1144
+ if (crons.length === 0) findings.push({
1145
+ severity: "ok",
1146
+ check: "triggers.crons",
1147
+ message: "no cron triggers declared; in-band write-triggered maintenance is the default."
1148
+ });
1149
+ else findings.push({
1150
+ severity: "info",
1151
+ check: "triggers.crons",
1152
+ message: `cron trigger${crons.length === 1 ? "" : "s"} ${crons.map((c) => JSON.stringify(c)).join(", ")} declared for opt-in scheduled maintenance; write-triggered maintenance still runs by default.`
1153
+ });
1154
+ if (config.domain !== void 0 && config.domain.length > 0) {
1155
+ const patterns = readDeclaredRoutePatterns(wranglerPath);
1156
+ const expectedPrefix = `${config.domain}/`;
1157
+ if (!patterns.some((p) => p === config.domain || p === expectedPrefix || p.startsWith(expectedPrefix))) findings.push({
1158
+ severity: "warning",
1159
+ check: "routes.domain",
1160
+ message: `baerly.config.ts declares domain ${JSON.stringify(config.domain)} but ${wranglerPath} has no matching routes[].pattern.`,
1161
+ fix: `Add { "pattern": "${config.domain}/*", "custom_domain": true } to wrangler.jsonc:routes.`
1162
+ });
1163
+ else findings.push({
1164
+ severity: "ok",
1165
+ check: "routes.domain",
1166
+ message: `routes[].pattern matches domain ${JSON.stringify(config.domain)}.`
1167
+ });
1168
+ }
1169
+ return {
1170
+ findings,
1171
+ status: rollupStatus(findings)
1172
+ };
1173
+ };
1174
+ // src/doctor/gcs.ts
1175
+ /**
1176
+ * `baerly doctor --bucket=gcs://<bucket>` — GCS-specific bucket-config
1177
+ * checks that go beyond the backend-agnostic CAS probe ({@link doctorCas}
1178
+ * in `./cas.ts`).
1179
+ *
1180
+ * Two findings, always both present:
1181
+ * 1. **Object Versioning** — an ACTIVE probe. Readable over the HMAC/XML
1182
+ * API via `GET <bucket>?versioning`, so we fetch it and warn only
1183
+ * when versioning is actually enabled (baerly's log is already an
1184
+ * append-only history; bucket versioning duplicates it at storage
1185
+ * cost). Never throws — a diagnostic must not crash on a transient
1186
+ * network error; an inconclusive probe degrades to an `info` finding.
1187
+ * 2. **Soft-delete** — a STATIC advisory, never an active probe. GCS
1188
+ * soft-delete is exposed only via the JSON API
1189
+ * (`storage/v1/b/<bucket>?fields=softDeletePolicy`), and the JSON API
1190
+ * rejects HMAC auth outright (401, demands OAuth2 Bearer). baerly's
1191
+ * native GCS adapter is HMAC-only by design, so there is no code path
1192
+ * to read it — this is an auth-model wall, not a TODO.
1193
+ */
1194
+ const versioningEnabledFix = (bucket) => `baerly's log is already an append-only history, so bucket versioning duplicates it at storage cost. Disable it unless you need object-level version recovery: \`gcloud storage buckets update gs://${bucket} --no-versioning\` (or add a lifecycle rule to expire noncurrent versions).`;
1195
+ const SOFT_DELETE_FIX = "Check it and, unless you want trash-style recovery, turn it off: `gcloud storage buckets describe gs://<bucket> --format='default(softDeletePolicy)'` then `gcloud storage buckets update gs://<bucket> --clear-soft-delete`.";
1196
+ /**
1197
+ * Inconclusive Object-Versioning probe result — a non-2xx response or a
1198
+ * thrown fetch error. `reason` is the branch-specific cause
1199
+ * (`HTTP <status>` or the caught error's message). Both branches degrade
1200
+ * to the same `info` finding, so the shape lives here once.
1201
+ */
1202
+ const versioningInconclusive = (bucket, reason) => ({
1203
+ severity: "info",
1204
+ check: "gcs-object-versioning",
1205
+ message: `Could not read Object Versioning config (${reason}). Verify manually: \`gcloud storage buckets describe gs://${bucket} --format='default(versioning)'\`.`
1206
+ });
1207
+ const probeVersioning = async (opts) => {
1208
+ const { endpoint, bucket, credentials, fetchImpl } = opts;
1209
+ const status = await gcsVersioningStatus({
1210
+ endpoint,
1211
+ bucket,
1212
+ credentials,
1213
+ fetch: fetchImpl
1214
+ });
1215
+ if (status.kind === "inconclusive") return versioningInconclusive(bucket, status.reason);
1216
+ if (status.kind === "enabled") return {
1217
+ severity: "warning",
1218
+ check: "gcs-object-versioning",
1219
+ message: `Object Versioning is enabled on "${bucket}". baerly overwrites and deletes objects during normal writes, compaction, and GC; with versioning on, every superseded or deleted object is retained as a billed noncurrent version.`,
1220
+ fix: versioningEnabledFix(bucket)
1221
+ };
1222
+ return {
1223
+ severity: "ok",
1224
+ check: "gcs-object-versioning",
1225
+ message: "Object Versioning is disabled — superseded and deleted objects are not retained."
1226
+ };
1227
+ };
1228
+ const softDeleteFinding = () => ({
1229
+ severity: "info",
1230
+ check: "gcs-soft-delete",
1231
+ message: "GCS enables soft-delete on new buckets by default (deleted objects retained ~7 days and billed). baerly's GC deletions then linger as billed soft-deleted objects. Soft-delete isn't readable over the HMAC/XML API, so this is a reminder, not a live measurement.",
1232
+ fix: SOFT_DELETE_FIX
1233
+ });
1234
+ /**
1235
+ * Walk the GCS-specific bucket-config checks: an active Object Versioning
1236
+ * probe plus a static soft-delete advisory. Never throws — every finding
1237
+ * degrades gracefully on a network failure instead of aborting the
1238
+ * surrounding `baerly doctor --bucket` walk.
1239
+ */
1240
+ const doctorGcsConfig = async (opts) => {
1241
+ const fetchImpl = opts.fetchImpl ?? globalThis.fetch.bind(globalThis);
1242
+ const findings = [await probeVersioning({
1243
+ endpoint: opts.endpoint,
1244
+ bucket: opts.bucket,
1245
+ credentials: opts.credentials,
1246
+ fetchImpl
1247
+ }), softDeleteFinding()];
1248
+ return {
1249
+ findings,
1250
+ status: rollupStatus(findings)
1251
+ };
1252
+ };
1253
+ // src/runner.ts
1254
+ /**
1255
+ * `ProcessRunner` interface + default `node:child_process.spawn`-backed
1256
+ * implementation. Shared by `baerly deploy` and `baerly doctor`, both of
1257
+ * which shell out to Wrangler.
1258
+ *
1259
+ * Tests inject a mock; production uses {@link defaultRunner}. Pass
1260
+ * `{ tee: true }` to also write the child's stdout/stderr to the parent
1261
+ * process — `baerly deploy` does this so the operator sees Wrangler's
1262
+ * progress in real time; `baerly doctor` captures silently for parsing.
1263
+ */
1264
+ /**
1265
+ * Default `node:child_process.spawn`-backed runner. Inherits stdin and
1266
+ * captures stdout/stderr. With `tee: true` the captured bytes are also
1267
+ * forwarded to the parent process so the user sees the child's progress
1268
+ * in real time.
1269
+ */
1270
+ const defaultRunner = (opts = {}) => {
1271
+ const tee = opts.tee === true;
1272
+ return { run: (cmd, args, cwd) => new Promise((res, rej) => {
1273
+ const child = spawn(cmd, args, {
1274
+ cwd,
1275
+ stdio: [
1276
+ "inherit",
1277
+ "pipe",
1278
+ "pipe"
1279
+ ]
1280
+ });
1281
+ let stdout = "";
1282
+ let stderr = "";
1283
+ child.stdout?.on("data", (b) => {
1284
+ stdout += b.toString("utf8");
1285
+ if (tee) process.stdout.write(b);
1286
+ });
1287
+ child.stderr?.on("data", (b) => {
1288
+ stderr += b.toString("utf8");
1289
+ if (tee) process.stderr.write(b);
1290
+ });
1291
+ child.on("error", rej);
1292
+ child.on("close", (code) => res({
1293
+ code: code ?? 1,
1294
+ stdout,
1295
+ stderr
1296
+ }));
1297
+ }) };
1298
+ };
1299
+ // src/wrangler-patch.ts
917
1300
  /**
918
1301
  * Surgical wrangler.jsonc helpers used by `baerly deploy` and the
919
1302
  * `@gusto/create-baerly-storage` bolt-on flow. All functions are pure (no I/O) —
@@ -951,23 +1334,19 @@ const parseR2Bindings$1 = (source) => {
951
1334
  }
952
1335
  return out;
953
1336
  };
954
- //#endregion
955
- //#region src/deploy/cloudflare.ts
1337
+ // src/deploy/cloudflare.ts
956
1338
  /**
957
1339
  * `baerly deploy --target=cloudflare` — one-command Cloudflare
958
1340
  * Workers deploy.
959
1341
  *
960
1342
  * Behavior:
961
1343
  * 1. Locate `wrangler.jsonc` at the package root.
962
- * 2. Sniff `wrangler deploy --help` for the `--x-provision` flag.
963
- * 3. When present, invoke
964
- * `wrangler deploy --x-provision --x-auto-create` and rely on
965
- * Wrangler to auto-create the declared R2 buckets.
966
- * 4. When absent, parse `wrangler.jsonc` for declared
967
- * `r2_buckets[]`, ensure each bucket exists (creating with
968
- * `wrangler r2 bucket create` when missing), then run
969
- * `wrangler deploy` without the experimental flag.
970
- * 5. Warn (non-fatal) on any `requiredSecret` not present in the
1344
+ * 2. Parse `wrangler.jsonc` for declared `r2_buckets[]` and ensure
1345
+ * each bucket exists (creating with `wrangler r2 bucket create`
1346
+ * when missing). Wrangler 4.45+ also provisions declared buckets
1347
+ * on deploy; this step covers older Wranglers and bolt-on apps.
1348
+ * 3. Run `wrangler deploy`.
1349
+ * 4. Warn (non-fatal) on any `requiredSecret` not present in the
971
1350
  * Wrangler-reported secret list.
972
1351
  *
973
1352
  * No `wrangler secret put` is invoked — that requires interactive
@@ -977,9 +1356,20 @@ const parseR2Bindings$1 = (source) => {
977
1356
  * Tests inject a {@link ProcessRunner} mock; production uses the
978
1357
  * default `node:child_process.spawn`-backed implementation.
979
1358
  */
1359
+ /**
1360
+ * The CAS-probe `staleEtag` override for a parsed bucket URI. Native GCS
1361
+ * rejects `doctorCas`'s default S3/R2-shaped quoted-string sentinel as a
1362
+ * malformed precondition (400) instead of a conflict (412), so the gcs://
1363
+ * path must feed a well-formed-but-stale generation; every other backend
1364
+ * uses `probeCas`'s default. Mirrors `doctor.ts`'s `--bucket=gcs://`
1365
+ * branch — kept as a pure function so the decision is unit-testable
1366
+ * without a live bucket.
1367
+ */
1368
+ const casProbeStaleEtag = (parsed) => parsed.gcs !== void 0 ? "1" : void 0;
980
1369
  const defaultCasProbe = async (probeBucketUri) => {
981
- const { storage, keyPrefix } = await parseBucketUri(probeBucketUri);
982
- return doctorCas(storage, keyPrefix);
1370
+ const parsed = await parseBucketUri(probeBucketUri);
1371
+ const staleEtag = casProbeStaleEtag(parsed);
1372
+ return doctorCas(parsed.storage, parsed.keyPrefix, staleEtag !== void 0 ? { staleEtag } : void 0);
983
1373
  };
984
1374
  /** Path to `wrangler.jsonc` at the package root. */
985
1375
  const wranglerPathFor = (repoRoot) => resolve(repoRoot, "wrangler.jsonc");
@@ -997,9 +1387,8 @@ const parseR2Bindings = (wranglerPath) => {
997
1387
  /**
998
1388
  * Walk the declared R2 bindings; for each, run `wrangler r2 bucket
999
1389
  * info <name>` and, on non-zero exit, `wrangler r2 bucket create
1000
- * <name>`. Used as the fallback when `wrangler --x-provision` is
1001
- * unavailable, and directly invoked by `baerly doctor
1002
- * --target=cloudflare --fix`.
1390
+ * <name>`. Run before every `baerly deploy`, and directly invoked by
1391
+ * `baerly doctor --target=cloudflare --fix`.
1003
1392
  *
1004
1393
  * @throws BaerlyError code="NetworkError" — bucket creation
1005
1394
  * reported a non-zero exit (Wrangler's own error already on
@@ -1053,8 +1442,8 @@ const warnOnMissingSecrets = async (runner, cwd, required) => {
1053
1442
  *
1054
1443
  * @throws BaerlyError code="InvalidConfig" — `wrangler.jsonc`
1055
1444
  * missing or unparseable.
1056
- * @throws BaerlyError code="NetworkError" — the fallback path
1057
- * could not create a declared R2 bucket.
1445
+ * @throws BaerlyError code="NetworkError" — `wrangler r2 bucket create`
1446
+ * failed for a declared R2 bucket.
1058
1447
  */
1059
1448
  const deployCloudflare = async (config, opts = {}) => {
1060
1449
  const runner = opts.runner ?? defaultRunner({ tee: true });
@@ -1069,19 +1458,10 @@ const deployCloudflare = async (config, opts = {}) => {
1069
1458
  }
1070
1459
  process.stderr.write(`baerly deploy: CAS preflight OK for ${opts.probeBucketUri}\n`);
1071
1460
  }
1072
- const help = await runner.run("wrangler", ["deploy", "--help"], repoRoot);
1073
- const hasXProvision = help.code === 0 && help.stdout.includes("--x-provision");
1074
1461
  await warnOnMissingSecrets(runner, repoRoot, config.requiredSecrets ?? ["SHARED_SECRET"]);
1075
- if (hasXProvision) return (await runner.run("wrangler", [
1076
- "deploy",
1077
- "--x-provision",
1078
- "--x-auto-create"
1079
- ], repoRoot)).code;
1080
- process.stderr.write("baerly deploy: wrangler --x-provision unavailable; falling back to manual provisioning\n");
1081
1462
  await ensureBindings(runner, repoRoot, wranglerPath);
1082
1463
  return (await runner.run("wrangler", ["deploy"], repoRoot)).code;
1083
1464
  };
1084
- //#endregion
1085
- export { defaultRunner as a, parse as i, ensureBindings as n, doctorCas as o, parseR2Bindings as r, deployCloudflare as t };
1465
+ export { mergeReports as a, doctorCloudflare as i, defaultRunner as n, rollupStatus as o, doctorGcsConfig as r, doctorCas as s, deployCloudflare as t };
1086
1466
 
1087
- //# sourceMappingURL=cloudflare-DzKBrUlg.js.map
1467
+ //# sourceMappingURL=cloudflare-CKHYXccw.js.map