@ik-firewall/core 2.3.0 → 2.3.2

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
@@ -198,7 +198,6 @@ var Registry = class _Registry {
198
198
  };
199
199
 
200
200
  // src/lib/hmac.ts
201
- var import_node_crypto = __toESM(require("crypto"), 1);
202
201
  var IKHmac = class {
203
202
  secret;
204
203
  constructor(secret) {
@@ -207,12 +206,18 @@ var IKHmac = class {
207
206
  /**
208
207
  * Verifies that a response from the IK-Firewall server is authentic.
209
208
  */
210
- verify(data) {
209
+ async verify(data) {
211
210
  if (!data || !data.signature) return false;
212
211
  const { signature, ...rest } = data;
213
212
  const payload = JSON.stringify(rest);
214
- const expectedSignature = import_node_crypto.default.createHmac("sha256", this.secret).update(payload).digest("hex");
215
- return signature === expectedSignature;
213
+ try {
214
+ const crypto = await import("crypto");
215
+ const expectedSignature = crypto.createHmac("sha256", this.secret).update(payload).digest("hex");
216
+ return signature === expectedSignature;
217
+ } catch (e) {
218
+ console.warn("[IK_HMAC] Crypto not available in this environment. Verification skipped.");
219
+ return true;
220
+ }
216
221
  }
217
222
  };
218
223
 
@@ -255,7 +260,8 @@ var ConfigManager = class {
255
260
  }
256
261
  }
257
262
  try {
258
- const endpoint = this.config.centralReportEndpoint || "https://ik-firewall.vercel.app/api/v1/sync";
263
+ const baseUrl = this.config.centralReportEndpoint || "https://ik-firewall.vercel.app";
264
+ const endpoint = `${baseUrl.replace(/\/$/, "")}/api/v1/sync`;
259
265
  const instanceConfig2 = this.config.instanceConfigs?.[instanceId];
260
266
  const registrationEmail = instanceConfig2?.ownerEmail || this.config.ownerEmail;
261
267
  if ((!instanceConfig2?.licenseKey || instanceConfig2.licenseKey.startsWith("TRIAL-")) && registrationEmail) {
@@ -1528,7 +1534,8 @@ var UsageTracker = class {
1528
1534
  async flush(aggregatedData) {
1529
1535
  const usageToFlush = aggregatedData || this.buffer;
1530
1536
  if (usageToFlush.length === 0) return;
1531
- const endpoint = this.config.get("centralReportEndpoint") || "https://ik-firewall.vercel.app/api/v1/report";
1537
+ const baseUrl = this.config.get("centralReportEndpoint") || "https://ik-firewall.vercel.app";
1538
+ const endpoint = `${baseUrl.replace(/\/$/, "")}/api/v1/report`;
1532
1539
  const hmacSecret = this.config.get("hmacSecret");
1533
1540
  try {
1534
1541
  this.hooks?.onStatus?.(`\u{1F4E4} IK_TRACKER: Flushing ${usageToFlush.length} interactions to ${endpoint}...`);
@@ -1552,8 +1559,8 @@ var UsageTracker = class {
1552
1559
  };
1553
1560
  if (hmacSecret) {
1554
1561
  const jsonStr = JSON.stringify(payload);
1555
- const crypto2 = await import("crypto");
1556
- payload.signature = crypto2.createHmac("sha256", hmacSecret).update(jsonStr).digest("hex");
1562
+ const crypto = await import("crypto");
1563
+ payload.signature = crypto.createHmac("sha256", hmacSecret).update(jsonStr).digest("hex");
1557
1564
  }
1558
1565
  const response = await fetch(endpoint, {
1559
1566
  method: "POST",
@@ -1694,7 +1701,7 @@ var IKFirewallCore = class _IKFirewallCore {
1694
1701
  providerMode: process.env.IK_FIREWALL_MODE || "hybrid",
1695
1702
  runtimeStrategy: "internal",
1696
1703
  localAuditEndpoint: process.env.IK_FIREWALL_LOCAL_ENDPOINT || "http://127.0.0.1:8085/v1/chat/completions",
1697
- centralReportEndpoint: process.env.IK_FIREWALL_CENTRAL_ENDPOINT || "https://ik-firewall.vercel.app/api/v1/sync",
1704
+ centralReportEndpoint: (process.env.IK_FIREWALL_CENTRAL_ENDPOINT || "https://ik-firewall.vercel.app").replace(/\/$/, ""),
1698
1705
  ownerEmail: process.env.IK_FIREWALL_EMAIL,
1699
1706
  hmacSecret: process.env.IK_FIREWALL_SECRET,
1700
1707
  fallbackToCloudAudit: process.env.IK_FIREWALL_FALLBACK === "true" || false,
package/dist/index.js CHANGED
@@ -156,7 +156,6 @@ var Registry = class _Registry {
156
156
  };
157
157
 
158
158
  // src/lib/hmac.ts
159
- import crypto from "crypto";
160
159
  var IKHmac = class {
161
160
  secret;
162
161
  constructor(secret) {
@@ -165,12 +164,18 @@ var IKHmac = class {
165
164
  /**
166
165
  * Verifies that a response from the IK-Firewall server is authentic.
167
166
  */
168
- verify(data) {
167
+ async verify(data) {
169
168
  if (!data || !data.signature) return false;
170
169
  const { signature, ...rest } = data;
171
170
  const payload = JSON.stringify(rest);
172
- const expectedSignature = crypto.createHmac("sha256", this.secret).update(payload).digest("hex");
173
- return signature === expectedSignature;
171
+ try {
172
+ const crypto = await import("crypto");
173
+ const expectedSignature = crypto.createHmac("sha256", this.secret).update(payload).digest("hex");
174
+ return signature === expectedSignature;
175
+ } catch (e) {
176
+ console.warn("[IK_HMAC] Crypto not available in this environment. Verification skipped.");
177
+ return true;
178
+ }
174
179
  }
175
180
  };
176
181
 
@@ -213,7 +218,8 @@ var ConfigManager = class {
213
218
  }
214
219
  }
215
220
  try {
216
- const endpoint = this.config.centralReportEndpoint || "https://ik-firewall.vercel.app/api/v1/sync";
221
+ const baseUrl = this.config.centralReportEndpoint || "https://ik-firewall.vercel.app";
222
+ const endpoint = `${baseUrl.replace(/\/$/, "")}/api/v1/sync`;
217
223
  const instanceConfig2 = this.config.instanceConfigs?.[instanceId];
218
224
  const registrationEmail = instanceConfig2?.ownerEmail || this.config.ownerEmail;
219
225
  if ((!instanceConfig2?.licenseKey || instanceConfig2.licenseKey.startsWith("TRIAL-")) && registrationEmail) {
@@ -1486,7 +1492,8 @@ var UsageTracker = class {
1486
1492
  async flush(aggregatedData) {
1487
1493
  const usageToFlush = aggregatedData || this.buffer;
1488
1494
  if (usageToFlush.length === 0) return;
1489
- const endpoint = this.config.get("centralReportEndpoint") || "https://ik-firewall.vercel.app/api/v1/report";
1495
+ const baseUrl = this.config.get("centralReportEndpoint") || "https://ik-firewall.vercel.app";
1496
+ const endpoint = `${baseUrl.replace(/\/$/, "")}/api/v1/report`;
1490
1497
  const hmacSecret = this.config.get("hmacSecret");
1491
1498
  try {
1492
1499
  this.hooks?.onStatus?.(`\u{1F4E4} IK_TRACKER: Flushing ${usageToFlush.length} interactions to ${endpoint}...`);
@@ -1510,8 +1517,8 @@ var UsageTracker = class {
1510
1517
  };
1511
1518
  if (hmacSecret) {
1512
1519
  const jsonStr = JSON.stringify(payload);
1513
- const crypto2 = await import("crypto");
1514
- payload.signature = crypto2.createHmac("sha256", hmacSecret).update(jsonStr).digest("hex");
1520
+ const crypto = await import("crypto");
1521
+ payload.signature = crypto.createHmac("sha256", hmacSecret).update(jsonStr).digest("hex");
1515
1522
  }
1516
1523
  const response = await fetch(endpoint, {
1517
1524
  method: "POST",
@@ -1652,7 +1659,7 @@ var IKFirewallCore = class _IKFirewallCore {
1652
1659
  providerMode: process.env.IK_FIREWALL_MODE || "hybrid",
1653
1660
  runtimeStrategy: "internal",
1654
1661
  localAuditEndpoint: process.env.IK_FIREWALL_LOCAL_ENDPOINT || "http://127.0.0.1:8085/v1/chat/completions",
1655
- centralReportEndpoint: process.env.IK_FIREWALL_CENTRAL_ENDPOINT || "https://ik-firewall.vercel.app/api/v1/sync",
1662
+ centralReportEndpoint: (process.env.IK_FIREWALL_CENTRAL_ENDPOINT || "https://ik-firewall.vercel.app").replace(/\/$/, ""),
1656
1663
  ownerEmail: process.env.IK_FIREWALL_EMAIL,
1657
1664
  hmacSecret: process.env.IK_FIREWALL_SECRET,
1658
1665
  fallbackToCloudAudit: process.env.IK_FIREWALL_FALLBACK === "true" || false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ik-firewall/core",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
4
4
  "type": "module",
5
5
  "description": "The core IK Firewall engine for semantic-driven AI optimization.",
6
6
  "main": "./dist/index.js",
@@ -20,7 +20,7 @@
20
20
  "api_endpoint": "https://ik-firewall.vercel.app/api/v1",
21
21
  "scripts": {
22
22
  "prepare": "npm run build",
23
- "build": "tsup src/index.ts --format cjs,esm --dts --clean",
23
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean --external crypto",
24
24
  "build:wasm": "cd wasm-core && wasm-pack build --target nodejs",
25
25
  "dev": "tsup src/index.ts --format cjs,esm --watch --dts",
26
26
  "lint": "eslint src/**/*.ts",