feat(HSP-067): exit-manifest — T01 open formats only (portabel till icke-SIAX-mål), T02 notice-krav följer tillåtna artefakter, T03 nonExportable EXPLIKIT med skäl (aldrig tyst utelämnat), 7 tester

This commit is contained in:
2026-09-22 20:46:58 +02:00
parent 46aa370450
commit 37ffd5bd94
2 changed files with 216 additions and 0 deletions
+114
View File
@@ -0,0 +1,114 @@
/**
* `connectors/exit-manifest.ts` — HSP-067: portabel export och utträde.
*
* T01: an export can be RESTORED in a clean NON-SIAX target environment —
* the manifest carries only OPEN formats (json/csv/tar references) and
* standard metadata; NO SIAX-proprietary structure is required to read it.
* The pure predicate `isPortableManifest` enforces the shape.
* T02: SOURCES/notice-requirements follow the ALLOWED artifacts — the
* manifest declares what each artifact's sources/notice obligations are
* (provenance per artifact), so the exit runbook can list exactly which
* notices the customer must honor.
* T03: the UI shows WHICH rights/data CANNOT be exported and WHY —
* `nonExportable` lists each blocked item with its reason (license,
* third-party data, security classification), never silently omitted.
*/
export interface ExportArtifact {
artifactId: string;
/** Open format — readable in a NON-SIAX target (T01). */
format: 'json' | 'csv' | 'tar' | 'parquet';
/** What the artifact contains (provenance chain). */
sourceIds: readonly string[];
/** Notice requirements attached to this artifact (T02). */
noticeRequirement?: string;
/** Rights/data that CANNOT be exported (T03) — never silently omitted. */
nonExportable?: ReadonlyArray<{ reason: string; detail: string }>;
}
export interface ExitManifest {
manifestId: string;
tenantId: string;
/** T01: open formats only — a clean NON-SIAX target can read these. */
artifacts: ReadonlyArray<{
artifactId: string;
format: 'json' | 'csv' | 'tar' | 'parquet';
contentHash: string;
recordCount: number;
}>;
/** T02: notice requirements per artifact (follows the ALLOWED artifacts). */
noticeRequirements: ReadonlyArray<{ artifactId: string; requirement: string }>;
/** T03: rights/data that CANNOT be exported, with WHY — never silently omitted. */
nonExportable: ReadonlyArray<{ reason: string; detail: string }>;
createdAt: string;
}
export class ExitManifestError extends Error {
constructor(message: string) {
super(message);
this.name = 'ExitManifestError';
}
}
/**
* T03: build the exit manifest. Every non-exportable right/data is EXPLICIT
* — the report lists WHAT the customer cannot take and WHY (license terms,
* third-party data, security classification), never silently omitted.
*/
export function buildExitManifest(input: {
manifestId: string;
tenantId: string;
artifacts: ReadonlyArray<{
artifactId: string;
format: 'json' | 'csv' | 'tar' | 'parquet';
contentHash: string;
recordCount: number;
sourceIds: readonly string[];
noticeRequirement?: string;
nonExportable?: ReadonlyArray<{ reason: string; detail: string }>;
}>;
createdAt: string;
}): ExitManifest {
const noticeRequirements = input.artifacts
.filter((a) => a.noticeRequirement !== undefined)
.map((a) => ({ artifactId: a.artifactId, requirement: a.noticeRequirement! }));
const nonExportable = input.artifacts.flatMap((a) =>
(a.nonExportable ?? []).map((n) => ({ ...n })),
);
return {
manifestId: input.manifestId,
tenantId: input.tenantId,
artifacts: input.artifacts.map((a) => ({
artifactId: a.artifactId,
format: a.format,
contentHash: a.contentHash,
recordCount: a.recordCount,
})),
noticeRequirements,
nonExportable,
createdAt: input.createdAt,
};
}
/**
* T01 (structural): the manifest's artifact formats are ALL open formats a
* clean NON-SIAX target can read (json/csv/tar/parquet). The pure predicate
* proves portability — no SIAX-proprietary format ever appears.
*/
export function isPortableToNonSiaxTarget(manifest: ExitManifest): boolean {
const openFormats: ReadonlyArray<string> = ['json', 'csv', 'tar', 'parquet'];
return manifest.artifacts.every((a) => openFormats.includes(a.format));
}
/**
* T02: which notice requirements apply at exit? The sources/notice-krav
* FOLLOW the allowed artifacts — a notice attached to an artifact in the
* manifest is carried; artifacts outside the manifest contribute nothing.
*/
export function applicableNoticeRequirements(
manifest: ExitManifest,
allNoticeRequirements: ReadonlyArray<{ artifactId: string; requirement: string }>,
): ReadonlyArray<{ artifactId: string; requirement: string }> {
const manifestIds = new Set(manifest.artifacts.map((a) => a.artifactId));
return allNoticeRequirements.filter((n) => manifestIds.has(n.artifactId));
}