@gusto/baerly-storage 0.4.1 → 0.6.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 (104) hide show
  1. package/dist/API.md +3 -2
  2. package/dist/CHANGELOG.md +125 -0
  3. package/dist/THIRD-PARTY-LICENSES.txt +1 -1
  4. package/dist/auth.d.ts +1 -1
  5. package/dist/aws4fetch.esm-CXE5ZbAa.js +460 -0
  6. package/dist/aws4fetch.esm-CXE5ZbAa.js.map +1 -0
  7. package/dist/baerly.js +10 -10
  8. package/dist/baerly.spec.json +1 -1
  9. package/dist/client-react.d.ts +2 -2
  10. package/dist/{client-Fe8CwB73.d.ts → client-ypCm3zjt.d.ts} +2 -2
  11. package/dist/client.d.ts +2 -2
  12. package/dist/{cloudflare-DzKBrUlg.js → cloudflare-wrVYf4bb.js} +457 -56
  13. package/dist/cloudflare-wrVYf4bb.js.map +1 -0
  14. package/dist/cloudflare.d.ts +13 -10
  15. package/dist/cloudflare.js +6 -6
  16. package/dist/cloudflare.js.map +1 -1
  17. package/dist/{config-1tv0-Yzm.js → config-B6nTy8e2.js} +435 -33
  18. package/dist/config-B6nTy8e2.js.map +1 -0
  19. package/dist/constants-CfeMWQWk.js.map +1 -1
  20. package/dist/{cost-DSMIVqzL.js → cost-_SE_SVgZ.js} +4 -4
  21. package/dist/{cost-DSMIVqzL.js.map → cost-_SE_SVgZ.js.map} +1 -1
  22. package/dist/{db-DsPkOVEH.d.ts → db-DjjthkTi.d.ts} +2 -2
  23. package/dist/{deploy-DonTr-CV.js → deploy-Di_Q01qx.js} +5 -5
  24. package/dist/deploy-Di_Q01qx.js.map +1 -0
  25. package/dist/dev-vite.d.ts +31 -27
  26. package/dist/dev-vite.js +60 -30
  27. package/dist/dev-vite.js.map +1 -1
  28. package/dist/dev.d.ts +1 -1
  29. package/dist/doctor-RWVRpvat.js +102 -0
  30. package/dist/doctor-RWVRpvat.js.map +1 -0
  31. package/dist/{dump-Bh5k26VQ.js → dump-m2vEYDNY.js} +4 -4
  32. package/dist/{dump-Bh5k26VQ.js.map → dump-m2vEYDNY.js.map} +1 -1
  33. package/dist/{export-DtF5tDIM.js → export-DenKwEQu.js} +4 -4
  34. package/dist/{export-DtF5tDIM.js.map → export-DenKwEQu.js.map} +1 -1
  35. package/dist/{fsck-D_djMO5D.js → fsck-2Vq-7-e2.js} +5 -5
  36. package/dist/{fsck-D_djMO5D.js.map → fsck-2Vq-7-e2.js.map} +1 -1
  37. package/dist/gcs-admin-Bx6xSNJj.d.ts +123 -0
  38. package/dist/gcs.d.ts +18 -0
  39. package/dist/gcs.js +2 -0
  40. package/dist/goog4-signer-Z7KnJ1su.js +321 -0
  41. package/dist/goog4-signer-Z7KnJ1su.js.map +1 -0
  42. package/dist/{http-DxM9MflO.js → http-7zT29K3P.js} +4 -4
  43. package/dist/{http-DxM9MflO.js.map → http-7zT29K3P.js.map} +1 -1
  44. package/dist/{aws4fetch.esm-p7eEzLCs.js → http-transport-BTgVCY5r.js} +24 -476
  45. package/dist/http-transport-BTgVCY5r.js.map +1 -0
  46. package/dist/http.d.ts +2 -2
  47. package/dist/http.js +2 -2
  48. package/dist/{index-BNRh23K9.d.ts → index-BHz92Acj.d.ts} +2 -2
  49. package/dist/{index-BYk9oCNf.d.ts → index-CEZKQsKt.d.ts} +3 -2
  50. package/dist/{index-B6oexfOB.d.ts → index-DP3ClvcA.d.ts} +12 -10
  51. package/dist/{index-0rZcMBwy.d.ts → index-uE-w2dgj.d.ts} +2 -2
  52. package/dist/index.d.ts +3 -3
  53. package/dist/index.js +3 -3
  54. package/dist/{inspect-6WZ-pC7-.js → inspect-BpYbH1DM.js} +5 -5
  55. package/dist/{inspect-6WZ-pC7-.js.map → inspect-BpYbH1DM.js.map} +1 -1
  56. package/dist/{log-tail-D98U1JBo.js → log-tail-QWU4wlu-.js} +3 -11
  57. package/dist/log-tail-QWU4wlu-.js.map +1 -0
  58. package/dist/{maintenance-B_e0T99L.d.ts → maintenance-BGHGt2Yg.d.ts} +2 -2
  59. package/dist/{maintenance-B4Dki6Ig.js → maintenance-DULFcpd1.js} +4 -17
  60. package/dist/maintenance-DULFcpd1.js.map +1 -0
  61. package/dist/{maintenance-C7coQp4c.js → maintenance-fEi-UZ2o.js} +5 -11
  62. package/dist/maintenance-fEi-UZ2o.js.map +1 -0
  63. package/dist/maintenance.d.ts +1 -1
  64. package/dist/maintenance.js +1 -1
  65. package/dist/node.d.ts +22 -61
  66. package/dist/node.js +4 -3
  67. package/dist/{observability-wzs3-BL_.js → observability-Ch-VQJyE.js} +85 -27
  68. package/dist/{observability-wzs3-BL_.js.map → observability-Ch-VQJyE.js.map} +1 -1
  69. package/dist/observability.d.ts +2 -2
  70. package/dist/observability.js +1 -1
  71. package/dist/{plan-a7PJHBCy.js → plan-C4qgiXSg.js} +2 -2
  72. package/dist/{plan-a7PJHBCy.js.map → plan-C4qgiXSg.js.map} +1 -1
  73. package/dist/{query-rAtXNQQB.js → query-C43r-6ib.js} +2 -2
  74. package/dist/{query-rAtXNQQB.js.map → query-C43r-6ib.js.map} +1 -1
  75. package/dist/{rebuild-index-BVzQSZlm.js → rebuild-index-BH1dc1p6.js} +4 -4
  76. package/dist/{rebuild-index-BVzQSZlm.js.map → rebuild-index-BH1dc1p6.js.map} +1 -1
  77. package/dist/{restore-R-4rbciV.js → restore-D0VYWzfP.js} +5 -5
  78. package/dist/{restore-R-4rbciV.js.map → restore-D0VYWzfP.js.map} +1 -1
  79. package/dist/{runtime-spec-_GTdeSMo.js → runtime-spec--LykAdl1.js} +2 -2
  80. package/dist/{runtime-spec-_GTdeSMo.js.map → runtime-spec--LykAdl1.js.map} +1 -1
  81. package/dist/{s3-http-B-z8th6O.d.ts → s3-http-DD5gDc7t.d.ts} +6 -4
  82. package/dist/s3.d.ts +1 -1
  83. package/dist/s3.js +1 -1
  84. package/dist/sha256-CqcKTjw9.js +22 -0
  85. package/dist/sha256-CqcKTjw9.js.map +1 -0
  86. package/dist/{src-D__mHQmQ.js → src-BMFfDUI2.js} +69 -29
  87. package/dist/src-BMFfDUI2.js.map +1 -0
  88. package/dist/{src-CYHFDrKz.js → src-DvbTEya2.js} +3 -3
  89. package/dist/{src-CYHFDrKz.js.map → src-DvbTEya2.js.map} +1 -1
  90. package/dist/{subcommand-DoDA-K7d.js → subcommand-BV68pqwJ.js} +2 -2
  91. package/dist/{subcommand-DoDA-K7d.js.map → subcommand-BV68pqwJ.js.map} +1 -1
  92. package/dist/{usage-DBV1eQHC.js → usage-BMZR8o6U.js} +3 -3
  93. package/dist/{usage-DBV1eQHC.js.map → usage-BMZR8o6U.js.map} +1 -1
  94. package/package.json +12 -6
  95. package/dist/aws4fetch.esm-p7eEzLCs.js.map +0 -1
  96. package/dist/cloudflare-DzKBrUlg.js.map +0 -1
  97. package/dist/config-1tv0-Yzm.js.map +0 -1
  98. package/dist/deploy-DonTr-CV.js.map +0 -1
  99. package/dist/doctor-DSIyCDg_.js +0 -346
  100. package/dist/doctor-DSIyCDg_.js.map +0 -1
  101. package/dist/log-tail-D98U1JBo.js.map +0 -1
  102. package/dist/maintenance-B4Dki6Ig.js.map +0 -1
  103. package/dist/maintenance-C7coQp4c.js.map +0 -1
  104. package/dist/src-D__mHQmQ.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { o as uuid, r as parseBucketUri } from "./config-1tv0-Yzm.js";
1
+ import { b as SHARED_SECRET_MISSING_MESSAGE, c as uuid, i as goog4Signer, r as parseBucketUri } from "./config-B6nTy8e2.js";
2
2
  import { o as BaerlyError } from "./baerly.js";
3
3
  import { resolve } from "node:path";
4
4
  import { existsSync, readFileSync } from "node:fs";
@@ -39,12 +39,13 @@ const probeCas = async (storage, opts) => {
39
39
  const key = `${prefix}__baerly_cas_probe__/${uuid()}`;
40
40
  const enc = new TextEncoder();
41
41
  const signal = opts?.signal;
42
+ const staleEtag = opts?.staleEtag ?? "\"baerly-cas-probe-stale\"";
42
43
  const checks = [];
43
44
  try {
44
45
  await storage.put(key, enc.encode("v1"), { signal });
45
46
  try {
46
47
  await storage.put(key, enc.encode("v2"), {
47
- ifMatch: "\"baerly-cas-probe-stale\"",
48
+ ifMatch: staleEtag,
48
49
  signal
49
50
  });
50
51
  checks.push({
@@ -129,6 +130,44 @@ const probeCas = async (storage, opts) => {
129
130
  };
130
131
  };
131
132
  //#endregion
133
+ //#region ../adapter-node/src/gcs-admin.ts
134
+ /**
135
+ * GCS bucket-administration probes over the native XML API — read-only
136
+ * config checks that fall outside the four-verb `Storage` interface.
137
+ * Kept in the adapter so GCS wire details (endpoint/URL shape, the
138
+ * `?versioning` sub-resource, the XML response, GOOG4 signing) live
139
+ * behind the adapter boundary rather than leaking into the CLI.
140
+ */
141
+ /** Case-sensitive per the GCS `?versioning` XML shape; tolerate surrounding whitespace. */
142
+ const VERSIONING_ENABLED_RE = /<Status>\s*Enabled\s*<\/Status>/;
143
+ /**
144
+ * Read a GCS bucket's Object Versioning setting over the native XML API
145
+ * (`GET <endpoint>/<bucket>?versioning`), signed with GOOG4-HMAC-SHA256.
146
+ * Never throws — a non-2xx response or a network error resolves to
147
+ * `{ kind: "inconclusive", reason }`, so callers (e.g. `baerly doctor`)
148
+ * can degrade gracefully instead of aborting.
149
+ */
150
+ async function gcsVersioningStatus(opts) {
151
+ const endpoint = (opts.endpoint ?? "https://storage.googleapis.com").replace(/\/+$/, "");
152
+ const fetchImpl = opts.fetch ?? globalThis.fetch.bind(globalThis);
153
+ const sign = goog4Signer({ credentials: opts.credentials });
154
+ const url = `${endpoint}/${opts.bucket}?versioning`;
155
+ try {
156
+ const res = await fetchImpl(await sign(new Request(url, { method: "GET" })));
157
+ if (!res.ok) return {
158
+ kind: "inconclusive",
159
+ reason: `HTTP ${res.status}`
160
+ };
161
+ const body = await res.text();
162
+ return VERSIONING_ENABLED_RE.test(body) ? { kind: "enabled" } : { kind: "disabled" };
163
+ } catch (error) {
164
+ return {
165
+ kind: "inconclusive",
166
+ reason: error instanceof Error ? error.message : String(error)
167
+ };
168
+ }
169
+ }
170
+ //#endregion
132
171
  //#region src/doctor/cas.ts
133
172
  /**
134
173
  * `baerly doctor --bucket <uri>` — live backend CAS probe.
@@ -147,14 +186,22 @@ const probeCas = async (storage, opts) => {
147
186
  * Writes throwaway sentinels and deletes them; see
148
187
  * {@link probeCas}.
149
188
  */
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.";
189
+ 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
190
  /**
152
191
  * Run the live CAS round-trip against `storage` and shape the result
153
192
  * as a {@link DoctorReport}. Status is `error` iff any sub-check failed
154
193
  * (a non-conformant backend is a hard blocker, not a warning).
194
+ *
195
+ * `opts.staleEtag` overrides `probeCas`'s default S3/R2-shaped stale-etag
196
+ * sentinel — required on the native GCS path, whose generation-based
197
+ * preconditions reject a quoted-string value as malformed (400) rather
198
+ * than as a conflict (412). See `doctor.ts`'s `--bucket=gcs://` branch.
155
199
  */
156
- const doctorCas = async (storage, keyPrefix) => {
157
- const result = await probeCas(storage, { keyPrefix });
200
+ const doctorCas = async (storage, keyPrefix, opts) => {
201
+ const result = await probeCas(storage, {
202
+ keyPrefix,
203
+ ...opts?.staleEtag !== void 0 && { staleEtag: opts.staleEtag }
204
+ });
158
205
  return {
159
206
  findings: result.checks.map((c) => ({
160
207
  severity: c.ok ? "ok" : "error",
@@ -166,53 +213,6 @@ const doctorCas = async (storage, keyPrefix) => {
166
213
  };
167
214
  };
168
215
  //#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
216
  //#region ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
217
217
  /**
218
218
  * Creates a JSON scanner on the given text.
@@ -913,6 +913,396 @@ var ParseErrorCode;
913
913
  ParseErrorCode[ParseErrorCode["InvalidCharacter"] = 16] = "InvalidCharacter";
914
914
  })(ParseErrorCode || (ParseErrorCode = {}));
915
915
  //#endregion
916
+ //#region src/doctor/cloudflare.ts
917
+ /**
918
+ * `baerly doctor --target=cloudflare` — walks the Cloudflare
919
+ * deploy invariants and reports. With `--fix`, remediates what
920
+ * can be safely auto-fixed (R2 bucket creation; secret prompts
921
+ * are still user-driven because `wrangler secret put` reads
922
+ * stdin interactively).
923
+ *
924
+ * Checks (each emitting one {@link DoctorFinding}):
925
+ * 1. `wrangler.jsonc` exists at the package root.
926
+ * 2. Each declared R2 binding exists in CF
927
+ * (`wrangler r2 bucket info`).
928
+ * 3. Each `requiredSecrets` entry is in `wrangler secret list`.
929
+ * 4. If `cloudflareAccess` is set in `baerly.config.ts`,
930
+ * `audienceTag` is 64 lowercase-hex chars and `teamDomain`
931
+ * is non-empty.
932
+ * 5. Report `triggers.crons` as optional. In-band write-triggered
933
+ * maintenance is the default; cron only drives an explicit
934
+ * `runScheduledMaintenance` sweep when the operator opts in.
935
+ * 6. If `baerly.config.ts:domain` is set but `wrangler.jsonc`
936
+ * doesn't declare a matching `routes` entry, warn.
937
+ *
938
+ * Output is a structured {@link DoctorReport} that
939
+ * `packages/cli/src/doctor.ts` renders as either a checklist
940
+ * (text mode) or a JSON envelope (`--json` mode).
941
+ */
942
+ const rollupStatus = (findings) => {
943
+ let worst = "ok";
944
+ for (const f of findings) {
945
+ if (f.severity === "error") return "error";
946
+ if (f.severity === "warning") worst = "warning";
947
+ }
948
+ return worst;
949
+ };
950
+ /**
951
+ * Combine several `DoctorReport`s (in order) into one: concatenate their
952
+ * findings and re-roll the overall status. Used where a single `doctor`
953
+ * run walks more than one check family — e.g. `gcs://` runs the
954
+ * backend-agnostic CAS probe plus GCS-specific bucket-config checks.
955
+ */
956
+ const mergeReports = (reports) => {
957
+ const findings = reports.flatMap((r) => [...r.findings]);
958
+ return {
959
+ findings,
960
+ status: rollupStatus(findings)
961
+ };
962
+ };
963
+ /**
964
+ * Read the declared cron schedule from `wrangler.jsonc`. Returns
965
+ * `[]` when missing — caller treats empty as ok; in-band
966
+ * write-triggered maintenance is the default and needs no cron.
967
+ */
968
+ const readDeclaredCrons = (wranglerPath) => {
969
+ const text = readFileSync(wranglerPath, "utf8");
970
+ const errors = [];
971
+ const obj = parse(text, errors, {
972
+ allowTrailingComma: true,
973
+ disallowComments: false
974
+ });
975
+ if (errors.length > 0 || obj === void 0) return [];
976
+ const crons = obj.triggers?.crons;
977
+ if (!Array.isArray(crons)) return [];
978
+ return crons.filter((c) => typeof c === "string");
979
+ };
980
+ /** Read declared `routes[].pattern` array from `wrangler.jsonc`. */
981
+ const readDeclaredRoutePatterns = (wranglerPath) => {
982
+ const text = readFileSync(wranglerPath, "utf8");
983
+ const errors = [];
984
+ const obj = parse(text, errors, {
985
+ allowTrailingComma: true,
986
+ disallowComments: false
987
+ });
988
+ if (errors.length > 0 || obj === void 0) return [];
989
+ const routes = obj.routes;
990
+ if (!Array.isArray(routes)) return [];
991
+ return routes.map((r) => r !== null && typeof r === "object" ? r.pattern : void 0).filter((p) => typeof p === "string");
992
+ };
993
+ /** Read declared `vars` keys from `wrangler.jsonc`. */
994
+ const readDeclaredVarKeys = (wranglerPath) => {
995
+ const text = readFileSync(wranglerPath, "utf8");
996
+ const errors = [];
997
+ const obj = parse(text, errors, {
998
+ allowTrailingComma: true,
999
+ disallowComments: false
1000
+ });
1001
+ if (errors.length > 0 || obj === void 0 || obj.vars === void 0) return [];
1002
+ return Object.keys(obj.vars);
1003
+ };
1004
+ /**
1005
+ * Walk the Cloudflare deploy invariants. With `opts.fix === true`,
1006
+ * remediate the auto-fixable issues (bucket creation). Secret
1007
+ * prompts stay user-driven.
1008
+ */
1009
+ const doctorCloudflare = async (config, opts = {}) => {
1010
+ const repoRoot = opts.cwd ?? config.repoRoot;
1011
+ const wranglerPath = resolve(repoRoot, "wrangler.jsonc");
1012
+ const findings = [];
1013
+ if (!existsSync(wranglerPath)) {
1014
+ findings.push({
1015
+ severity: "error",
1016
+ check: "wrangler.jsonc",
1017
+ message: `Expected wrangler.jsonc at the package root: ${wranglerPath}.`,
1018
+ fix: "Re-scaffold (npm create baerly@latest) or restore the file from git."
1019
+ });
1020
+ return {
1021
+ findings,
1022
+ status: rollupStatus(findings)
1023
+ };
1024
+ }
1025
+ findings.push({
1026
+ severity: "ok",
1027
+ check: "wrangler.jsonc",
1028
+ message: `${wranglerPath} found.`
1029
+ });
1030
+ let declared;
1031
+ try {
1032
+ declared = parseR2Bindings(wranglerPath);
1033
+ } catch (error) {
1034
+ if (error instanceof BaerlyError && error.code === "InvalidConfig") {
1035
+ findings.push({
1036
+ severity: "error",
1037
+ check: "wrangler.jsonc.parse",
1038
+ message: error.message
1039
+ });
1040
+ return {
1041
+ findings,
1042
+ status: rollupStatus(findings)
1043
+ };
1044
+ }
1045
+ throw error;
1046
+ }
1047
+ if (opts.fix === true && opts.runner !== void 0) try {
1048
+ await ensureBindings(opts.runner, repoRoot, wranglerPath);
1049
+ } catch (error) {
1050
+ findings.push({
1051
+ severity: "error",
1052
+ check: "r2.fix",
1053
+ message: error instanceof Error ? error.message : "unknown error during ensureBindings"
1054
+ });
1055
+ }
1056
+ if (opts.runner !== void 0) for (const { bucket_name } of declared) if ((await opts.runner.run("wrangler", [
1057
+ "r2",
1058
+ "bucket",
1059
+ "info",
1060
+ bucket_name
1061
+ ], repoRoot)).code === 0) findings.push({
1062
+ severity: "ok",
1063
+ check: `r2.${bucket_name}`,
1064
+ message: `R2 bucket "${bucket_name}" exists.`
1065
+ });
1066
+ else findings.push({
1067
+ severity: "error",
1068
+ check: `r2.${bucket_name}`,
1069
+ message: `R2 bucket "${bucket_name}" not found.`,
1070
+ fix: `wrangler r2 bucket create ${bucket_name} (or re-run with --fix)`
1071
+ });
1072
+ else findings.push({
1073
+ severity: "info",
1074
+ check: "r2.skip",
1075
+ message: "no runner supplied; skipped R2 bucket probes."
1076
+ });
1077
+ const required = config.requiredSecrets ?? ["SHARED_SECRET"];
1078
+ let configured = [];
1079
+ if (opts.runner !== void 0 && required.length > 0) {
1080
+ const r = await opts.runner.run("wrangler", ["secret", "list"], repoRoot);
1081
+ if (r.code !== 0) findings.push({
1082
+ severity: "warning",
1083
+ check: "secrets",
1084
+ message: "could not list secrets (wrangler exit non-zero); skipping check."
1085
+ });
1086
+ else {
1087
+ try {
1088
+ const parsed = JSON.parse(r.stdout);
1089
+ if (Array.isArray(parsed)) configured = parsed.map((s) => s !== null && typeof s === "object" ? s.name : void 0).filter((n) => typeof n === "string");
1090
+ } catch {}
1091
+ for (const name of required) if (configured.includes(name)) findings.push({
1092
+ severity: "ok",
1093
+ check: `secret.${name}`,
1094
+ message: `secret ${name} is set.`
1095
+ });
1096
+ else findings.push({
1097
+ severity: "warning",
1098
+ check: `secret.${name}`,
1099
+ message: `secret ${name} is required but unset.`,
1100
+ fix: `wrangler secret put ${name}`
1101
+ });
1102
+ }
1103
+ } else if (required.length > 0) findings.push({
1104
+ severity: "info",
1105
+ check: "secrets.skip",
1106
+ message: "no runner supplied; skipped secret checks."
1107
+ });
1108
+ if (config.auth === "none") findings.push({
1109
+ severity: "warning",
1110
+ check: "auth.none-on-deploy",
1111
+ 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.`,
1112
+ 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`."
1113
+ });
1114
+ if (config.auth === "shared-secret" && opts.runner !== void 0) {
1115
+ if (!configured.includes("SHARED_SECRET")) findings.push({
1116
+ severity: "error",
1117
+ check: "auth.shared-secret-missing",
1118
+ message: SHARED_SECRET_MISSING_MESSAGE,
1119
+ fix: "wrangler secret put SHARED_SECRET (for production) or add SHARED_SECRET=<value> to .dev.vars (for `wrangler dev`)."
1120
+ });
1121
+ }
1122
+ const varKeys = new Set(readDeclaredVarKeys(wranglerPath));
1123
+ if (varKeys.has("CF_ACCESS_TEAM_DOMAIN") && varKeys.has("CF_ACCESS_AUDIENCE_TAG")) findings.push({
1124
+ severity: "info",
1125
+ check: "auth.cf-access-inert",
1126
+ 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.`
1127
+ });
1128
+ if (config.cloudflareAccess !== void 0) {
1129
+ const { teamDomain, audienceTag } = config.cloudflareAccess;
1130
+ if (teamDomain.length === 0) findings.push({
1131
+ severity: "error",
1132
+ check: "cloudflareAccess.teamDomain",
1133
+ message: "cloudflareAccess.teamDomain in baerly.config.ts is empty."
1134
+ });
1135
+ if (!/^[0-9a-f]{64}$/.test(audienceTag)) findings.push({
1136
+ severity: "error",
1137
+ check: "cloudflareAccess.audienceTag",
1138
+ message: `cloudflareAccess.audienceTag must be 64 lowercase-hex chars (got ${JSON.stringify(audienceTag)}).`,
1139
+ fix: "Copy the AUD tag from the Cloudflare Access app's configuration tab."
1140
+ });
1141
+ else if (teamDomain.length > 0) findings.push({
1142
+ severity: "ok",
1143
+ check: "cloudflareAccess",
1144
+ message: `cloudflareAccess audience tag is well-formed; team domain "${teamDomain}".`
1145
+ });
1146
+ }
1147
+ const crons = readDeclaredCrons(wranglerPath);
1148
+ if (crons.length === 0) findings.push({
1149
+ severity: "ok",
1150
+ check: "triggers.crons",
1151
+ message: "no cron triggers declared; in-band write-triggered maintenance is the default."
1152
+ });
1153
+ else findings.push({
1154
+ severity: "info",
1155
+ check: "triggers.crons",
1156
+ 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.`
1157
+ });
1158
+ if (config.domain !== void 0 && config.domain.length > 0) {
1159
+ const patterns = readDeclaredRoutePatterns(wranglerPath);
1160
+ const expectedPrefix = `${config.domain}/`;
1161
+ if (!patterns.some((p) => p === config.domain || p === expectedPrefix || p.startsWith(expectedPrefix))) findings.push({
1162
+ severity: "warning",
1163
+ check: "routes.domain",
1164
+ message: `baerly.config.ts declares domain ${JSON.stringify(config.domain)} but ${wranglerPath} has no matching routes[].pattern.`,
1165
+ fix: `Add { "pattern": "${config.domain}/*", "custom_domain": true } to wrangler.jsonc:routes.`
1166
+ });
1167
+ else findings.push({
1168
+ severity: "ok",
1169
+ check: "routes.domain",
1170
+ message: `routes[].pattern matches domain ${JSON.stringify(config.domain)}.`
1171
+ });
1172
+ }
1173
+ return {
1174
+ findings,
1175
+ status: rollupStatus(findings)
1176
+ };
1177
+ };
1178
+ //#endregion
1179
+ //#region src/doctor/gcs.ts
1180
+ /**
1181
+ * `baerly doctor --bucket=gcs://<bucket>` — GCS-specific bucket-config
1182
+ * checks that go beyond the backend-agnostic CAS probe ({@link doctorCas}
1183
+ * in `./cas.ts`).
1184
+ *
1185
+ * Two findings, always both present:
1186
+ * 1. **Object Versioning** — an ACTIVE probe. Readable over the HMAC/XML
1187
+ * API via `GET <bucket>?versioning`, so we fetch it and warn only
1188
+ * when versioning is actually enabled (baerly's log is already an
1189
+ * append-only history; bucket versioning duplicates it at storage
1190
+ * cost). Never throws — a diagnostic must not crash on a transient
1191
+ * network error; an inconclusive probe degrades to an `info` finding.
1192
+ * 2. **Soft-delete** — a STATIC advisory, never an active probe. GCS
1193
+ * soft-delete is exposed only via the JSON API
1194
+ * (`storage/v1/b/<bucket>?fields=softDeletePolicy`), and the JSON API
1195
+ * rejects HMAC auth outright (401, demands OAuth2 Bearer). baerly's
1196
+ * native GCS adapter is HMAC-only by design, so there is no code path
1197
+ * to read it — this is an auth-model wall, not a TODO.
1198
+ */
1199
+ 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).`;
1200
+ 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`.";
1201
+ /**
1202
+ * Inconclusive Object-Versioning probe result — a non-2xx response or a
1203
+ * thrown fetch error. `reason` is the branch-specific cause
1204
+ * (`HTTP <status>` or the caught error's message). Both branches degrade
1205
+ * to the same `info` finding, so the shape lives here once.
1206
+ */
1207
+ const versioningInconclusive = (bucket, reason) => ({
1208
+ severity: "info",
1209
+ check: "gcs-object-versioning",
1210
+ message: `Could not read Object Versioning config (${reason}). Verify manually: \`gcloud storage buckets describe gs://${bucket} --format='default(versioning)'\`.`
1211
+ });
1212
+ const probeVersioning = async (opts) => {
1213
+ const { endpoint, bucket, credentials, fetchImpl } = opts;
1214
+ const status = await gcsVersioningStatus({
1215
+ endpoint,
1216
+ bucket,
1217
+ credentials,
1218
+ fetch: fetchImpl
1219
+ });
1220
+ if (status.kind === "inconclusive") return versioningInconclusive(bucket, status.reason);
1221
+ if (status.kind === "enabled") return {
1222
+ severity: "warning",
1223
+ check: "gcs-object-versioning",
1224
+ 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.`,
1225
+ fix: versioningEnabledFix(bucket)
1226
+ };
1227
+ return {
1228
+ severity: "ok",
1229
+ check: "gcs-object-versioning",
1230
+ message: "Object Versioning is disabled — superseded and deleted objects are not retained."
1231
+ };
1232
+ };
1233
+ const softDeleteFinding = () => ({
1234
+ severity: "info",
1235
+ check: "gcs-soft-delete",
1236
+ 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.",
1237
+ fix: SOFT_DELETE_FIX
1238
+ });
1239
+ /**
1240
+ * Walk the GCS-specific bucket-config checks: an active Object Versioning
1241
+ * probe plus a static soft-delete advisory. Never throws — every finding
1242
+ * degrades gracefully on a network failure instead of aborting the
1243
+ * surrounding `baerly doctor --bucket` walk.
1244
+ */
1245
+ const doctorGcsConfig = async (opts) => {
1246
+ const fetchImpl = opts.fetchImpl ?? globalThis.fetch.bind(globalThis);
1247
+ const findings = [await probeVersioning({
1248
+ endpoint: opts.endpoint,
1249
+ bucket: opts.bucket,
1250
+ credentials: opts.credentials,
1251
+ fetchImpl
1252
+ }), softDeleteFinding()];
1253
+ return {
1254
+ findings,
1255
+ status: rollupStatus(findings)
1256
+ };
1257
+ };
1258
+ //#endregion
1259
+ //#region src/runner.ts
1260
+ /**
1261
+ * `ProcessRunner` interface + default `node:child_process.spawn`-backed
1262
+ * implementation. Shared by `baerly deploy` and `baerly doctor`, both of
1263
+ * which shell out to Wrangler.
1264
+ *
1265
+ * Tests inject a mock; production uses {@link defaultRunner}. Pass
1266
+ * `{ tee: true }` to also write the child's stdout/stderr to the parent
1267
+ * process — `baerly deploy` does this so the operator sees Wrangler's
1268
+ * progress in real time; `baerly doctor` captures silently for parsing.
1269
+ */
1270
+ /**
1271
+ * Default `node:child_process.spawn`-backed runner. Inherits stdin and
1272
+ * captures stdout/stderr. With `tee: true` the captured bytes are also
1273
+ * forwarded to the parent process so the user sees the child's progress
1274
+ * in real time.
1275
+ */
1276
+ const defaultRunner = (opts = {}) => {
1277
+ const tee = opts.tee === true;
1278
+ return { run: (cmd, args, cwd) => new Promise((res, rej) => {
1279
+ const child = spawn(cmd, args, {
1280
+ cwd,
1281
+ stdio: [
1282
+ "inherit",
1283
+ "pipe",
1284
+ "pipe"
1285
+ ]
1286
+ });
1287
+ let stdout = "";
1288
+ let stderr = "";
1289
+ child.stdout?.on("data", (b) => {
1290
+ stdout += b.toString("utf8");
1291
+ if (tee) process.stdout.write(b);
1292
+ });
1293
+ child.stderr?.on("data", (b) => {
1294
+ stderr += b.toString("utf8");
1295
+ if (tee) process.stderr.write(b);
1296
+ });
1297
+ child.on("error", rej);
1298
+ child.on("close", (code) => res({
1299
+ code: code ?? 1,
1300
+ stdout,
1301
+ stderr
1302
+ }));
1303
+ }) };
1304
+ };
1305
+ //#endregion
916
1306
  //#region src/wrangler-patch.ts
917
1307
  /**
918
1308
  * Surgical wrangler.jsonc helpers used by `baerly deploy` and the
@@ -977,9 +1367,20 @@ const parseR2Bindings$1 = (source) => {
977
1367
  * Tests inject a {@link ProcessRunner} mock; production uses the
978
1368
  * default `node:child_process.spawn`-backed implementation.
979
1369
  */
1370
+ /**
1371
+ * The CAS-probe `staleEtag` override for a parsed bucket URI. Native GCS
1372
+ * rejects `doctorCas`'s default S3/R2-shaped quoted-string sentinel as a
1373
+ * malformed precondition (400) instead of a conflict (412), so the gcs://
1374
+ * path must feed a well-formed-but-stale generation; every other backend
1375
+ * uses `probeCas`'s default. Mirrors `doctor.ts`'s `--bucket=gcs://`
1376
+ * branch — kept as a pure function so the decision is unit-testable
1377
+ * without a live bucket.
1378
+ */
1379
+ const casProbeStaleEtag = (parsed) => parsed.gcs !== void 0 ? "1" : void 0;
980
1380
  const defaultCasProbe = async (probeBucketUri) => {
981
- const { storage, keyPrefix } = await parseBucketUri(probeBucketUri);
982
- return doctorCas(storage, keyPrefix);
1381
+ const parsed = await parseBucketUri(probeBucketUri);
1382
+ const staleEtag = casProbeStaleEtag(parsed);
1383
+ return doctorCas(parsed.storage, parsed.keyPrefix, staleEtag !== void 0 ? { staleEtag } : void 0);
983
1384
  };
984
1385
  /** Path to `wrangler.jsonc` at the package root. */
985
1386
  const wranglerPathFor = (repoRoot) => resolve(repoRoot, "wrangler.jsonc");
@@ -1082,6 +1483,6 @@ const deployCloudflare = async (config, opts = {}) => {
1082
1483
  return (await runner.run("wrangler", ["deploy"], repoRoot)).code;
1083
1484
  };
1084
1485
  //#endregion
1085
- export { defaultRunner as a, parse as i, ensureBindings as n, doctorCas as o, parseR2Bindings as r, deployCloudflare as t };
1486
+ export { mergeReports as a, doctorCloudflare as i, defaultRunner as n, doctorCas as o, doctorGcsConfig as r, deployCloudflare as t };
1086
1487
 
1087
- //# sourceMappingURL=cloudflare-DzKBrUlg.js.map
1488
+ //# sourceMappingURL=cloudflare-wrVYf4bb.js.map