Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
fix(threat-protection): no scan fee in zscaler mode (#4162)
Gergő Móricz29cf850af689
diff --git a/apps/api/src/lib/scrape-billing.test.ts b/apps/api/src/lib/scrape-billing.test.tsindex fd9cc5a41..c417b6839 100644--- a/apps/api/src/lib/scrape-billing.test.ts+++ b/apps/api/src/lib/scrape-billing.test.ts@@ -245,6 +245,28 @@ describe("calculateThreatScanCredits", () => {).toBe(0);});+ it("never bills zscaler-mode decisions, consulted or not", () => {+ const zscalerConsulted: ThreatDecision = {+ ...consulted(false),+ mode: "zscaler",+ verdict: {+ provider: "zscaler-zia",+ riskScore: null,+ categories: ["GAMBLING"],+ fromCache: false,+ raw: {},+ },+ };+ expect(calculateThreatScanCredits([zscalerConsulted])).toBe(0);+ // Mixed with a billable normal-mode decision, only that one bills.+ expect(+ calculateThreatScanCredits([+ zscalerConsulted,+ consulted(true, "http://a.example/"),+ ]),+ ).toBe(2);+ });+it("sums mixed decisions across URLs", () => {expect(calculateThreatScanCredits([diff --git a/apps/api/src/lib/scrape-billing.ts b/apps/api/src/lib/scrape-billing.tsindex 58347aec3..6ec2a3f41 100644--- a/apps/api/src/lib/scrape-billing.ts+++ b/apps/api/src/lib/scrape-billing.ts@@ -10,10 +10,7 @@ import { hasFormatOfType } from "./format-utils";import { TransportableError } from "./error";import { FeatureFlag } from "../scraper/scrapeURL/engines";import { isUrlBlocked } from "../scraper/WebScraper/utils/blocklist";-import {- ExchangeScrapeMetadata,- getExchangeSuccessCredits,-} from "./exchange";+import { ExchangeScrapeMetadata, getExchangeSuccessCredits } from "./exchange";import type { ThreatDecision } from "./threat-protection/types";import { UnsafeDomainBlockedError } from "./threat-protection/error";@@ -38,6 +35,9 @@ const threatScanCost = 2;* Sums the scan fees for a set of threat protection decisions. Only decisions* that consulted the provider bill; the fee is +2 per unique scanned* canonical URL across the given decisions.+ *+ * "zscaler" mode is exempt: classification runs against the customer's own+ * ZIA tenant (their credentials, their quota), so no scan fee applies.*/export function calculateThreatScanCredits(decisions: Iterable<ThreatDecision>,@@ -46,6 +46,7 @@ export function calculateThreatScanCredits(let credits = 0;for (const decision of decisions) {if (!decision.providerConsulted) continue;+ if (decision.mode === "zscaler") continue;// Decisions serialized by a pre-URL-level deploy have no `url`; bill// them individually (the old per-decision behavior) rather than letting// them all collapse onto one `undefined` key.diff --git a/apps/api/src/lib/threat-protection/types.ts b/apps/api/src/lib/threat-protection/types.tsindex c045ddc20..a85b6bba9 100644--- a/apps/api/src/lib/threat-protection/types.ts+++ b/apps/api/src/lib/threat-protection/types.ts@@ -117,7 +117,11 @@ export interface ThreatDecision {url: string;/** Canonicalized host of the checked URL (for logs and error surfaces). */domain: string;- /** True if a provider verdict (fresh OR cached) was consulted — this drives billing (+2 per scanned URL). */+ /**+ * True if a provider verdict (fresh OR cached) was consulted — this drives+ * billing (+2 per scanned URL; "zscaler" mode is exempt because the+ * customer's own tenant does the classification).+ */providerConsulted: boolean;verdict: RawVerdict | null;mode: ThreatProtectionMode;