UNPKG

run402-mcp

Version:

MCP server for Run402 — full-stack backend infrastructure for AI agents: Postgres, auth, storage, serverless functions and atomic deploys. Paid with x402/MPP. Includes $0.03 image generation.

62 lines • 3.01 kB
/** * vault D2 — lazy allocation on first push (repo-first-onramp task 2.2). * * The orchestration `Repos.openOrCreate` (the namespace method the remote * helper and the capture lane drive) delegates to: resolve `repo_id` from * `project_id` via the SAME transport method `forProject` uses * (`findVaultByProject`, already on {@link VaultTransport} — no second * transport shape, no HTTP wire duplicated), and when that resolution fails * AND an owning `org_id` was supplied, run the six-stage creation journal * ({@link createVault}) to allocate it. * * Pulled out of the namespace class so it can be exercised directly against * `VaultMemoryTransport` (the fixture every other creation/deploy test * already uses) instead of hand-rolling an HTTP-level mock of the entire * six-stage protocol a second time. */ import { createVault, findResumableVaultJournal } from "./vault-creation-journal.js"; /** * Resolve a project's vault, allocating it when it does not exist yet. * * Without `org_id` this is byte-identical to a plain resolve: the resolution * failure (whatever `findVaultByProject` threw) is rethrown unchanged, so a * caller with no reason to create anything sees no behavior change at all. * * RESUMABILITY: before starting a fresh attempt, looks for an INCOMPLETE * local journal already matching this exact `(org_id, project_id)` and * resumes ITS `client_creation_id` rather than starting a second competing * one. Interrupt a creation mid-flight, call this again: the same journal — * never a new one — drives to ACTIVE, and exactly one vault exists either * way. An explicit `client_creation_id` always wins over that search. */ export async function openOrCreateVault(options) { let unresolved = null; try { const record = await options.transport.findVaultByProject({ project_id: options.project_id }); return { found: true, repo_id: record.repo_id, created: null }; } catch (e) { unresolved = e; } if (!options.org_id) throw unresolved; const resumable = options.client_creation_id ? null : findResumableVaultJournal(options.keystore, options.org_id, options.project_id); const created = await createVault({ keystore: options.keystore, transport: options.transport, org_id: options.org_id, project_id: options.project_id, ...(options.client_creation_id !== undefined ? { client_creation_id: options.client_creation_id } : resumable ? { client_creation_id: resumable.client_creation_id } : {}), ...(options.service_public_key !== undefined ? { service_public_key: options.service_public_key } : {}), }); return { found: false, repo_id: created.repo_id, created: { deduplicated: created.how === "reconciled", recovery_receipt: created.recovery_receipt, genesis_sha256: created.genesis_sha256 }, }; } //# sourceMappingURL=vault-open-or-create.js.map