import { SmrtCollection } from '@happyvertical/smrt-core'; import { AgreementExecution } from '../models/AgreementExecution.js'; import { AgreementExecutionStatus } from '../types.js'; export interface ClaimAgreementCreateAttemptInput { tenantId: string; executionId: string; expectedAttemptCount: number; expectedLeaseId: string; expectedStatus: string; expectedLastError: string; operationId: string; leaseExpiresAt: Date; now: Date; } export interface CompleteAgreementCreateAttemptInput { tenantId: string; executionId: string; operationId: string; provider: string; providerRequestId: string; status: AgreementExecutionStatus; expiresAt: Date | null; } export interface FailAgreementCreateAttemptInput { tenantId: string; executionId: string; operationId: string; lastError: string; } export interface BindAgreementProviderRequestInput { tenantId: string; executionId: string; provider: string; providerRequestId: string; } export interface CompareAndSetAgreementLifecycleInput { tenantId: string; executionId: string; expectedStatus: AgreementExecutionStatus; status: AgreementExecutionStatus; expiresAt: Date | null; cancellationReason: string; lastProviderEventAt: Date; lastReconciledAt: Date | null; completedAt: Date | null; } export interface UpdateAgreementExecutionErrorInput { tenantId: string; executionId: string; lastError: string; } export type AgreementEvidenceArtifactKind = 'signed_document' | 'audit_trail'; export interface BindAgreementEvidenceArtifactInput { tenantId: string; executionId: string; kind: AgreementEvidenceArtifactKind; assetId: string; sha256: string; sizeBytes: number; mediaType: string; filename: string; } export declare class AgreementExecutionCollection extends SmrtCollection { static readonly _itemClass: typeof AgreementExecution; findByIdempotencyKey(idempotencyKey: string): Promise; findByProviderRequest(provider: string, providerRequestId: string): Promise; /** * Atomically claim an expired or cleared provider-create lease. * * The explicit tenant predicate and expected-state predicates make the raw * compare-and-swap fail closed across workers. `RETURNING id` is used * because not every database adapter reports affected-row counts reliably. */ claimCreateAttempt(input: ClaimAgreementCreateAttemptInput): Promise; /** * Persist a provider-create result only while the caller still owns its * lease. This prevents a slow, expired attempt from overwriting a newer * recovery attempt after returning from the provider. */ completeCreateAttempt(input: CompleteAgreementCreateAttemptInput): Promise; /** Record a create failure only while the caller still owns its lease. */ failCreateAttempt(input: FailAgreementCreateAttemptInput): Promise; /** Bind an adopted provider request without saving a stale object snapshot. */ bindProviderRequest(input: BindAgreementProviderRequestInput): Promise; /** * Apply provider lifecycle state only while status still matches the * caller's snapshot and the candidate observation is not older than the * persisted provider event. Service retries re-read the winner before * deciding whether the candidate state remains monotonic. */ compareAndSetLifecycle(input: CompareAndSetAgreementLifecycleInput): Promise; /** Increment audit attempts without writing any lifecycle columns. */ incrementAttemptCount(tenantId: string, executionId: string): Promise; /** Update failure diagnostics without writing a stale lifecycle snapshot. */ updateLastError(input: UpdateAgreementExecutionErrorInput): Promise; /** * Bind one immutable evidence artifact with a tenant-fenced compare-and-swap. * Concurrent finalizers can only publish one asset identity for each kind. */ bindEvidenceArtifact(input: BindAgreementEvidenceArtifactInput): Promise; findBySource(sourceKind: string, sourceId: string): Promise; private assertCreateAttemptTenant; private getReturnedExecution; } export default AgreementExecutionCollection; //# sourceMappingURL=AgreementExecutionCollection.d.ts.map