blockintel-gate-sdk 0.4.4 → 0.4.5

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.cjs CHANGED
@@ -1287,6 +1287,8 @@ var HeartbeatManager = class {
1287
1287
  started = false;
1288
1288
  maxBackoffSeconds = 30;
1289
1289
  // Maximum backoff interval
1290
+ /** Server's current adoption stage for this tenant (cached from heartbeat response) */
1291
+ adoptionStage = null;
1290
1292
  maxSigners;
1291
1293
  signerIdleTtlMs;
1292
1294
  localRateLimitMs;
@@ -1560,6 +1562,9 @@ var HeartbeatManager = class {
1560
1562
  policyHash: response.data.policyHash
1561
1563
  };
1562
1564
  entry.consecutiveFailures = 0;
1565
+ if (response.data.adoptionStage != null) {
1566
+ this.adoptionStage = response.data.adoptionStage;
1567
+ }
1563
1568
  console.log("[HEARTBEAT] Acquired heartbeat token", {
1564
1569
  expiresAt,
1565
1570
  signerId,
@@ -1588,6 +1593,14 @@ var HeartbeatManager = class {
1588
1593
  getClientInstanceId() {
1589
1594
  return this.clientInstanceId;
1590
1595
  }
1596
+ /**
1597
+ * Get the server's current adoption stage for this tenant.
1598
+ * Populated after the first successful heartbeat response.
1599
+ * Returns null if not yet received.
1600
+ */
1601
+ getAdoptionStage() {
1602
+ return this.adoptionStage;
1603
+ }
1591
1604
  };
1592
1605
 
1593
1606
  // src/security/IamPermissionRiskChecker.ts
@@ -1920,6 +1933,8 @@ var GateClient = class {
1920
1933
  apiKey: heartbeatApiKey
1921
1934
  });
1922
1935
  this.heartbeatManager.start();
1936
+ this.checkAdoptionStageMismatch().catch(() => {
1937
+ });
1923
1938
  }
1924
1939
  if (!config.local) {
1925
1940
  const enforcementMode = config.enforcementMode || "SOFT";
@@ -1965,9 +1980,38 @@ var GateClient = class {
1965
1980
  console.warn("[GATE CLIENT] Async IAM risk check warning:", error instanceof Error ? error.message : String(error));
1966
1981
  }
1967
1982
  }
1983
+ /**
1984
+ * Warn if the local SDK mode is SHADOW but the server's adoption stage is enforcing.
1985
+ * Runs non-blocking after heartbeat startup; never throws.
1986
+ */
1987
+ async checkAdoptionStageMismatch() {
1988
+ if (!this.heartbeatManager) return;
1989
+ const signerId = this.config.signerId ?? DEFAULT_SIGNER_ID;
1990
+ try {
1991
+ await this.heartbeatManager.getTokenForSigner(signerId, 5e3);
1992
+ } catch {
1993
+ return;
1994
+ }
1995
+ const adoptionStage = this.heartbeatManager.getAdoptionStage();
1996
+ if (!adoptionStage) return;
1997
+ const ENFORCING_STAGES = [
1998
+ "SOFT_ENFORCE",
1999
+ "HARD_ENFORCE",
2000
+ "PROVENANCE",
2001
+ "HARD_KMS_GATEWAY",
2002
+ "HARD_KMS_ATTESTED",
2003
+ "HARD_KMS_ATTESTED_ENCLAVE",
2004
+ "HARD_GCP_CONFIDENTIAL_VM"
2005
+ ];
2006
+ if (this.mode === "SHADOW" && ENFORCING_STAGES.includes(adoptionStage)) {
2007
+ console.warn(
2008
+ `[GATE SDK] Server adoption stage is ${adoptionStage} but SDK mode is SHADOW. Consider updating mode to 'ENFORCE' so your application handles blocks correctly. Until updated, the SDK will allow transactions the server would block.`
2009
+ );
2010
+ }
2011
+ }
1968
2012
  /**
1969
2013
  * Evaluate a transaction defense request
1970
- *
2014
+ *
1971
2015
  * Implements:
1972
2016
  * - Shadow Mode (SHADOW: monitor-only, ENFORCE: enforce decisions)
1973
2017
  * - Connection failure strategy (FAIL_OPEN vs FAIL_CLOSED)
@@ -2228,7 +2272,8 @@ var GateClient = class {
2228
2272
  }
2229
2273
  }
2230
2274
  if (result.decision === "BLOCK") {
2231
- if (requestMode === "SOFT_ENFORCE") {
2275
+ const effectiveMode = result.mode ?? requestMode;
2276
+ if (effectiveMode === "SOFT_ENFORCE") {
2232
2277
  console.warn("[SOFT ENFORCE] Policy violation detected - app can override", {
2233
2278
  requestId,
2234
2279
  reasonCodes: result.reasonCodes
@@ -2242,7 +2287,7 @@ var GateClient = class {
2242
2287
  warning: "Policy violation detected. Override at your own risk."
2243
2288
  };
2244
2289
  }
2245
- if (requestMode === "SHADOW") {
2290
+ if (effectiveMode === "SHADOW") {
2246
2291
  console.warn("[GATE SHADOW MODE] Would have blocked transaction", {
2247
2292
  requestId,
2248
2293
  reasonCodes: result.reasonCodes,