Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9b719aa
feat(breg): name the Proposal behind each record revision
jeremi Nov 26, 2026
0bc4a2e
feat(breg): keep write-once files on records
jeremi Nov 26, 2026
208360e
docs(breg): document record attachment slots
jeremi Nov 26, 2026
cffbc40
fix(breg): fail closed and index the Proposal link on record history
jeremi Nov 26, 2026
1cb2035
feat(breg): promote Proposal files to record slots on apply
jeremi Nov 26, 2026
c9cc386
feat(clients): download record attachments from the bindings
jeremi Nov 26, 2026
63ae3c3
docs(breg): document attachment promotion
jeremi Nov 26, 2026
52c6009
test(breg): re-pin revisions moved by the record attachment changes
jeremi Nov 26, 2026
1887436
fix(breg): answer 413 when an Action's files exceed the body bound
jeremi Nov 26, 2026
4979e95
docs(breg): state what record file labels, markers and erasure keep
jeremi Nov 26, 2026
e1cc9a6
docs(clients): state the record download limits and pin its refusals
jeremi Nov 26, 2026
1878918
fix(breg): audit a failed record file download as refused, per slot
jeremi Nov 26, 2026
cdb82dd
test(breg): pin that a standing agent never sees a history Proposal link
jeremi Nov 26, 2026
fa92e84
test(breg): pin the promotion recheck of a verdict rejected mid-apply
jeremi Nov 26, 2026
5798393
fix(breg): promote Proposal files in content-hash lock order
jeremi Nov 26, 2026
1134ead
fix(breg): refuse a record write whose declared files never arrived
jeremi Nov 26, 2026
755962d
test(breg): name the record attachments table as a fingerprint cause
jeremi Nov 26, 2026
a46ffb0
fix(breg): answer 503 when a Proposal target context fails to install
jeremi Nov 26, 2026
27d59e5
docs(clients): split the download limit sentence in the READMEs
jeremi Nov 26, 2026
506f1b7
fix(breg): let history erasure remove revisions a Proposal wrote
jeremi Nov 26, 2026
c836e21
docs(breg): describe history erasure of revisions a Proposal wrote
jeremi Nov 26, 2026
50493ca
test(breg): pin Proposal files and apply receipts after history erasure
jeremi Nov 26, 2026
714c9fe
docs(breg): separate a current Proposal read from the original apply …
jeremi Nov 26, 2026
d823aee
chore(identifiers): refresh BReg source fingerprints
jeremi Nov 26, 2026
4bdef69
fix(breg): validate Action files during invocation
jeremi Nov 26, 2026
bcf846b
fix(breg): refuse already rejected Action files
jeremi Nov 26, 2026
1de195e
fix(breg): keep current files until explicit erasure
jeremi Nov 26, 2026
492d4b5
fix(breg): identify refused attachment reads in audit
jeremi Nov 26, 2026
90ddc2e
fix(breg): align retention docs and schema checks
jeremi Nov 26, 2026
8903849
fix(breg): protect retained record attachment slots
jeremi Nov 26, 2026
62b2bf2
fix(breg): publish attachment slot migration contract
jeremi Nov 26, 2026
c405654
test(breg): update migration vocabulary count
jeremi Nov 26, 2026
9bc3d9b
fix(breg): activate attachment-slot-only successors
jeremi Nov 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion crates/registry-breg-client-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ temporal parameters and continuations distinct. Snapshot continuations bind
the returned snapshot and optional `validAt` identity. Relationship lists
bind the root record and relationship path. `getRecordRevision` returns one
validated retained record as inert bytes, while `recordRevisions` returns the
bounded revision collection. Every specialized object read has an exact `...Json`
bounded revision collection. A revision written by an applied Proposal may
carry an optional `proposal` member (`actionId`, `proposalId`,
`submissionVersion`), present only when the profile can read that Proposal.
The bytes pass through unchanged. Every specialized object read has an exact `...Json`
variant when record or GeoJSON values may cross JavaScript's integer boundary.

Standalone Proposals use `getProposal` or one explicit `listProposals` page.
Expand Down Expand Up @@ -290,6 +293,23 @@ Downloads follow the promoted link and return bounded bytes with their stored
content type. Keep the returned Proposal for subsequent operations; do not
substitute a Registry Record ETag or construct an attachment route.

## Record attachments

A record attachment slot holds a file that an immediate Action wrote or an
applied Proposal promoted. Read that file with
`downloadRecordAttachment(recordRoute, recordIdentifier, slot, accessProfile?)`.
The method checks the route, record identifier and slot before I/O. It returns
the bytes only when they match the service's `Repr-Digest`. A slot can hold up
to 16 MiB, but the client reads at most 8 MiB by default. Raise
`maximumResponseBytes` to download larger files. The client cannot yet send
request files, so an immediate Action that declares attachments is not
invocable from it.

```js
const file = await client.downloadRecordAttachment('applications', recordId,
'evidence', 'auditor');
```

## Explicit OAuth token exchange

`breg.PrivateKeyJwt` wraps the shared Rust OAuth provider. Construct it with the
Expand Down
6 changes: 6 additions & 0 deletions crates/registry-breg-client-node/__test__/facade.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ client.patchRecord(patch, '9f6973f9-10b3-4c58-b41b-494cba26796f', '"breg-1"', [
{ op: 'replace', field: 'name', value: 'Grace' },
], 'patch-person-1')
client.recordRevisions('people', '9f6973f9-10b3-4c58-b41b-494cba26796f', 'auditor')
client.downloadRecordAttachment('people', '9f6973f9-10b3-4c58-b41b-494cba26796f', 'photo', 'auditor').then(outcome => {
const digest: string | undefined = outcome.reprDigest
void digest
})
// @ts-expect-error The slot is required.
client.downloadRecordAttachment('people', '9f6973f9-10b3-4c58-b41b-494cba26796f')
client.getRecordRevision('people', '9f6973f9-10b3-4c58-b41b-494cba26796f', 2)
client.getGeoJsonRecord('people', '9f6973f9-10b3-4c58-b41b-494cba26796f')
client.getGeoJsonRecordJson('people', '9f6973f9-10b3-4c58-b41b-494cba26796f')
Expand Down
137 changes: 137 additions & 0 deletions crates/registry-breg-client-node/__test__/record-attachments.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
'use strict';
const assert = require('node:assert/strict');
const http = require('node:http');
const { test } = require('node:test');
const { createHash } = require('node:crypto');
const { BaseRegistryClient } = process.env.BREG_CLIENT_PACKAGE
? require(process.env.BREG_CLIENT_PACKAGE).breg : require('..');

const id = '00000000-0000-4000-8000-000000000001';
const slot = 'evidence';
const bytes = Buffer.from('%PDF-1.7 promoted record file');
const traceparent = '00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01';
const profileLink = '<https://id.registrystack.org/profiles/registry-record/v1>; rel="profile", </v1/schemas/application>; rel="describedby"';
const meta = { registryIdentifier: 'registry', datasetIdentifier: 'dataset', recordTypeIdentifier: 'application' };
const proposal = { actionId: 'amend', proposalId: '00000000-0000-4000-8000-0000000000aa', submissionVersion: 1 };
const revision = { recordIdentifier: id, revisionIdentifier: '2', domainData: { name: 'one' }, proposal };

function digest(body) {
return `sha-256=:${createHash('sha256').update(body).digest('base64')}:`;
}

async function serve(t, digestHeader) {
const requests = [];
const server = http.createServer((request, response) => {
requests.push({ url: request.url, accept: request.headers.accept });
response.setHeader('traceparent', traceparent);
response.setHeader('cache-control', 'no-store');
const path = request.url.split('?')[0];
if (path.includes('/attachments/')) {
response.setHeader('content-type', 'application/pdf');
response.setHeader('content-disposition', 'attachment');
response.setHeader('x-content-type-options', 'nosniff');
response.setHeader('vary', 'authorization');
if (digestHeader !== undefined) response.setHeader('repr-digest', digestHeader);
return response.end(bytes);
}
response.setHeader('content-type', 'application/json');
response.setHeader('link', profileLink);
const document = path.endsWith('/revisions')
? { items: [revision], pageInfo: { hasNextPage: false } }
: { data: revision, meta };
response.end(JSON.stringify(document));
});
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
t.after(() => new Promise(resolve => server.close(resolve)));
return { client: new BaseRegistryClient({ baseUrl: `http://127.0.0.1:${server.address().port}` }), requests };
}

test('a record attachment download uses the slot route and returns the verified digest', async t => {
const { client, requests } = await serve(t, digest(bytes));
const downloaded = await client.downloadRecordAttachment('applications', id, slot, 'auditor');
assert.deepEqual(downloaded.body, bytes);
assert.equal(downloaded.mediaType, 'application/pdf');
assert.equal(downloaded.reprDigest, digest(bytes));
assert.equal(requests[0].url, `/v1/records/applications/${id}/attachments/${slot}?accessProfile=auditor`);
assert.equal(requests[0].accept, '*/*');
});

test('a record attachment whose bytes miss the stated digest is a protocol refusal', async t => {
for (const header of [digest(Buffer.from('other bytes')), undefined]) {
const { client } = await serve(t, header);
await assert.rejects(
client.downloadRecordAttachment('applications', id, slot),
error => error.kind === 'protocol',
);
}
});

async function serveDownload(t, answer, options = {}) {
const server = http.createServer((request, response) => {
response.setHeader('traceparent', traceparent);
response.setHeader('cache-control', 'no-store');
answer(response);
});
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
t.after(() => new Promise(resolve => server.close(resolve)));
return new BaseRegistryClient({ baseUrl: `http://127.0.0.1:${server.address().port}`, ...options });
}

test('a concealed record attachment surfaces the service Problem', async t => {
const client = await serveDownload(t, response => {
response.statusCode = 404;
response.setHeader('content-type', 'application/problem+json');
response.end(JSON.stringify({
type: 'https://id.registrystack.org/problems/registry-breg/resource/not_found',
title: 'Not Found',
status: 404,
detail: 'The requested resource was not found.',
code: 'resource.not_found',
traceId: '4bf92f3577b34da6a3ce929d0e0e4736',
}));
});
await assert.rejects(
client.downloadRecordAttachment('applications', id, slot),
error => error.kind === 'not-found' && error.status === 404
&& error.code === 'resource.not_found' && error.traceId === '4bf92f3577b34da6a3ce929d0e0e4736',
);
});

test('a record attachment larger than the response bound is refused unread', async t => {
const client = await serveDownload(t, response => {
response.setHeader('content-type', 'application/pdf');
response.setHeader('content-disposition', 'attachment');
response.setHeader('x-content-type-options', 'nosniff');
response.setHeader('vary', 'authorization');
response.setHeader('repr-digest', digest(bytes));
response.end(bytes);
}, { maximumResponseBytes: bytes.length - 1 });
await assert.rejects(
client.downloadRecordAttachment('applications', id, slot),
error => error.kind === 'transport' && error.transportKind === 'response-too-large',
);
});

test('invalid record attachment selectors never reach HTTP', async t => {
const { client, requests } = await serve(t, digest(bytes));
for (const [route, record, name] of [
['applications', 'not-a-record', slot],
['applications', id, '../evidence'],
['applications', id, 'Evidence'],
['applications/other', id, slot],
]) {
await assert.rejects(
client.downloadRecordAttachment(route, record, name),
error => error.kind === 'invalid-request',
);
}
assert.equal(requests.length, 0);
});

test('revision reads keep the Proposal link the server sent', async t => {
const { client } = await serve(t, digest(bytes));
const history = JSON.parse((await client.recordRevisions('applications', id, 'auditor')).body);
assert.deepEqual(history.items[0].proposal, proposal);
const single = JSON.parse((await client.getRecordRevision('applications', id, 2, { accessProfile: 'auditor' })).body);
assert.deepEqual(single.data.proposal, proposal);
});
2 changes: 2 additions & 0 deletions crates/registry-breg-client-node/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,8 @@ export declare class BaseRegistryClient {
registryContract(accessProfile?: string | null, request?: ReadRequestOptions): Promise<BRegMetadata>
recordSchema(recordTypeIdentifier: string, accessProfile?: string | null, request?: ReadRequestOptions): Promise<RawOutcome>
recordRevisions(recordRoute: string, recordIdentifier: string, accessProfile?: string | null, request?: ReadRequestOptions): Promise<RawOutcome>
/** Download one record attachment slot. The bytes are returned only when they match the service's `Repr-Digest`. */
downloadRecordAttachment(recordRoute: string, recordIdentifier: string, slot: string, accessProfile?: string | null): Promise<RawOutcome>
getRecordRevision(recordRoute: string, recordIdentifier: string, revision: SafeInteger, options?: RecordProjectionOptions | null, request?: ReadRequestOptions): Promise<RawOutcome>
getRecord(recordRoute: string, recordIdentifier: string, options?: RecordOptions | null, request?: ReadRequestOptions): Promise<CompleteOutcome<RecordEnvelope>>
listRecords(recordRoute: string, options?: ListOptions | null, request?: ReadRequestOptions): Promise<PageOutcome>
Expand Down
1 change: 1 addition & 0 deletions crates/registry-breg-client-node/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ for (const [method, jsonIndexes, requiredIndexes] of [
['patchRecord', [3], [3]], ['batchRecords', [1], [1]], ['tombstoneRecord'],
['startProposal', [1], [1]], ['readProposal'], ['readProposalSubmission'], ['getProposal'], ['listProposals', [1], [1]], ['executeProposal'], ['listProposalsJson'],
['downloadProposalAttachment'], ['uploadProposalAttachment'], ['deleteProposalAttachment'],
['downloadRecordAttachment'],
['readProposalReviewStatus'], ['readProposalReviewStatusWithProgress'], ['readProposalReviewContext'],
['readProposalReviewContextBatch', [1], [1]],
['readProposalReviewById'], ['downloadProposalReviewDocument', [1], [1]],
Expand Down
5 changes: 5 additions & 0 deletions crates/registry-breg-client-node/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export declare class BaseRegistryClient {
recordSchema(recordTypeIdentifier: string, accessProfile?: string | undefined | null, cancellation?: ReadCancellation | undefined | null): Promise<RawOutcome>
/** Retrieve one bounded first page of record revisions as inert JSON. */
recordRevisions(recordRoute: string, recordIdentifier: string, accessProfile?: string | undefined | null, cancellation?: ReadCancellation | undefined | null): Promise<RawOutcome>
/**
* Download the file in one record attachment slot. The bytes are
* returned only when they match the service's `Repr-Digest`.
*/
downloadRecordAttachment(recordRoute: string, recordIdentifier: string, slot: string, accessProfile?: string | undefined | null): Promise<RawOutcome>
/** Retrieve one exact retained revision as validated inert record JSON. */
getRecordRevision(recordRoute: string, recordIdentifier: string, revision: number, options?: any | undefined | null, cancellation?: ReadCancellation | undefined | null): Promise<RawOutcome>
/**
Expand Down
22 changes: 22 additions & 0 deletions crates/registry-breg-client-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2969,6 +2969,28 @@ impl BaseRegistryClient {
.await
}

/// Download the file in one record attachment slot. The bytes are
/// returned only when they match the service's `Repr-Digest`.
#[napi]
pub async fn download_record_attachment(
&self,
record_route: String,
record_identifier: String,
slot: String,
access_profile: Option<String>,
) -> Result<RawOutcome> {
self.inner
.download_record_attachment(
&record_route,
&record_identifier,
&slot,
access_profile.as_deref(),
)
.await
.map(raw_value)
.map_err(client_error)
}

/// Retrieve one exact retained revision as validated inert record JSON.
#[napi]
pub async fn get_record_revision(
Expand Down
20 changes: 20 additions & 0 deletions crates/registry-breg-client-py/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ page. Application result references grant no target read authority. Read the
target through an ordinary authorized `get_record`; the retained result revision
records application provenance, not a current ETag or write precondition.

A revision written by an applied Proposal may carry an optional `proposal`
member (`actionId`, `proposalId`, `submissionVersion`) when the profile can
read that Proposal. Both revision reads return it as the server sent it.

## Hook verification

`verify_hook_delivery(method=..., path=..., headers=..., body=..., key=...)`
Expand Down Expand Up @@ -288,6 +292,22 @@ read with `read_proposal_review_by_id(binding, proposal_id)`, then call
document field. This does not require or grant ordinary Proposal Get authority.
The server rechecks the full context's current disclosure before releasing bytes.

## Record attachments

A record attachment slot holds a file that an immediate Action wrote or an
applied Proposal promoted. Read that file with
`download_record_attachment(record_route, record_identifier, slot, access_profile=None)`.
The method checks the route, record identifier and slot before I/O. It returns
the bytes only when they match the service's `Repr-Digest`. A slot can hold up
to 16 MiB, but the client reads at most 8 MiB by default. Raise
`maximum_response_bytes` to download larger files. The client cannot yet send
request files, so an immediate Action that declares attachments is not
invocable from it.

```python
stored = client.download_record_attachment("applications", record_id, "evidence", "auditor")
```

## Explicit OAuth token exchange

For automatic context-bound authorization, construct `BaseRegistryClient` with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,13 @@ class BaseRegistryClient:
record_identifier: str,
access_profile: str | None = None,
) -> dict[str, Any]: ...
def download_record_attachment(
self,
record_route: str,
record_identifier: str,
slot: str,
access_profile: str | None = None,
) -> dict[str, Any]: ...
def get_record_revision(
self,
record_route: str,
Expand Down
24 changes: 24 additions & 0 deletions crates/registry-breg-client-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2243,6 +2243,30 @@ impl BaseRegistryClient {
raw_value(py, &value.value, &value.metadata)
}

/// Download the file in one record attachment slot. The bytes are
/// returned only when they match the service's `Repr-Digest`.
#[pyo3(signature = (record_route, record_identifier, slot, access_profile=None))]
fn download_record_attachment<'py>(
&self,
py: Python<'py>,
record_route: &str,
record_identifier: &str,
slot: &str,
access_profile: Option<&str>,
) -> PyResult<Bound<'py, PyAny>> {
let value = py
.detach(|| {
self.runtime.block_on(self.inner.download_record_attachment(
record_route,
record_identifier,
slot,
access_profile,
))
})
.map_err(|error| sdk_error(py, error))?;
raw_value(py, &value.value, &value.metadata)
}

#[pyo3(signature = (record_route, record_identifier, revision, *, select=None, access_profile=None, format="json"))]
#[allow(clippy::too_many_arguments)]
fn get_record_revision<'py>(
Expand Down
Loading
Loading