@blamejs/core 0.17.20 → 0.17.21

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/CHANGELOG.md CHANGED
@@ -8,6 +8,8 @@ upgrading across more than a few patches at a time.
8
8
 
9
9
  ## v0.17.x
10
10
 
11
+ - v0.17.21 (2026-07-25) — **`blamejs erase` treats only `--confirm true` as confirmation, so `--confirm false` no longer triggers the irreversible erase.** Three fixes to the blamejs command line. The `erase` subcommand (a cryptographic single-row erase) gated its irreversible action on a bare-truthiness check, so `--confirm false` -- a string -- counted as confirmation and the erase proceeded; the gate now accepts only `true` / "true", matching `audit purge`, and refuses anything else. A stray `-v` / `--version` token alongside a subcommand no longer short-circuits to the version print: `blamejs migrate up --db x -v` previously returned 0 after printing the version without running the migration, handing automation a false pass; the version flag is now honored only when it is the whole invocation. And `blamejs dev` now survives a crash of the watched child -- it stays up to hot-restart on the next file change instead of draining the event loop and exiting 0 -- and awaits the child's full termination on SIGINT/SIGTERM so a shutdown cannot orphan it. **Fixed:** *blamejs erase refuses --confirm false instead of performing the irreversible erase* — The erase subcommand confirmed its irreversible action with a bare-truthiness check, so the string `--confirm false` was treated as confirmation and the erase ran. Confirmation is now satisfied only by `--confirm true` (or the bare `--confirm`), matching the check `audit purge` already used; any other value -- including `false` -- is refused with a non-zero exit and no erase. A shared confirmation helper backs every destructive subcommand so the acknowledgement contract cannot drift between them. · *A stray -v / --version no longer turns a subcommand into a silent no-op* — The top-level version flag was evaluated before subcommand dispatch and returned 0 whenever `-v` / `--version` appeared anywhere in the arguments, so a consequential command such as `migrate up`, `seed run`, or `erase` alongside a stray `-v` printed the version and exited 0 without doing anything -- a false success for any script checking the exit code. The version flag is now honored only when the invocation carries no subcommand; otherwise the subcommand runs (or fails) as written. · *blamejs dev survives a watched-child crash and shuts the child down cleanly* — The dev supervisor held the event loop open with an unref'd timer, so when the watched child process crashed the supervisor drained the loop and exited 0 -- defeating crash-resilience (it should stay up and hot-restart on the next file change) and reporting success even though the app had crashed. It now holds a referenced heartbeat so a child crash leaves the supervisor running, and on SIGINT/SIGTERM it awaits the child's full termination (graceful signal, then escalation) before exiting, so a shutdown can no longer race ahead and orphan the child.
12
+
11
13
  - v0.17.20 (2026-07-24) — **`b.forms.validate` enforces required checkboxes server-side and rejects malformed field bounds, closing two validation gaps.** b.forms.validate previously let an unchecked required checkbox pass: the renderer emits the HTML `required` attribute for it, but the server-side validator skipped the check, so a client that omitted the box -- or any non-browser caller -- bypassed a constraint the form advertised. It now rejects an unchecked required checkbox, keeping backend validation in lock-step with what the form displays. Separately, a field whose numeric bound (min/max/minlength/maxlength) was not a finite number went silently unenforced -- a NaN comparison is always false -- so the bound became a no-op; validate now throws on such a spec at the entry point, the same way it already rejects a non-precompiled regex pattern. Two smaller fixes: a field rendered without an explicit type now emits type="text" (matching the widget it dispatches to) rather than an empty type attribute, and b.externalDb reports EXPLAIN statements as row-returning so a query plan's rows are not dropped by the local-execution row/no-row chooser. **Changed:** *b.forms.validate option reference corrected* — The validate() reference described length bounds as minLength/maxLength, but the option keys are the HTML-attribute spellings minlength/maxlength (the same keys the renderer reads); the reference and its example are corrected, and the example now uses a numeric min bound on its number field. · *Vendored Public Suffix List refreshed to the current snapshot* — The bundled Public Suffix List that backs domain classification (registrable-domain and public-suffix checks in URL, cookie, and SSRF handling) is updated to the latest upstream publicsuffix.org snapshot, so newly delegated public suffixes and private-domain entries are recognized. **Fixed:** *Required checkboxes are enforced server-side in b.forms.validate* — A checkbox marked required is rendered with the HTML `required` attribute, but validate() treated an unchecked box (which coerces to false) as satisfying the field, so an unchecked required checkbox passed. Any caller that skipped the box -- a scripted client, or a browser with the constraint stripped -- bypassed a documented requirement. validate() now returns an error for an unchecked required checkbox (honouring the field's errorMessages.required), so the backend enforces the same constraint the frontend shows. A form that relied on the previous pass-through for an unchecked required checkbox will now surface a validation error, which is the intended behaviour. · *A malformed numeric field bound is rejected instead of silently ignored* — When a field's min, max, minlength, or maxlength was not a finite number (a non-numeric string, NaN, or Infinity), its comparison could never fire -- a NaN comparison is always false -- so the bound was quietly unenforced while appearing to constrain the field. validate() now throws at the entry point when a defined bound is non-finite, matching how it already requires pattern to be a pre-compiled RegExp. Numeric-string bounds (e.g. min: "1") remain accepted. · *A typeless field renders type="text" instead of an empty type attribute* — b.forms.render dispatches a field with no explicit type to a text input, but the emitted markup carried type="" rather than type="text". The rendered type attribute now matches the widget dispatched, so the markup is self-consistent. · *b.externalDb reports EXPLAIN statements as row-returning* — statementReturnsRows classified a plain EXPLAIN (and an EXPLAIN ANALYZE wrapping a write) as producing no row set, so the local-execution path could route it to a no-row call and drop the query plan. EXPLAIN always returns plan rows to the caller; it is now reported as row-returning whenever its prefix resolves, while an unparseable EXPLAIN prefix stays fail-closed. This is distinct from the cross-border residency read/write classification, which is unchanged.
12
14
 
13
15
  - v0.17.19 (2026-07-24) — **The error and adversarial paths of the sanctions-screening, JSON Schema, and HTTP client primitives are now under test.** This release adds no behaviour change. The fail-closed error paths, boundary conditions, and adversarial-input handling of b.complianceSanctions, b.jsonSchema, and b.httpClient -- previously exercised only on their happy paths -- are now asserted, verifying that each rejects malformed input, unresolvable references, and edge cases the documented contract already promised. No defects were found; the primitives behaved as specified. Genuinely-unreachable defensive fallbacks are documented rather than contorted into coverage. **Changed:** *Verified error-path behaviour for sanctions screening, JSON Schema, and the HTTP client* — The sanctions-screening list parsers (OFAC SDN/alias, EU CSL, UN 1267), the fuzzy/exact match strategy toggle, and the entry normalizer; the JSON Schema $ref/$dynamicRef resolution, JSON-pointer traversal, format assertions, and unevaluated-properties/items handling; and the HTTP client's error, redirect, and stream branches now have explicit tests for their failure and boundary behaviour. Behaviour is unchanged -- these assert guarantees the primitives already met -- so no migration is needed; the value is regression protection for the fail-closed paths of security-relevant primitives.
package/lib/arg-parser.js CHANGED
@@ -625,7 +625,7 @@ function create(opts) {
625
625
 
626
626
  /**
627
627
  * @primitive b.argParser.parseRaw
628
- * @signature b.argParser.parseRaw(argv)
628
+ * @signature b.argParser.parseRaw(argv, opts?)
629
629
  * @since 0.8.48
630
630
  * @status stable
631
631
  * @related b.argParser.create
@@ -638,12 +638,21 @@ function create(opts) {
638
638
  * value`, `--key=value`, and bare `--bool`. `--` terminates flag
639
639
  * parsing.
640
640
  *
641
+ * Pass `opts.booleanNames` (an array of long-flag names) to declare flags
642
+ * that never consume a following token as their value — a bare
643
+ * `--version` stays boolean instead of swallowing the next token, so
644
+ * `--version foo` yields `flags.version === true` with `foo` left as a
645
+ * positional. An inline `--version=x` still records the explicit value.
646
+ *
641
647
  * A flag repeated on the command line accumulates every occurrence into
642
648
  * an array, in order — `--watch a --watch b` yields `["a", "b"]`, not
643
649
  * just the last value. A flag seen once stays a scalar. This keeps
644
650
  * repeatable flags (the `dev` command's `--arg` / `--watch` / `--ignore`)
645
651
  * from silently dropping all but the final occurrence.
646
652
  *
653
+ * @opts
654
+ * booleanNames: string[], // long-flag names that never consume a following token as a value (default: none)
655
+ *
647
656
  * @example
648
657
  * var r = b.argParser.parseRaw(
649
658
  * ["build", "--target=node", "-v", "--out", "dist", "--", "extra"]);
@@ -670,11 +679,21 @@ function _assignFlag(flags, name, val) {
670
679
  }
671
680
  }
672
681
 
673
- function parseRaw(argv) {
682
+ function parseRaw(argv, opts) {
674
683
  if (!Array.isArray(argv)) {
675
684
  throw new ArgParserError("arg-parser/argv-not-array",
676
685
  "argv must be an array of strings");
677
686
  }
687
+ opts = opts || {};
688
+ // Long-flag names declared boolean never consume a following token as a
689
+ // value (a bare `--version` stays true instead of swallowing the next
690
+ // token). Inline `--flag=value` still records the explicit value.
691
+ var booleanNames = Object.create(null);
692
+ if (Array.isArray(opts.booleanNames)) {
693
+ for (var bn = 0; bn < opts.booleanNames.length; bn++) {
694
+ booleanNames[opts.booleanNames[bn]] = true;
695
+ }
696
+ }
678
697
  var pos = [];
679
698
  var flags = Object.create(null);
680
699
  for (var i = 0; i < argv.length; i++) {
@@ -694,7 +713,8 @@ function parseRaw(argv) {
694
713
  if (eq !== -1) {
695
714
  val = name.slice(eq + 1);
696
715
  name = name.slice(0, eq);
697
- } else if (i + 1 < argv.length && argv[i + 1].indexOf("--") !== 0) {
716
+ } else if (i + 1 < argv.length && argv[i + 1].indexOf("--") !== 0 &&
717
+ booleanNames[name] !== true) {
698
718
  val = argv[++i];
699
719
  } else {
700
720
  val = true;
package/lib/cli.js CHANGED
@@ -84,7 +84,12 @@ function _writeLine(stream, line) {
84
84
  // written flag validation continues to read the same { pos, flags }
85
85
  // shape the cli has always exposed.
86
86
  function _parseArgs(argv) {
87
- return argParser.parseRaw(argv);
87
+ // `--version` is the global boolean version flag — declare it so it never
88
+ // swallows a following token as its value. Without this, `--version <cmd>`
89
+ // (or `<cmd> --version <sub>`) would consume the subcommand and a stray
90
+ // version flag could no-op the command it accompanies. (`-v` is a
91
+ // single-dash flag and is already boolean in parseRaw.)
92
+ return argParser.parseRaw(argv, { booleanNames: ["version"] });
88
93
  }
89
94
 
90
95
  function _resolvePath(p, cwd) {
@@ -93,6 +98,16 @@ function _resolvePath(p, cwd) {
93
98
  return nodePath.resolve(cwd || process.cwd(), p);
94
99
  }
95
100
 
101
+ // A destructive command's --confirm gate is satisfied ONLY by an explicit
102
+ // `true` / "true"; a bare-truthiness check (`!flags.confirm`) would accept
103
+ // `--confirm false` as confirmation, so an operator who typed `--confirm
104
+ // false` — meaning "do NOT proceed" — would still trigger an irreversible
105
+ // operation. Shared by every destructive subcommand so the acknowledgement
106
+ // contract can't drift between them.
107
+ function _isConfirmed(flags) {
108
+ return flags.confirm === true || flags.confirm === "true";
109
+ }
110
+
96
111
  function _openSqlite(dbPath) {
97
112
  // Lazy-required so the CLI doesn't crash on `blamejs version` or
98
113
  // `blamejs help` if node:sqlite isn't usable for some reason.
@@ -424,7 +439,7 @@ async function _runDev(args, ctx) {
424
439
  }
425
440
  var killSignal = args.flags["kill-signal"];
426
441
 
427
- var d = dev.create({
442
+ var d = (ctx._dev || dev.create)({
428
443
  command: String(command),
429
444
  args: argList,
430
445
  watch: watchList.length ? watchList : undefined,
@@ -435,31 +450,51 @@ async function _runDev(args, ctx) {
435
450
  env: ctx.env,
436
451
  });
437
452
 
438
- // Forward parent SIGINT/SIGTERM to the child via stop()
453
+ // Forward parent SIGINT/SIGTERM to the child via stop(). The supervisor
454
+ // resolves ONLY after stop() has fully completed (SIGTERM → SIGKILL
455
+ // escalation → watchers disarmed), so main() never returns — and the bin
456
+ // shim never process.exit()s — while a child kill is still in flight and
457
+ // could be abandoned, orphaning the app child.
439
458
  var stopped = false;
459
+ var onStopComplete;
460
+ var stopComplete = new Promise(function (resolve) { onStopComplete = resolve; });
440
461
  function shutdown() {
441
462
  if (stopped) return;
442
463
  stopped = true;
443
- d.stop().then(function () { /* exit naturally */ });
464
+ Promise.resolve(d.stop()).then(onStopComplete, onStopComplete);
444
465
  }
445
466
  process.once("SIGINT", shutdown);
446
467
  process.once("SIGTERM", shutdown);
468
+ function _clearSignalHandlers() {
469
+ process.removeListener("SIGINT", shutdown);
470
+ process.removeListener("SIGTERM", shutdown);
471
+ }
447
472
 
448
473
  try {
449
474
  await d.start();
450
475
  } catch (e) {
451
476
  _writeLine(ctx.stderr, "blamejs dev: " + ((e && e.message) || String(e)));
477
+ _clearSignalHandlers();
452
478
  return 1;
453
479
  }
454
- // The dev loop runs until the operator interrupts. Resolve a
455
- // never-settling promise so main() awaits forever; the SIGINT handler
456
- // above flips stopped+resolves on Ctrl-C.
457
- await new Promise(function (resolve) {
458
- var iv = setInterval(function () {
459
- if (stopped) { clearInterval(iv); resolve(); }
460
- }, 250);
461
- if (typeof iv.unref === "function") iv.unref();
462
- });
480
+ // The dev loop runs until the operator interrupts. A REF'd heartbeat holds
481
+ // the event loop open so a watched-child CRASH does not drain it and exit
482
+ // the supervisor dev's crash-resilience contract is to stay up and
483
+ // hot-restart on the next file change, but an unref'd keep-alive let a
484
+ // child's exit terminate the parent with a false code 0. Cleared once
485
+ // stop() has completed on SIGINT/SIGTERM. Unref'ing would drain the loop on
486
+ // a child crash and reintroduce the exit-on-crash bug this heartbeat fixes.
487
+ // allow:timer-no-unref-process-pinning supervisor must stay pinned.
488
+ var heartbeat = setInterval(function () {}, C.TIME.minutes(1));
489
+ // Hand the shutdown trigger to a test seam (no-op in production) so a test
490
+ // can drive the signal path deterministically instead of raising SIGINT.
491
+ if (typeof ctx._onDevRunning === "function") ctx._onDevRunning(shutdown);
492
+ try {
493
+ await stopComplete;
494
+ } finally {
495
+ clearInterval(heartbeat);
496
+ _clearSignalHandlers();
497
+ }
463
498
  return 0;
464
499
  }
465
500
 
@@ -766,7 +801,7 @@ async function _runAudit(args, ctx) {
766
801
  _writeLine(ctx.stderr, "blamejs audit purge: --archive (path to verified archive bundle) is required");
767
802
  return 2;
768
803
  }
769
- if (args.flags.confirm !== true && args.flags.confirm !== "true") {
804
+ if (!_isConfirmed(args.flags)) {
770
805
  _writeLine(ctx.stderr, "blamejs audit purge: --confirm is REQUIRED — destructive operation");
771
806
  return 2;
772
807
  }
@@ -2081,7 +2116,7 @@ async function _runErase(args, ctx) {
2081
2116
  var rowId = args.flags["row-id"];
2082
2117
  if (!table || table === true) return report.error("--table <name> is required", 2);
2083
2118
  if (!rowId || rowId === true) return report.error("--row-id <id> is required", 2);
2084
- if (!args.flags.confirm) {
2119
+ if (!_isConfirmed(args.flags)) {
2085
2120
  return report.error("--confirm is required (this operation is irreversible)", 2);
2086
2121
  }
2087
2122
  var dataDirFlag = args.flags["data-dir"];
@@ -2317,12 +2352,24 @@ async function main(argv, opts) {
2317
2352
  stderr: opts.stderr || process.stderr,
2318
2353
  env: opts.env || process.env,
2319
2354
  cwd: opts.cwd || process.cwd(),
2355
+ // Test seams (undefined in production): _dev injects the dev-supervisor
2356
+ // factory; _onDevRunning receives the shutdown fn once `dev` is live, so
2357
+ // a test can drive graceful teardown without raising a real OS signal.
2358
+ _dev: opts._dev,
2359
+ _onDevRunning: opts._onDevRunning,
2320
2360
  };
2321
2361
  if (!Array.isArray(argv)) argv = [];
2322
2362
  var args = _parseArgs(argv);
2323
2363
 
2324
- // Top-level flags handled before subcommand dispatch
2325
- if (args.flags.version || args.flags.v) {
2364
+ // Version is honored only as the WHOLE invocation — a bare `-v` /
2365
+ // `--version` with no subcommand. `_parseArgs` declares `--version`
2366
+ // boolean, so a stray version flag never swallows a token: it works in any
2367
+ // order (leading, trailing, or between a command and its subcommand) and
2368
+ // leaves the positional list intact, so the command dispatches instead of
2369
+ // a silent version no-op returning a false 0. A `-v` used as another
2370
+ // option's value stays that value, and a version token after the `--`
2371
+ // terminator stays a literal positional.
2372
+ if ((args.flags.version || args.flags.v) && args.pos.length === 0) {
2326
2373
  _writeLine(ctx.stdout, C.version);
2327
2374
  return 0;
2328
2375
  }
package/lib/dev.js CHANGED
@@ -255,14 +255,29 @@ function create(opts) {
255
255
  if (killTimer) { try { clearTimeoutFn(killTimer); } catch (_e) { /* timer already cleared */ } killTimer = null; }
256
256
  resolve();
257
257
  }
258
+ // 'exit' is the only event that reliably means the process is gone, so
259
+ // it is the only one that completes shutdown. A child that FAILED TO
260
+ // SPAWN has no pid and never emits 'exit' — it is settled by the
261
+ // no-process check below, NOT by listening for 'error'/'close', which
262
+ // can also fire for a LIVE child (a rejected kill emits 'error' while
263
+ // the process keeps running) and must not complete shutdown then.
258
264
  c.once("exit", done);
259
- try { c.kill(killSignal); }
265
+ var sent;
266
+ try { sent = c.kill(killSignal); }
260
267
  catch (e) {
261
268
  _logVia(log, "warn", "kill threw, child may already be gone",
262
269
  { error: (e && e.message) || String(e) });
263
270
  done();
264
271
  return;
265
272
  }
273
+ // kill() returning false means the signal was NOT delivered — which can
274
+ // be either "no process exists" (a child that failed to spawn has no
275
+ // pid; no 'exit' will ever arrive, so settle now) OR "a live process
276
+ // rejected the signal" (e.g. EPERM after the child changed credentials;
277
+ // pid is set). Only the no-process case completes shutdown here; a live
278
+ // child keeps the SIGKILL escalation + awaits exit/close, so stop()
279
+ // never falsely reports termination while the process is still running.
280
+ if (!sent && !c.pid) { done(); return; }
266
281
  // Hard-kill if the child ignores SIGTERM
267
282
  killTimer = setTimeoutFn(function () {
268
283
  if (settled) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blamejs/core",
3
- "version": "0.17.20",
3
+ "version": "0.17.21",
4
4
  "description": "The Node framework that owns its stack.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "blamejs contributors",
package/sbom.cdx.json CHANGED
@@ -2,10 +2,10 @@
2
2
  "$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
3
3
  "bomFormat": "CycloneDX",
4
4
  "specVersion": "1.5",
5
- "serialNumber": "urn:uuid:ca04b307-a233-4b08-991a-1182e07f9ff1",
5
+ "serialNumber": "urn:uuid:5c9f188a-268c-45b5-b70b-b8a8c8fcd062",
6
6
  "version": 1,
7
7
  "metadata": {
8
- "timestamp": "2026-07-25T06:27:12.675Z",
8
+ "timestamp": "2026-07-25T13:10:41.119Z",
9
9
  "lifecycles": [
10
10
  {
11
11
  "phase": "build"
@@ -19,14 +19,14 @@
19
19
  }
20
20
  ],
21
21
  "component": {
22
- "bom-ref": "@blamejs/core@0.17.20",
22
+ "bom-ref": "@blamejs/core@0.17.21",
23
23
  "type": "application",
24
24
  "name": "blamejs",
25
- "version": "0.17.20",
25
+ "version": "0.17.21",
26
26
  "scope": "required",
27
27
  "author": "blamejs contributors",
28
28
  "description": "The Node framework that owns its stack.",
29
- "purl": "pkg:npm/%40blamejs/core@0.17.20",
29
+ "purl": "pkg:npm/%40blamejs/core@0.17.21",
30
30
  "properties": [],
31
31
  "externalReferences": [
32
32
  {
@@ -54,7 +54,7 @@
54
54
  "components": [],
55
55
  "dependencies": [
56
56
  {
57
- "ref": "@blamejs/core@0.17.20",
57
+ "ref": "@blamejs/core@0.17.21",
58
58
  "dependsOn": []
59
59
  }
60
60
  ]