@silmaril-security/sdk 0.10.1 → 0.10.3

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/dist/index.js CHANGED
@@ -1380,6 +1380,18 @@ init_exceptions();
1380
1380
  init_hooks();
1381
1381
  init_modes();
1382
1382
 
1383
+ // src/validation.ts
1384
+ var PYTHON_NONBLANK = /[^\p{White_Space}\u001c-\u001f]/u;
1385
+ function isPythonNonblankString(value) {
1386
+ return typeof value === "string" && PYTHON_NONBLANK.test(value);
1387
+ }
1388
+ function validateThreshold(name, value) {
1389
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) {
1390
+ throw new Error(`Firewall: ${name} must be a finite number between 0 and 1`);
1391
+ }
1392
+ return value;
1393
+ }
1394
+
1383
1395
  // src/outcomes.ts
1384
1396
  var Outcome = {
1385
1397
  Benign: "benign",
@@ -1445,13 +1457,13 @@ function isHarmfulOutcome(value) {
1445
1457
  return typeof value === "string" && HARMFUL_OUTCOME_SET.has(value);
1446
1458
  }
1447
1459
  function normalizePrimaryOutcome(value, fieldName = "primary_outcome") {
1448
- if (typeof value !== "string") {
1460
+ if (!isPythonNonblankString(value)) {
1449
1461
  throw new Error(`Firewall: invalid ${fieldName} ${JSON.stringify(value)}`);
1450
1462
  }
1451
1463
  return isPrimaryOutcome(value) ? value : value;
1452
1464
  }
1453
1465
  function normalizeHarmfulOutcome(value, fieldName = "outcome") {
1454
- if (typeof value !== "string" || value === Outcome.Benign) {
1466
+ if (!isPythonNonblankString(value) || value === Outcome.Benign) {
1455
1467
  throw new Error(`Firewall: invalid ${fieldName} ${JSON.stringify(value)}`);
1456
1468
  }
1457
1469
  return isHarmfulOutcome(value) ? value : value;
@@ -1469,7 +1481,12 @@ function normalizeNumericOutcomeMap(values, fieldName, accepts) {
1469
1481
  if (typeof value !== "number" || !accepts(value)) {
1470
1482
  throw new Error(`Firewall: invalid ${fieldName} value for ${JSON.stringify(key)}`);
1471
1483
  }
1472
- out[normalizedKey] = value;
1484
+ Object.defineProperty(out, normalizedKey, {
1485
+ value,
1486
+ enumerable: true,
1487
+ configurable: true,
1488
+ writable: true
1489
+ });
1473
1490
  }
1474
1491
  return Object.freeze(out);
1475
1492
  }
@@ -1509,16 +1526,8 @@ function sanitizeText(text) {
1509
1526
  return out;
1510
1527
  }
1511
1528
 
1512
- // src/validation.ts
1513
- function validateThreshold(name, value) {
1514
- if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) {
1515
- throw new Error(`Firewall: ${name} must be a finite number between 0 and 1`);
1516
- }
1517
- return value;
1518
- }
1519
-
1520
1529
  // src/firewall.ts
1521
- var SDK_VERSION = "0.10.1";
1530
+ var SDK_VERSION = "0.10.3";
1522
1531
  var DEFAULT_TIMEOUT_MS = 1e4;
1523
1532
  var DEFAULT_MAX_RETRIES = 5;
1524
1533
  var MAX_BACKOFF_SECONDS = 30;
@@ -1725,12 +1734,12 @@ function governanceDecisionFromResponse(value) {
1725
1734
  if (value.rule_id !== void 0 && value.rule_id !== null && typeof value.rule_id !== "string") {
1726
1735
  throw new Error("Firewall: response governance rule_id must be a string when provided");
1727
1736
  }
1728
- if (value.identity_revision !== void 0 && value.identity_revision !== null && (typeof value.identity_revision !== "string" || !value.identity_revision.trim())) {
1737
+ if (value.identity_revision !== void 0 && value.identity_revision !== null && !isPythonNonblankString(value.identity_revision)) {
1729
1738
  throw new Error(
1730
1739
  "Firewall: response governance identity_revision must be a non-empty string when provided"
1731
1740
  );
1732
1741
  }
1733
- if (value.reason !== void 0 && value.reason !== null && (typeof value.reason !== "string" || !value.reason.trim())) {
1742
+ if (value.reason !== void 0 && value.reason !== null && !isPythonNonblankString(value.reason)) {
1734
1743
  throw new Error(
1735
1744
  "Firewall: response governance reason must be a non-empty string when provided"
1736
1745
  );