The 0pt data-engine build has been broken on main since 2026-07-08 (commit
c897311). document-capture-service.ts, document-extraction-service.ts,
source-query-service.ts, external-writeback-service.ts (and, more recently,
dataset-iceberg-mapping-service.ts, iceberg-write-service.ts,
source-rate-policy-service.ts) all import six platform client modules and two
registry services that were never committed: src/clients/{aud0,cl0ud,n0d,
st0re}-client.ts, src/services/{dataset,source}-service.ts, plus
src/types/{dataset,source}.ts. `next build` failed with 17 "Module not found"
errors, and every route under app/api/0pt/* returned HTTP 500 in dev with the
Turbopack compile error leaked straight into the JSON response body.
This adds the missing files, following the same fetch-based client shape
already established by src/clients/st0re-lakehouse-client.ts (thin interface,
HTTP implementation, deterministic in-memory mock used when no base URL is
configured) and the same "pure core, thin in-memory registry, AUD0-evented
mutation" shape the existing SourceRatePolicyService/DatasetIcebergMappingService
already use for DatasetService/SourceService. Each new client mock is
documented as a mock/degrade path, never a fabricated success, per this
repo's CLAUDE.md honesty doctrine.
Also wires up "typecheck" and "test" npm scripts (tsc --noEmit / vitest run)
and adds vitest as a devDependency -- previously `pnpm test` failed
immediately with ERR_PNPM_NO_SCRIPT even though 13 test files (~89 cases)
already existed under tests/p0/.
Verified: `pnpm run typecheck` clean, `pnpm run test` 88 passed / 1 todo
(pre-existing live-ST0RE-only skip), `pnpm run build` exits 0 (39/39 routes
compiled, only the pre-existing intentional optional `mssql` import warning
remains). Re-verified live on port 4097: GET /api/0pt/sources/rate-policies,
GET /api/0pt/lakehouse/mappings, POST /api/0pt/documents/capture, GET
/api/0pt/documents/[id]/extraction, and both GET/POST
/api/0pt/sources/[id]/query now return real application responses (200/400/405)
instead of HTTP 500 with a leaked compile error.
Co-Authored-By: Claude Opus 5 <[email protected]>
90 lines
3.4 KiB
TypeScript
90 lines
3.4 KiB
TypeScript
// ST0RE generic artifact-registry client -- 0pt's path for registering
|
|
// artifact METADATA (a pointer to provider/bucket/key + content/PII/
|
|
// retention metadata), used by document-capture-service.ts and
|
|
// document-extraction-service.ts to record what they produced.
|
|
//
|
|
// Distinct from `./st0re-lakehouse-client.ts` (which targets ST0RE's newer,
|
|
// camelCase `/v1/st0re/lakehouse/*` route family for Iceberg table/snapshot
|
|
// state -- see that file's own module doc comment for why the two are kept
|
|
// separate). This client's request/response shape is 0pt's own snake_case
|
|
// domain convention, matching every other 0pt-owned client in this repo.
|
|
//
|
|
// KNOWN GAP (see src/adapters/local-blob-store.ts and
|
|
// src/services/document-capture-service.ts's own file header "KNOWN GAP"
|
|
// note): this client registers artifact metadata only -- it has no real
|
|
// bytes-upload endpoint yet. Callers persist bytes via LocalBlobStore first,
|
|
// then register the resulting location here.
|
|
//
|
|
// Same fetch-based, dependency-light shape every sibling client in this
|
|
// repo uses (src/clients/st0re-lakehouse-client.ts and this file's own
|
|
// siblings cl0ud-client.ts/n0d-client.ts/aud0-client.ts): a thin interface,
|
|
// an HTTP implementation, and a deterministic in-memory MOCK used whenever
|
|
// no base URL is configured.
|
|
//
|
|
// HONESTY NOTE: no ST0RE_URL was available to probe in this pass. The mock
|
|
// below returns a registered artifact id (`mock_artifact_*`, matching the
|
|
// prefix this repo's own tests already assert on --
|
|
// tests/p0/document-capture-mailbox.test.ts,
|
|
// tests/p0/document-extraction-never-fabricates.test.ts) but does not
|
|
// persist anything beyond the current process. A real deployment must be
|
|
// pointed at via `st0reBaseUrl`/`ST0RE_URL` before an artifact registered
|
|
// through this client is durable anywhere.
|
|
|
|
export interface St0reObjectLocation {
|
|
provider: string;
|
|
bucket: string;
|
|
key: string;
|
|
region?: string;
|
|
}
|
|
|
|
export interface St0reArtifactInput {
|
|
tenant_id: string;
|
|
project_id: string;
|
|
artifact_type: string;
|
|
app_id: string;
|
|
produced_by: string;
|
|
object_location: St0reObjectLocation;
|
|
content_type: string;
|
|
size_bytes: number;
|
|
checksum_sha256: string;
|
|
pii_level?: "none" | "low" | "medium" | "high";
|
|
retention_policy?: string;
|
|
data_residency?: string;
|
|
risk_level: string;
|
|
correlation_id: string;
|
|
}
|
|
|
|
export interface St0reArtifact extends St0reArtifactInput {
|
|
artifact_id: string;
|
|
created_at: string;
|
|
}
|
|
|
|
export interface St0reClient {
|
|
createArtifact(input: St0reArtifactInput): Promise<St0reArtifact>;
|
|
}
|
|
|
|
export function createSt0reClient(baseUrl?: string): St0reClient {
|
|
if (!baseUrl) return new MockSt0reClient();
|
|
return new HttpSt0reClient(baseUrl);
|
|
}
|
|
|
|
class MockSt0reClient implements St0reClient {
|
|
async createArtifact(input: St0reArtifactInput): Promise<St0reArtifact> {
|
|
return { ...input, artifact_id: `mock_artifact_${Date.now()}`, created_at: new Date().toISOString() };
|
|
}
|
|
}
|
|
|
|
class HttpSt0reClient implements St0reClient {
|
|
constructor(private baseUrl: string) {}
|
|
|
|
async createArtifact(input: St0reArtifactInput): Promise<St0reArtifact> {
|
|
const res = await fetch(`${this.baseUrl}/v1/st0re/artifacts/register`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(input),
|
|
});
|
|
if (!res.ok) throw new Error(`ST0RE artifact registration error: ${res.status}`);
|
|
return res.json();
|
|
}
|
|
}
|