export { TogglyIntegrationOptions, createTogglyMiddleware, default as togglyIntegration } from './integration/index.js'; export { TogglyServer, createTogglyServerClient } from './server/toggly-server.js'; export { SegmentMembershipError, createSegmentMembershipClient } from '@ops-ai/toggly-segments'; export { allFeaturesEnabled, anyFeatureEnabled, getTogglyFromAstroGlobal, withFeatureFlag } from './server/utils.js'; import { b as FeatureStatPayload, M as MetricStatPayload, c as MetricsFeatureOptions } from './index-B3YY1P83.js'; export { E as EvaluatedVariantDef, g as FeatureClientProps, f as FeatureProps, F as Flags, d as MetricsBatcher, P as PageFeatureMapping, a as TogglyClient, T as TogglyConfig, U as UsageBatcher, e as UsageFlushBundle, V as VariantResult } from './index-B3YY1P83.js'; export { $error, $flag, $flags, $gate, $isReady, $variant, $variants, clearIdentity, destroyTogglyClient, flushTelemetry, getVariant, getVariantValue, incrementCounter, initTogglyClient, recordUsage, recordView, refreshFlags, setGauge, setIdentity, stopRefreshInterval, stopWebSocket } from './client/store.js'; import 'astro'; import '@ops-ai/toggly-hooks-types'; import '@ops-ai/toggly-local-gates'; import 'nanostores'; declare const DEFAULT_METRICS_BASE_URL = "https://metrics.toggly.io/"; declare const DEFAULT_TELEMETRY_FLUSH_MS = 60000; /** Default AbortSignal timeout for usage HTTPS posts (aligns with connectTimeout). */ declare const DEFAULT_TELEMETRY_FETCH_TIMEOUT_MS = 5000; interface HttpsTelemetryClientOptions { metricsBaseUrl?: string; userAgent?: string; fetchImpl?: typeof fetch; /** Abort hanging usage posts after this many ms (default: 5000). */ fetchTimeoutMs?: number; } /** * Soft-fail HTTPS JSON client for gateway usage and metrics posts. * Network and non-2xx errors never throw to callers. */ declare class HttpsTelemetryClient { private readonly baseUrl; private readonly userAgent; private readonly fetchImpl; private readonly fetchTimeoutMs; constructor(options?: HttpsTelemetryClientOptions); getUserAgent(): string; getBaseUrl(): string; /** * POST JSON. Returns true on 2xx, false on soft-fail (network / non-2xx / timeout). */ post(path: string, body: unknown): Promise; sendUsageStats(payload: FeatureStatPayload): Promise; sendMetrics(payload: MetricStatPayload): Promise; } declare function resolveMetricsBaseUrl(raw?: string): string; /** * Resolve an enable flag. `TOGGLY_DISABLE_TELEMETRY=1` is authoritative and * wins over any explicit `true` in config. */ declare function resolveTelemetryEnableFlag(explicit: boolean | undefined, defaultWhenUnset: boolean): boolean; type SystemMetricObservation = { metric: string; value: number; }; type SystemMetricsSampler = () => SystemMetricObservation[]; /** Bound wait for request-scoped / signal close so hung flush cannot stall forever. */ declare const REQUEST_SCOPED_CLOSE_TIMEOUT_MS = 2000; interface UsageSender { sendStats(request: FeatureStatPayload): Promise; close?(): void; } interface MetricsSender { sendMetrics(request: MetricStatPayload): Promise; close?(): void; } /** * Usage + metrics telemetry config for Astro SSR. */ interface UsageTelemetryConfig { appKey: string; environment: string; metricsBaseUrl?: string; enableUsageTracking?: boolean; enableMetrics?: boolean; /** * Opt-in automatic process metrics (CpuUsage, MemoryWorkingSet, …). * Requires `enableMetrics`. Default false. */ systemMetrics?: boolean; usageFlushInterval?: number; metricsFlushInterval?: number; instanceName?: string; appVersion?: string; /** * When true (default), attach beforeExit/SIGTERM/SIGINT flush. * Edge-like hosts that lack signals should set false. */ attachProcessHandlers?: boolean; /** When true (default), restore batches if HTTPS/send returns soft-fail. */ restoreOnSendFailure?: boolean; fetchImpl?: typeof fetch; /** Injected client for tests. When unset, HTTPS `api/usage/stats` is used. */ usageClient?: UsageSender | null; /** Injected metrics client for tests. When unset, HTTPS `api/metrics` is used. */ metricsClient?: MetricsSender | null; /** Injected system-metrics sampler for tests. */ systemMetricsSampler?: SystemMetricsSampler; systemMetricsIntervalMs?: number; /** Abort hanging HTTPS posts after this many ms (default: 5000). */ fetchTimeoutMs?: number; } interface TelemetryLogger { debug: (...args: unknown[]) => void; warn: (...args: unknown[]) => void; error: (...args: unknown[]) => void; } /** * Owns usage + metrics batchers, flush timers, and soft-fail HTTPS restore. */ declare class UsageTelemetryRuntime { private usageBatcher; private metricsBatcher; private systemMetrics; private usageClient; private metricsClient; private httpsClient; private usageTimer; private metricsTimer; private flushInFlight; private pendingDrain; private closed; private readonly processStartTime; private readonly signalHandlers; private readonly logger; private readonly restoreOnSendFailure; private readonly attachProcessHandlers; private readonly config; constructor(config: UsageTelemetryConfig, logger?: TelemetryLogger); get usageEnabled(): boolean; get metricsEnabled(): boolean; start(): void; private ensureHttpsClient; private startUsageTelemetry; private resolveUsageClient; private startMetricsTelemetry; private resolveMetricsClient; static readonly SIGNAL_FLUSH_TIMEOUT_MS = 2000; static readonly REQUEST_SCOPED_CLOSE_TIMEOUT_MS = 2000; private attachHandlers; private bindTerminationSignal; private handleProcessSignal; private closeWithin; private reemitSignalAndExit; private exitCodeForSignal; private detachProcessHandlers; private startSystemMetrics; recordDefinitionCacheHit(): void; recordDefinitionCacheMiss(): void; measure(metric: string, value: number, options?: MetricsFeatureOptions): void; incrementCounter(metric: string, value?: number, options?: MetricsFeatureOptions): void; observe(metric: string, value: number, options?: MetricsFeatureOptions): void; flush(): Promise; private drainUntilIdle; private sendUsageOnce; private sendMetricsOnce; /** * Flush remaining telemetry and tear down. When `timeoutMs` is set, abandon the * await after that bound (flush may continue in the background) so callers * such as request middleware never stall on a hung telemetry endpoint. */ close(options?: { timeoutMs?: number; }): Promise; } /** * Soft-decode a variant configuration value as `T`. * Missing/null → null; with `isT` → null when guard fails; otherwise value as T. */ declare function decodeVariantValue(value: unknown, isT?: (v: unknown) => v is T): T | null; export { DEFAULT_METRICS_BASE_URL, DEFAULT_TELEMETRY_FETCH_TIMEOUT_MS, DEFAULT_TELEMETRY_FLUSH_MS, FeatureStatPayload, HttpsTelemetryClient, MetricStatPayload, MetricsFeatureOptions, type MetricsSender, REQUEST_SCOPED_CLOSE_TIMEOUT_MS, type UsageSender, type UsageTelemetryConfig, UsageTelemetryRuntime, decodeVariantValue, resolveMetricsBaseUrl, resolveTelemetryEnableFlag };