blockintel-gate-sdk 0.4.3 → 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.d.cts CHANGED
@@ -273,6 +273,11 @@ declare class GateClient {
273
273
  * Logs warnings but doesn't block (initialization already completed).
274
274
  */
275
275
  private performIamRiskCheckAsync;
276
+ /**
277
+ * Warn if the local SDK mode is SHADOW but the server's adoption stage is enforcing.
278
+ * Runs non-blocking after heartbeat startup; never throws.
279
+ */
280
+ private checkAdoptionStageMismatch;
276
281
  /**
277
282
  * Evaluate a transaction defense request
278
283
  *
@@ -597,6 +602,8 @@ declare class HeartbeatManager {
597
602
  private evictionTimer;
598
603
  private started;
599
604
  private maxBackoffSeconds;
605
+ /** Server's current adoption stage for this tenant (cached from heartbeat response) */
606
+ private adoptionStage;
600
607
  private readonly maxSigners;
601
608
  private readonly signerIdleTtlMs;
602
609
  private readonly localRateLimitMs;
@@ -662,6 +669,12 @@ declare class HeartbeatManager {
662
669
  * Get client instance ID (for tracking)
663
670
  */
664
671
  getClientInstanceId(): string;
672
+ /**
673
+ * Get the server's current adoption stage for this tenant.
674
+ * Populated after the first successful heartbeat response.
675
+ * Returns null if not yet received.
676
+ */
677
+ getAdoptionStage(): string | null;
665
678
  }
666
679
 
667
680
  /**
package/dist/index.d.ts CHANGED
@@ -273,6 +273,11 @@ declare class GateClient {
273
273
  * Logs warnings but doesn't block (initialization already completed).
274
274
  */
275
275
  private performIamRiskCheckAsync;
276
+ /**
277
+ * Warn if the local SDK mode is SHADOW but the server's adoption stage is enforcing.
278
+ * Runs non-blocking after heartbeat startup; never throws.
279
+ */
280
+ private checkAdoptionStageMismatch;
276
281
  /**
277
282
  * Evaluate a transaction defense request
278
283
  *
@@ -597,6 +602,8 @@ declare class HeartbeatManager {
597
602
  private evictionTimer;
598
603
  private started;
599
604
  private maxBackoffSeconds;
605
+ /** Server's current adoption stage for this tenant (cached from heartbeat response) */
606
+ private adoptionStage;
600
607
  private readonly maxSigners;
601
608
  private readonly signerIdleTtlMs;
602
609
  private readonly localRateLimitMs;
@@ -662,6 +669,12 @@ declare class HeartbeatManager {
662
669
  * Get client instance ID (for tracking)
663
670
  */
664
671
  getClientInstanceId(): string;
672
+ /**
673
+ * Get the server's current adoption stage for this tenant.
674
+ * Populated after the first successful heartbeat response.
675
+ * Returns null if not yet received.
676
+ */
677
+ getAdoptionStage(): string | null;
665
678
  }
666
679
 
667
680
  /**
package/dist/index.js CHANGED
@@ -1282,6 +1282,8 @@ var HeartbeatManager = class {
1282
1282
  started = false;
1283
1283
  maxBackoffSeconds = 30;
1284
1284
  // Maximum backoff interval
1285
+ /** Server's current adoption stage for this tenant (cached from heartbeat response) */
1286
+ adoptionStage = null;
1285
1287
  maxSigners;
1286
1288
  signerIdleTtlMs;
1287
1289
  localRateLimitMs;
@@ -1555,6 +1557,9 @@ var HeartbeatManager = class {
1555
1557
  policyHash: response.data.policyHash
1556
1558
  };
1557
1559
  entry.consecutiveFailures = 0;
1560
+ if (response.data.adoptionStage != null) {
1561
+ this.adoptionStage = response.data.adoptionStage;
1562
+ }
1558
1563
  console.log("[HEARTBEAT] Acquired heartbeat token", {
1559
1564
  expiresAt,
1560
1565
  signerId,
@@ -1583,6 +1588,14 @@ var HeartbeatManager = class {
1583
1588
  getClientInstanceId() {
1584
1589
  return this.clientInstanceId;
1585
1590
  }
1591
+ /**
1592
+ * Get the server's current adoption stage for this tenant.
1593
+ * Populated after the first successful heartbeat response.
1594
+ * Returns null if not yet received.
1595
+ */
1596
+ getAdoptionStage() {
1597
+ return this.adoptionStage;
1598
+ }
1586
1599
  };
1587
1600
 
1588
1601
  // src/security/IamPermissionRiskChecker.ts
@@ -1915,6 +1928,8 @@ var GateClient = class {
1915
1928
  apiKey: heartbeatApiKey
1916
1929
  });
1917
1930
  this.heartbeatManager.start();
1931
+ this.checkAdoptionStageMismatch().catch(() => {
1932
+ });
1918
1933
  }
1919
1934
  if (!config.local) {
1920
1935
  const enforcementMode = config.enforcementMode || "SOFT";
@@ -1960,9 +1975,38 @@ var GateClient = class {
1960
1975
  console.warn("[GATE CLIENT] Async IAM risk check warning:", error instanceof Error ? error.message : String(error));
1961
1976
  }
1962
1977
  }
1978
+ /**
1979
+ * Warn if the local SDK mode is SHADOW but the server's adoption stage is enforcing.
1980
+ * Runs non-blocking after heartbeat startup; never throws.
1981
+ */
1982
+ async checkAdoptionStageMismatch() {
1983
+ if (!this.heartbeatManager) return;
1984
+ const signerId = this.config.signerId ?? DEFAULT_SIGNER_ID;
1985
+ try {
1986
+ await this.heartbeatManager.getTokenForSigner(signerId, 5e3);
1987
+ } catch {
1988
+ return;
1989
+ }
1990
+ const adoptionStage = this.heartbeatManager.getAdoptionStage();
1991
+ if (!adoptionStage) return;
1992
+ const ENFORCING_STAGES = [
1993
+ "SOFT_ENFORCE",
1994
+ "HARD_ENFORCE",
1995
+ "PROVENANCE",
1996
+ "HARD_KMS_GATEWAY",
1997
+ "HARD_KMS_ATTESTED",
1998
+ "HARD_KMS_ATTESTED_ENCLAVE",
1999
+ "HARD_GCP_CONFIDENTIAL_VM"
2000
+ ];
2001
+ if (this.mode === "SHADOW" && ENFORCING_STAGES.includes(adoptionStage)) {
2002
+ console.warn(
2003
+ `[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.`
2004
+ );
2005
+ }
2006
+ }
1963
2007
  /**
1964
2008
  * Evaluate a transaction defense request
1965
- *
2009
+ *
1966
2010
  * Implements:
1967
2011
  * - Shadow Mode (SHADOW: monitor-only, ENFORCE: enforce decisions)
1968
2012
  * - Connection failure strategy (FAIL_OPEN vs FAIL_CLOSED)
@@ -2223,7 +2267,8 @@ var GateClient = class {
2223
2267
  }
2224
2268
  }
2225
2269
  if (result.decision === "BLOCK") {
2226
- if (requestMode === "SOFT_ENFORCE") {
2270
+ const effectiveMode = result.mode ?? requestMode;
2271
+ if (effectiveMode === "SOFT_ENFORCE") {
2227
2272
  console.warn("[SOFT ENFORCE] Policy violation detected - app can override", {
2228
2273
  requestId,
2229
2274
  reasonCodes: result.reasonCodes
@@ -2237,7 +2282,7 @@ var GateClient = class {
2237
2282
  warning: "Policy violation detected. Override at your own risk."
2238
2283
  };
2239
2284
  }
2240
- if (requestMode === "SHADOW") {
2285
+ if (effectiveMode === "SHADOW") {
2241
2286
  console.warn("[GATE SHADOW MODE] Would have blocked transaction", {
2242
2287
  requestId,
2243
2288
  reasonCodes: result.reasonCodes,