import { type EffectiveNangoIntegration, type IntegrationBackendSetting } from "@opengeni/contracts"; import type { Database } from "./database.js"; /** Newest revision per integration key; empty before migration 1406 is applied. */ export declare function readIntegrationBackendSettings(db: Database): Promise; /** * A process-local cache of the switch. A failed refresh keeps serving the last * good value (or nothing, which means every integration is native). */ export declare function createIntegrationBackendSettingsCache(options?: { ttlMs?: number; now?: () => number; }): { get(db: Database): Promise; invalidate(): void; }; export type IntegrationBackendSettingsCache = ReturnType; /** The deployment's shared cache; API and worker processes each hold one. */ export declare const integrationBackendSettingsCache: { get(db: Database): Promise; invalidate(): void; }; /** * The Nango-backed integrations in effect for this deployment right now. * Empty (every integration native) unless a Nango secret key is configured. */ export declare function readEffectiveNangoIntegrations(db: Database, settings: { nangoSecretKey?: string | null | undefined; }, cache?: IntegrationBackendSettingsCache): Promise>; /** * Serializes, deployment-wide, every change to which Nango connection one * person's rows of one Nango integration stand for: storing a connect, * sharing it across organizations, and deciding that a Nango connection is * no longer used and may be deleted. Holds a transaction-scoped advisory lock * on the caller's open transaction. */ export declare function lockNangoPersonIntegration(tx: Database, input: { subjectId: string; providerConfigKey: string; }): Promise; /** `fn` in one transaction that holds `lockNangoPersonIntegration`. */ export declare function withNangoPersonIntegrationLock(db: Database, input: { subjectId: string; providerConfigKey: string; }, fn: (tx: Database) => Promise): Promise; /** Migration 1482's check; created withheld, granted to the runtime by 1499. */ export declare const NANGO_CONNECTIONS_IN_USE_ROUTINE = "opengeni_private.nango_connections_in_use_v1(text[])"; /** False on a database without 1499's grant of the check (1482). */ export declare function nangoConnectionsInUseAvailable(db: Database): Promise; /** * The ids among `nangoConnectionIds` that some live (not revoked) Nango-backed * connection row still stands for, in any organization; null while the check * is not granted (a database before 1499; see * nangoConnectionsInUseAvailable). The check opens and closes a * one-transaction capability, so call it from a read-write transaction (every * caller holds the person lock in one). */ export declare function nangoConnectionsInUse(db: Database, nangoConnectionIds: readonly string[]): Promise | null>; /** Migration 1487's listing; created withheld, granted to the runtime by 1499. */ export declare const NANGO_LIVE_CONNECTION_OWNERS_ROUTINE = "opengeni_private.nango_live_connection_owners_v1(text, text, text, integer)"; export type NangoLiveConnectionOwner = { subjectId: string; providerConfigKey: string; nangoConnectionId: string; }; /** * Every active Nango-backed row's owner, Nango integration and Nango * connection id, deployment-wide (each triple once), in pages of `pageSize`; * null on a database without 1499's grant. Like nangoConnectionsInUse it opens * and closes a one-transaction capability, so each page runs in its own * read-write transaction. */ export declare function listNangoLiveConnectionOwners(db: Database, options?: { pageSize?: number; maxRows?: number; }): Promise; export type NangoUsageKind = "connection_created" | "connection_reconnected" | "connection_deleted" | "connection_needs_reauth" | "proxy_request" | "tool_call"; export type NangoUsageEvent = { accountId: string; workspaceId: string; subjectId?: string | null; integrationKey: string; providerConfigKey: string; connectionId?: string | null; nangoConnectionId: string; kind: NangoUsageKind; toolName?: string | null; httpMethod?: string | null; httpStatus?: number | null; requestBytes?: number; responseBytes?: number; durationMs?: number | null; occurredAt?: Date; }; /** Inserts one usage event under the event's workspace scope. Throws on failure. */ export declare function insertNangoUsageEvent(db: Database, event: NangoUsageEvent): Promise; /** * Best-effort usage recording for the tool path: never awaited by callers, * never throws, bounded in flight. A dropped event only lowers the estimate. */ export declare function recordNangoUsageEvent(db: Database, event: NangoUsageEvent): void; export declare function nangoUsageRecorderStats(): { inFlight: number; dropped: number; }; export type NangoUsageSummaryRow = { accountId: string; workspaceId: string; integrationKey: string; subjectId: string | null; connectionSeconds: number; connectionDays: number; proxyRequests: number; toolCalls: number; requestBytes: number; responseBytes: number; computeSeconds: number; estimatedCostUsd: { connections: number; transfer: number; compute: number; total: number; }; }; export type NangoUsageSummary = { since: string; until: string; rows: NangoUsageSummaryRow[]; totals: Omit; }; type LifecycleRow = { account_id: string; workspace_id: string; integration_key: string; subject_id: string | null; nango_connection_id: string; kind: string; occurred_at: Date | string; }; type ActivityRow = { account_id: string; workspace_id: string; integration_key: string; subject_id: string | null; proxy_requests: number | string; tool_calls: number | string; request_bytes: number | string; response_bytes: number | string; compute_seconds: number | string; }; /** * Connection time from lifecycle events: a connection exists from its first * created/reconnected event until its deleted event, clipped to the period. * Proxy and tool counts, bytes and compute come from activity events. Run it * under an account scope (organization admins) or as the owner (operators). */ export declare function summarizeNangoUsage(db: Database, input: { since: Date; until: Date; accountId?: string; }): Promise; export declare function buildNangoUsageSummary(input: { since: Date; until: Date; lifecycle: LifecycleRow[]; activity: ActivityRow[]; }): NangoUsageSummary; export type NangoAffectedConnection = { organizationId: string; organizationName: string; workspaceId: string; workspaceName: string; userId: string | null; userEmail: string | null; connectionId: string; backend: "native" | "nango"; providerDomain: string; status: string; accountLabel: string | null; createdAt: string; lastUsedAt: string | null; /** The Nango connection a Nango-backed row stands for. */ nangoConnectionId: string | null; }; /** Owner-only: every native and Nango connection of one integration. */ export declare function listNangoAffectedConnections(db: Database, integrationKey: string): Promise; export {};