import type { Database } from "./database.js"; /** * Signup network velocity (migration 1354) and the denied network rule * (migration 1368): the post-setup evaluation fan-out and the owner-only * operator review helpers. Rows hold keyed hashes only, never addresses, and * review output carries a 16-hex group key, email domains and account UUIDs * only. */ export declare const SIGNUP_NETWORK_POLICY_VERSION = "ip-velocity-v1"; /** Migration 1368: a network used by a denied or currently held account. */ export declare const SIGNUP_DENIED_NETWORK_POLICY_VERSION = "denied-network-v1"; /** * Migration 1489: a farm of new organizations sharing one non-public mail * domain, a burst of setups within seconds, or a non-public domain a denied * organization used. */ export declare const SIGNUP_EMAIL_CLUSTER_POLICY_VERSION = "email-cluster-v1"; /** * Migration 1491: a person's second or later additional organization within * 24 hours of their first organization, while none of theirs pays. */ export declare const ADDITIONAL_ORGANIZATION_POLICY_VERSION = "additional-organization-v1"; /** Detector holds listed by the network review and released by its rollback. */ export declare const SIGNUP_NETWORK_HOLD_POLICY_VERSIONS: readonly ["ip-velocity-v1", "denied-network-v1", "email-cluster-v1", "additional-organization-v1"]; export type SignupNetworkHoldPolicyVersion = (typeof SIGNUP_NETWORK_HOLD_POLICY_VERSIONS)[number]; /** Plain review reason for each network hold rule. */ export declare const SIGNUP_NETWORK_HOLD_REASONS: Record; export declare const PROMOTION_DETECTOR_ACTOR = "service:promotion-detector"; /** SQLSTATE raised by the setup receipt trigger when the network rate limit refuses. */ export declare const SIGNUP_NETWORK_RATE_LIMIT_SQLSTATE = "OG429"; /** * Evaluates each account in its own transaction under its own account scope, * sequentially and best-effort, through the ordinary Free eligibility seam * (which runs the abuse detectors and may hold only that account). Failures * are reported to `onError` and never thrown; the lazy per-account evaluation * at Free issuance and admission remains the correctness backstop. */ export declare function evaluateSignupNetworkAccounts(db: Database, accountIds: readonly string[], onError?: (accountId: string, error: unknown) => void): Promise<{ evaluated: number; failed: number; }>; export type SignupNetworkVelocitySettings = { revision: number; mode: "off" | "observe" | "enforce"; windowHours: number; exactHoldThreshold: number; prefixHoldThreshold: number | null; rateLimitEnabled: boolean; rateLimitMax: number; rateLimitWindowHours: number; /** Migration 1368; "off" until set. Older databases omit it. */ deniedNetworkMode?: "off" | "observe" | "enforce"; deniedNetworkLookbackDays?: number; /** Migration 1471: velocity on owners' sign-in networks; "off" until set. Older databases omit it. */ signInNetworkMode?: "off" | "observe" | "enforce"; /** * Migration 1489: the email cluster legs, each with its own mode (domain * observes, burst and denied domain enforce, until set). Older databases * omit these. */ emailDomainMode?: "off" | "observe" | "enforce"; emailDomainHoldThreshold?: number; emailDomainWindowMinutes?: number; burstMode?: "off" | "observe" | "enforce"; burstHoldThreshold?: number; burstWindowSeconds?: number; deniedDomainMode?: "off" | "observe" | "enforce"; deniedDomainHoldThreshold?: number; deniedDomainLookbackDays?: number; /** * Migration 1493: disposable mail and slow domain legs (both enforce until * set). Older databases omit these. */ disposableMailMode?: "off" | "observe" | "enforce"; slowDomainMode?: "off" | "observe" | "enforce"; slowDomainHoldThreshold?: number; slowDomainWindowHours?: number; /** * Migration 1494: the card verification gate (docs/signup-abuse-protection.md, * "Card verification"); "off" until set. Older databases omit it. */ cardVerificationMode?: "off" | "enforce"; operator: string | null; changedAt: string | null; }; export type SignupNetworkVelocityChanges = Partial>; /** Owner connection only. */ export declare function readSignupNetworkVelocitySettings(ownerDb: Database): Promise; /** Owner connection only; revision-fenced (SQLSTATE 40001 when stale). */ export declare function setSignupNetworkVelocitySettings(ownerDb: Database, input: { changes: SignupNetworkVelocityChanges; operator: string; reason: string; expectedRevision: number; }): Promise<{ previous: SignupNetworkVelocitySettings; current: SignupNetworkVelocitySettings; }>; export type SignupNetworkHoldAccount = { accountId: string; decision: string; revision: number; actor: string; decidedAt: string; ruleId: string | null; policyVersion: string | null; /** Why the detector held the account (see SIGNUP_NETWORK_HOLD_REASONS). */ reason: string; /** Null when the API had no trusted client address at setup. */ addressGroup: string | null; prefixGroup: string | null; exactGroupSize: number | null; prefixGroupSize: number | null; /** * Migration 1471: the largest group of new organizations whose owners * signed in from one exact network around their setup, and its 16-hex * reference (the database's key, not comparable with addressGroup). */ signInGroup: string | null; signInGroupSize: number | null; /** email-cluster-v1 evidence; null for the network rules' holds. */ emailCluster: { domainKind: string | null; /** 16-hex reference of the keyed domain hash; never the domain. */ domainGroup: string | null; domainGroupSize: number | null; burstGroupSize: number | null; /** Setups in the burst window sharing this one's domain group or signup network. */ relatedBurstGroupSize: number | null; /** Setups in the burst window that can hold: through the same shared relay, * or with the same domain group and the same signup network. */ enforceableBurstGroupSize: number | null; deniedDomainAccounts: number | null; /** Migration 1493: "disposable", "clear" or null (not checked). */ mailSignal: string | null; slowDomainGroupSize: number | null; /** Whether any organization of the slow domain group admitted a model call. */ slowDomainGroupUsed: boolean | null; } | null; /** denied-network-v1 evidence; null for the other rules' holds. */ deniedNetwork: { deniedAccounts: number | null; heldAccounts: number | null; matchedVia: string[]; matchedAccountIds: string[]; lastFlaggedUseAt: string | null; } | null; signupAt: string | null; setUpAt: string | null; emailDomain: string | null; chats: number | null; sessions: number | null; directApiSpendMicros: number | null; inAppSpendMicros: number | null; otherSpendMicros: number | null; freeGrantedMicros: number | null; freeUsedMicros: number | null; /** From the ordinary billing projection: purchased credit, paid-plan credit and credit on hold. */ balance: { creditsMicros: number; paidPlanCreditMicros: number; heldCreditMicros: number; balanceMicros: number; } | null; unreadable: string[]; }; export type SignupNetworkHoldGroup = { addressGroup: string; /** Self-serve organizations from this exact network in the last 7 days (bounded at 200). */ recentOrganizations: number; /** Distinct /24 or /48 prefix groups among them. */ prefixGroups: string[]; firstSetUpAt: string | null; lastSetUpAt: string | null; heldAccounts: number; members: { accountId: string; setUpAt: string; decision: string | null; revision: number; actor: string | null; }[]; }; export type SignupNetworkHolds = { schemaVersion: 2; policyVersions: readonly SignupNetworkHoldPolicyVersion[]; settings: SignupNetworkVelocitySettings; /** * Denied or held accounts, how many owners the denied network rule has * captured, how many have no self-serve owner to capture, and the oldest * capture of a currently flagged account (sign-ins after it are not yet * captured; --network-capture-flagged refreshes it). */ deniedNetworkCoverage: { flaggedAccounts: number; capturedOwners: number; withoutSelfServeOwner: number; oldestCaptureAt: string | null; } | null; holdCount: number; truncated: boolean; accounts: SignupNetworkHoldAccount[]; groups: SignupNetworkHoldGroup[]; }; /** * Pending detector holds from the network rules (velocity and denied network) * with per-account and per-network evidence, for an operator or agent reviewer. Owner connection * only; every read runs in one transaction that is always rolled back. A part * that cannot be read is null and named in `unreadable`. */ export declare function listSignupNetworkHolds(ownerDb: Database, options?: { limit?: number; }): Promise; /** * Captures again, account by account, the owners' sign-in networks of every * account that is denied or held now (the migration 1368 backfill). Safe to * repeat; unchanged rows are not rewritten. Owner connection only. */ export declare function captureFlaggedSignupNetworkOwners(ownerDb: Database): Promise<{ flaggedAccounts: number; capturedOwners: number; withoutSelfServeOwner: number; failed: number; }>; /** * Rollback helper: releases (decision eligible) every current detector hold * from the network rules (both, or only the given policy versions), one * account per transaction through the * revision-fenced decision setter with an operator actor and reason, so the * detector never re-holds them. Owner connection only. A stale revision (an * account decided meanwhile) is skipped and reported, never overwritten. */ export declare function releaseSignupNetworkHolds(ownerDb: Database, input: { operator: string; reason: string; limit?: number; dryRun?: boolean; policyVersions?: readonly SignupNetworkHoldPolicyVersion[]; }): Promise<{ candidates: number; wouldRelease?: { accountId: string; revision: number; }[]; released: { accountId: string; revision: number; }[]; skipped: { accountId: string; reason: string; }[]; dryRun: boolean; }>;