@zabaca/zbc 0.10.7 → 0.10.9

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zabaca/zbc",
3
- "version": "0.10.7",
3
+ "version": "0.10.9",
4
4
  "description": "Zabaca stack CLI — scaffold and deploy infrastructure",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -220,6 +220,62 @@ async function ensureDestinationVerified(
220
220
  )
221
221
  }
222
222
 
223
+ /** Recorded in outputs when the API carried no status for a record. */
224
+ const UNREPORTED = 'unreported'
225
+
226
+ /** One record as the Sending API returned it, plus how it should be labelled. */
227
+ export interface SendingDnsReading {
228
+ /** `MX cf-bounce.example.com` — what a warning prints. */
229
+ key: string
230
+ /** The status Cloudflare reported, or `null` when it reported none. */
231
+ status: string | null
232
+ }
233
+
234
+ /**
235
+ * Read one Sending DNS record.
236
+ *
237
+ * The API is beta and its field names have moved, so this reads defensively —
238
+ * but the defensiveness stops at the LABEL. `type` and `name` fall back to
239
+ * placeholders because a wrong guess there only mislabels a line. `status` does
240
+ * not fall back at all: it returns `null` when the API carried none, because the
241
+ * previous `?? 'unknown'` produced a string the caller then compared against
242
+ * active|verified|locked, failed, and printed as `Sending DNS pending`.
243
+ *
244
+ * That turned "I could not find the field" into a claim about the customer's
245
+ * DNS. On one zone it fired on all four records — MX, SPF, DKIM, DMARC — every
246
+ * apply, while every record resolved correctly and the domain published
247
+ * `p=reject`, under which unaligned mail is refused rather than delivered. Mail
248
+ * was flowing the whole time. Absence and failure are different answers and only
249
+ * one of them is about DNS.
250
+ */
251
+ export function readSendingDnsRecord(
252
+ record: Record<string, unknown>,
253
+ domain: string,
254
+ ): SendingDnsReading {
255
+ const reported = record.status ?? record.state
256
+ return {
257
+ key: `${String(record.type ?? 'record')} ${String(record.name ?? domain)}`,
258
+ status: reported === undefined || reported === null ? null : String(reported),
259
+ }
260
+ }
261
+
262
+ /** A status Cloudflare reports for a record that is live and serving. */
263
+ const LIVE = new Set(['active', 'verified', 'locked'])
264
+
265
+ export interface SendingDnsVerdict {
266
+ /** Reported as something other than live. A real warning. */
267
+ pending: SendingDnsReading[]
268
+ /** Carried no status. The module's blind spot, not a fact about the zone. */
269
+ unreported: SendingDnsReading[]
270
+ }
271
+
272
+ export function classifySendingDns(readings: SendingDnsReading[]): SendingDnsVerdict {
273
+ return {
274
+ pending: readings.filter((r) => r.status !== null && !LIVE.has(r.status)),
275
+ unreported: readings.filter((r) => r.status === null),
276
+ }
277
+ }
278
+
223
279
  export const cloudflareEmailModule = defineModule({
224
280
  name: 'cloudflare-email',
225
281
  configSchema: z.object({
@@ -286,13 +342,18 @@ export const cloudflareEmailModule = defineModule({
286
342
  ? (dns as Array<Record<string, unknown>>)
287
343
  : (((dns as Record<string, unknown>)?.['records'] as Array<Record<string, unknown>>) ??
288
344
  [])
289
- for (const r of records) {
290
- const key = `${String(r.type ?? 'record')} ${String(r.name ?? domain)}`
291
- const status = String(r.status ?? r.state ?? 'unknown')
292
- dnsStatus[key] = status
293
- if (status !== 'active' && status !== 'verified' && status !== 'locked') {
294
- console.log(` ⚠ Sending DNS pending: ${key} → ${status}`)
295
- }
345
+ const readings = records.map((r) => readSendingDnsRecord(r, domain))
346
+ const verdict = classifySendingDns(readings)
347
+ for (const r of readings) dnsStatus[r.key] = r.status ?? UNREPORTED
348
+ for (const r of verdict.pending) {
349
+ console.log(` ⚠ Sending DNS pending: ${r.key} → ${r.status}`)
350
+ }
351
+ if (verdict.unreported.length > 0) {
352
+ // Said once, and not as a warning: the records may be perfectly fine.
353
+ console.log(
354
+ ` Sending DNS: the API reported no status for ${verdict.unreported.length} record(s) ` +
355
+ `— not a claim about the zone; check them with dig if in doubt`,
356
+ )
296
357
  }
297
358
  } catch (err) {
298
359
  console.log(` ⚠ Could not read sending DNS status: ${(err as Error).message}`)
@@ -421,7 +482,7 @@ export const cloudflareEmailModule = defineModule({
421
482
  }
422
483
 
423
484
  const pending = Object.entries(dnsStatus).filter(
424
- ([, s]) => s !== 'active' && s !== 'verified' && s !== 'locked',
485
+ ([, s]) => s !== UNREPORTED && s !== 'active' && s !== 'verified' && s !== 'locked',
425
486
  )
426
487
  if (pending.length > 0) {
427
488
  console.log(
@@ -65,7 +65,27 @@ export function renderProvisionScript(input: {
65
65
  )
66
66
  }
67
67
 
68
- lines.push(input.script)
68
+ // The declared script runs in a SUBSHELL, so an `exit` inside it ends the
69
+ // script and not the payload.
70
+ //
71
+ // Consumers append a marker write after this string (see `markerWrite`) and
72
+ // rely on `set -e` to skip it when the script fails. The comment at those call
73
+ // sites — "only reached if everything above succeeded" — anticipates failure
74
+ // and not a success path that exits. A readiness poll ending in `exit 0` is a
75
+ // natural thing to write and it took the marker with it: on one consumer the
76
+ // provision re-ran on every apply for eight days, restarting a live service
77
+ // each time, while the module read exit code 0 and reported "provisioned".
78
+ // A missing marker is indistinguishable from a first run, so nothing noticed.
79
+ //
80
+ // `set -e` still aborts on a non-zero subshell, so a failing script records
81
+ // nothing exactly as before. What the subshell costs is that the script can no
82
+ // longer alter the payload's own environment — nothing follows it but the
83
+ // marker write, which needs nothing from it.
84
+ //
85
+ // An empty script is left unwrapped: `(` followed by `)` with nothing between
86
+ // them is a bash syntax error, and rendering something unparseable would turn
87
+ // a no-op into a failed apply.
88
+ lines.push(input.script.trim() === '' ? input.script : `(\n${input.script}\n)`)
69
89
  return `${lines.join('\n')}\n`
70
90
  }
71
91