import type { ContractStreamEvent } from "../events/schemas"; import type { IdempotencyLedgerEntry } from "../areas/idempotency-ledger"; import type { IsolationState } from "../areas/isolation-breaker/schemas"; import type { ProtocolObjectType } from "../areas/object-registry/schemas"; import type { ProtectedSurfaceOperationClaim } from "../areas/operation-lifecycle"; import type { ProtectedPathPosture } from "../areas/protected-path-posture"; import type { Receipt } from "../areas/receipt-export"; export type { ContractStreamEvent } from "../events/schemas"; export type { IdempotencyLedgerEntry } from "../areas/idempotency-ledger"; export type { IsolationState } from "../areas/isolation-breaker/schemas"; export type { ProtocolObjectType } from "../areas/object-registry/schemas"; export type { ProtectedSurfaceOperationClaim } from "../areas/operation-lifecycle"; export type { ProtectedPathPosture } from "../areas/protected-path-posture"; export type { Receipt } from "../areas/receipt-export"; export type StoredProtocolRecord = { objectId: string; objectType: ProtocolObjectType; tenantId: string; organizationId: string; schemaVersion: string; canonicalDigest: string; payload: T; createdAt: string; sourceEventId: string | null; }; export type GreenlightConsumption = { greenlightId: string; gateAttemptId: string; actionContractId: string; idempotencyKey: string; consumedAt: string; }; export type GreenlightIssuanceClaim = { actionContractId: string; greenlightId: string; policyDecisionId: string; tenantId: string; organizationId: string; claimedAt: string; }; export type RecoveryTerminalClaim = { recoveryRecommendationId: string; statusTransitionId: string; nextStatus: "expired" | "superseded"; claimedAt: string; }; export type ProtectedPathPostureIndexEntry = { postureScopeKey: string; protectedPathPostureId: string; tenantId: string; organizationId: string; updatedAt: string; }; export type ProtectedSurfaceOperationClaimIndexEntry = { claimKeyDigest: string; protectedSurfaceOperationClaimId: string; tenantId: string; organizationId: string; claimState: ProtectedSurfaceOperationClaim["claimState"]; updatedAt: string; }; export type ReceiptMutationAttemptIndexEntry = { mutationAttemptId: string; receiptId: string; tenantId: string; organizationId: string; createdAt: string; }; export type IdempotencyLedgerIndexEntry = { ledgerKeyDigest: string; idempotencyLedgerEntryId: string; tenantId: string; organizationId: string; paramsDigest: string; actionContractId: string; policyDecisionId: string; greenlightId: string | null; ledgerState: IdempotencyLedgerEntry["ledgerState"]; updatedAt: string; }; export type IsolationStateIndexEntry = { isolationScopeKey: string; isolationStateId: string; tenantId: string; organizationId: string; scopeType: IsolationState["scopeType"]; scopeId: string; state: IsolationState["state"]; updatedAt: string; }; export type IsolationScopeRef = Pick; export type GatewayCheckCommit = { consumption: GreenlightConsumption | null; protectedSurfaceOperationClaimIndexEntries?: ProtectedSurfaceOperationClaimIndexEntry[]; idempotencyLedgerIndexEntries?: IdempotencyLedgerIndexEntry[]; receiptMutationAttemptIndexEntries?: ReceiptMutationAttemptIndexEntry[]; records: StoredProtocolRecord[]; events: ContractStreamEvent[]; }; export type EndpointAccessLeaseClaim = { greenlightId: string; leaseId: string; tenantId: string; organizationId: string; claimedAt: string; }; export type EndpointAccessUsageCounterKey = { tenantId: string; organizationId: string; leaseId: string; usageKind: string; }; export type EndpointAccessRecordScope = { tenantId: string; organizationId: string; }; export type RawRecordReadAuditRecordScope = { tenantId: string; organizationId: string; }; export type RawRecordReadAuditQuery = { targetObjectType: ProtocolObjectType; targetObjectId: string; limit: number; }; export type EndpointAccessUsageCounterReservation = EndpointAccessUsageCounterKey & { expectedCounter: number; counterAfter: number; updatedAt: string; }; export type EndpointAccessLeaseCommit = { leaseClaim: EndpointAccessLeaseClaim; records: StoredProtocolRecord[]; events: ContractStreamEvent[]; }; export type EndpointAccessUsageCommit = { usageCounterReservation: EndpointAccessUsageCounterReservation; records: StoredProtocolRecord[]; events: ContractStreamEvent[]; }; export type ProtocolCommit = { recordConflictMode?: "replace" | "absent_or_same"; greenlightIssuanceClaims?: GreenlightIssuanceClaim[]; recoveryTerminalClaims?: RecoveryTerminalClaim[]; protectedPathPostureIndexEntries?: ProtectedPathPostureIndexEntry[]; isolationStateIndexEntries?: IsolationStateIndexEntry[]; idempotencyLedgerReservationEntries?: IdempotencyLedgerIndexEntry[]; idempotencyLedgerIndexEntries?: IdempotencyLedgerIndexEntry[]; protectedSurfaceOperationClaimIndexEntries?: ProtectedSurfaceOperationClaimIndexEntry[]; protectedSurfaceOperationClaimIndexReleases?: string[]; receiptMutationAttemptIndexEntries?: ReceiptMutationAttemptIndexEntry[]; records: StoredProtocolRecord[]; events: ContractStreamEvent[]; }; export type ProtocolCommitResult = "committed" | "stream_conflict" | "record_digest_conflict" | "recovery_terminal_conflict" | "greenlight_issuance_conflict" | "idempotency_ledger_conflict"; export type GatewayCheckCommitResult = "committed" | "already_consumed" | "operation_claim_conflict" | "receipt_index_conflict" | "stream_conflict"; export type EndpointAccessLeaseCommitResult = "committed" | "greenlight_already_leased" | "record_digest_conflict" | "stream_conflict"; export type EndpointAccessUsageCommitResult = "committed" | "counter_conflict" | "record_digest_conflict" | "stream_conflict"; export type StreamTail = { offset: number; eventDigest: string; } | null; export type ProtocolRecordScope = { tenantId?: string; organizationId?: string; }; export type StreamEventRange = { startOffset?: number; endOffset?: number; limit?: number; }; /** * A postcondition, not an insertion-causality claim. "exact" means the complete * requested envelope is durably readable after the call; concurrent same-envelope * insertion is intentionally indistinguishable from insertion by this invocation. */ export type PutRecordIfAbsentOrSameResult = "exact" | "conflict"; export interface ProtocolStore { putRecord(record: StoredProtocolRecord): Promise; putRecordIfAbsentOrSame(record: StoredProtocolRecord): Promise; getRecord(objectType: ProtocolObjectType, objectId: string): Promise | null>; listRecordsByType(objectType: ProtocolObjectType, scope?: ProtocolRecordScope): Promise[]>; listRecordsByActionContract(objectType: ProtocolObjectType, actionContractId: string, scope?: ProtocolRecordScope): Promise[]>; getStreamTail(streamId: string, partitionKey: string): Promise; getStreamEvent(streamId: string, partitionKey: string, offset: number): Promise; listStreamEvents(streamId: string, partitionKey: string, range?: StreamEventRange): Promise; getCurrentProtectedPathPosture(postureScopeKey: string): Promise | null>; getCurrentIdempotencyLedgerEntry(ledgerKeyDigest: string): Promise | null>; getCurrentProtectedSurfaceOperationClaim(claimKeyDigest: string): Promise | null>; getReceiptByMutationAttemptId(mutationAttemptId: string): Promise | null>; listIsolationStates(scopeRefs: IsolationScopeRef[]): Promise; consumeGreenlight(consumption: GreenlightConsumption): Promise<"consumed" | "already_consumed">; commitProtocolRecords(commit: ProtocolCommit): Promise; commitGatewayCheck(commit: GatewayCheckCommit): Promise; commitEndpointAccessLease(commit: EndpointAccessLeaseCommit): Promise; getEndpointAccessLeaseByGreenlightId(greenlightId: string, scope: EndpointAccessRecordScope): Promise | null>; getEndpointAccessClearanceBindingByAttemptId(attemptId: string, scope: EndpointAccessRecordScope): Promise | null>; listEndpointAccessUsageEventsByLeaseId(leaseId: string, scope: EndpointAccessRecordScope): Promise[]>; getEndpointAccessUsageCounter(key: EndpointAccessUsageCounterKey): Promise; commitEndpointAccessUsage(commit: EndpointAccessUsageCommit): Promise; } export interface RawRecordReadAuditReader { listRawRecordReadAudits(scope: RawRecordReadAuditRecordScope, query: RawRecordReadAuditQuery): Promise[]>; }