/** * Single source of truth for $/GB rate resolution across cost-emitting tools. * * Background * ---------- * The five dollar-emitting tools (services, top_patterns, event_lookup, * explain_mode, estimate_savings) could label the *same* env / window / pattern * with *different* `rate_source` tags: * - services / top_patterns: customer_supplied ($1.50/GB from somewhere) * - event_lookup / explain_mode / estimate_savings: list_price * (destination-specific $0.50/GB CloudWatch list) * The absolute dollars agreed; the provenance did not, which undermines * trust in the numbers. * * Fix: every cost-emitting tool consults `resolveRate(...)` below and uses * the SAME priority chain (highest wins): * * 1. Caller's explicit `effective_ingest_per_gb` arg ........ customer_supplied * 2. Env's envs.json `analyzerCost` field ................... customer_supplied * 3. LOG10X_ANALYZER_COST env var .......................... customer_supplied * 4. Destination list price (COST_MODEL_BY_DESTINATION) ..... list_price * 5. None ................................................... unset * * On 'unset', callers MUST collapse dollar fields to null per the existing * "no $1/GB lie" convention — no fictional fallback rate. */ import type { EnvConfig } from './environments.js'; /** Provenance tag returned for every resolution. */ export type RateSource = 'customer_supplied' | 'list_price' | 'unset'; /** * Result of `resolveRate(...)`. `rate_per_gb` is null iff source==='unset' — * the only signal callers need to switch dollar fields to null. * * `disclosure` is a plain-English caveat suitable for rendering verbatim: * - customer_supplied → null (no caveat needed; caller owns the rate) * - list_price → "(at list price $X.XX/GB — your actual bill * may differ depending on discounts, commits, or * contract tier. To use your real rate, set * analyzerCost in your env config or pass * effective_ingest_per_gb.)" * - unset → "(no $/GB rate configured — pass * effective_ingest_per_gb, set envs.json * analyzerCost, or export LOG10X_ANALYZER_COST)" */ export interface ResolvedRate { rate_per_gb: number | null; source: RateSource; disclosure: string | null; /** Which rung of the priority chain produced the value. Aids debugging. */ origin: 'arg' | 'envs_json' | 'env_var' | 'destination_list' | 'none'; } /** * Arguments the caller passes through from its own tool args. The two * accepted alias keys are kept for back-compat with tools that historically * exposed only `analyzerCost` (event_lookup, services, savings). */ export interface RateArgs { effective_ingest_per_gb?: number | null; /** Deprecated alias of effective_ingest_per_gb; same provenance semantics. */ analyzerCost?: number | null; } /** * Resolve the effective $/GB rate + provenance for a tool's dollar surface. * * Every cost-emitting tool MUST call this rather than computing its own rate. * Callers pass: * - their explicit args (effective_ingest_per_gb / analyzerCost) * - the resolved env (for envs.json analyzerCost) * - the destination SIEM id (for destination list fallback) * * The function consults the env-var LOG10X_ANALYZER_COST itself — callers * do not need to read it. * * Returns a structured result; callers gate dollar fields on * `result.source === 'unset'` and render `result.disclosure` verbatim. */ export declare function resolveRate(args: RateArgs | undefined, env: EnvConfig | undefined, destination: string | undefined | null, opts?: { /** * SIEM-lens mode: the caller is pricing a DIFFERENT destination than the * env's actual one. Rung 1 (explicit caller rate) still wins — that is * the caller asserting their own rate for the lens — but rungs 2/3 * (envs.json analyzerCost / LOG10X_ANALYZER_COST) are SKIPPED because the * env-configured rate belongs to the actual destination and must not * price another SIEM's story. The lens therefore lands on the lens * destination's list price (rung 4). */ lensed?: boolean; }): ResolvedRate; /** * Narrow a string analyzer field (as found on EnvConfig.analyzer) to a * destination key the rate resolver understands. Returns undefined when the * field is missing or names a destination outside COST_MODEL_BY_DESTINATION. * * Exposed so callers can take the same "destination from env.analyzer when * the tool's own `destination` arg is omitted" decision uniformly. */ export declare function destinationFromEnvAnalyzer(env: EnvConfig | undefined): string | undefined;