// The port the archive module's use cases are written against: the platform's Archive service, in this // module's own words. adapters/service.ts is the one place that knows `@conusai-sdk/archive` exists, and // it turns every refusal into the kit's typed app error (`businessAppError`) before core sees it. import { token } from "@conusai-kit/core" import type { DocumentReceipt, DocumentView, RetentionClassView, VersionFacts, VersionView } from "../contract/index.js" export interface Page { readonly rows: T[] readonly after?: string } /** What a `read` procedure may ask the service: nothing that changes a row. */ export interface ArchiveReads { listDocuments(query: { q?: string; after?: string; limit: number }): Promise> getDocument(documentId: string): Promise listVersions(documentId: string, query: { after?: string; limit: number }): Promise> listRetentionClasses(query: { after?: string; limit: number }): Promise> listDisposalDue(query: { after?: string; limit: number }): Promise> } export interface ArchiveService extends ArchiveReads { registerDocument(input: { title: string kind?: string retentionClass: string version: VersionFacts key: string }): Promise addVersion(input: { documentId: string revision: string version: VersionFacts key: string }): Promise setLegalHold(input: { documentId: string revision: string legalHold: boolean key: string }): Promise disposeDocument(input: { documentId: string; revision: string; key: string }): Promise createRetentionClass(input: { code: string keepFor: string from: RetentionClassView["from"] key: string }): Promise } /** The read view a `read` or `write` handler receives: the kind is a capability, not a label. */ export const archiveReadsOf = (service: ArchiveReads): ArchiveReads => ({ listDocuments: (query) => service.listDocuments(query), getDocument: (documentId) => service.getDocument(documentId), listVersions: (documentId, query) => service.listVersions(documentId, query), listRetentionClasses: (query) => service.listRetentionClasses(query), listDisposalDue: (query) => service.listDisposalDue(query), }) /** * Bound by a composition root or a test that brings its own client (another organization, the * business-services fake). With nothing bound, the module calls this deployment's service. */ export const ARCHIVE_SERVICE = token("archive.service", { views: { read: archiveReadsOf, write: archiveReadsOf }, })