@sentropic/artifacts 0.2.12 → 0.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +67 -0
- package/README.md +45 -10
- package/dist/adapters/postgres-management.js +3 -2
- package/dist/adapters/postgres-reader-consent.d.ts +11 -0
- package/dist/adapters/postgres-reader-consent.js +109 -0
- package/dist/adapters/postgres.js +4 -3
- package/dist/adapters/s3-uploads.d.ts +33 -0
- package/dist/adapters/s3-uploads.js +105 -0
- package/dist/content/headers.js +12 -0
- package/dist/http.d.ts +16 -2
- package/dist/http.js +325 -12
- package/dist/mcp-core.d.ts +3 -3
- package/dist/mcp-core.js +51 -4
- package/dist/profile/contracts.d.ts +1 -1
- package/dist/profile/contracts.js +3 -0
- package/dist/profile/index.js +33 -2
- package/dist/profile/radar.js +7 -0
- package/dist/profile/schemas.js +59 -0
- package/dist/profile/validation.d.ts +11 -0
- package/dist/profile/validation.js +71 -6
- package/dist/server/access.d.ts +2 -0
- package/dist/server/command-identity.d.ts +1 -1
- package/dist/server/command-identity.js +5 -3
- package/dist/server/consent.d.ts +65 -0
- package/dist/server/consent.js +42 -0
- package/dist/server/gc.d.ts +17 -0
- package/dist/server/gc.js +22 -0
- package/dist/server/management.d.ts +3 -1
- package/dist/server/management.js +48 -7
- package/dist/server/mime.d.ts +26 -2
- package/dist/server/mime.js +124 -2
- package/dist/server/ports.d.ts +29 -0
- package/dist/server/ports.js +11 -0
- package/dist/server/publication-limits.d.ts +12 -0
- package/dist/server/publication-limits.js +19 -1
- package/dist/server/publication.d.ts +9 -0
- package/dist/server/publication.js +4 -2
- package/dist/server/reader-store.d.ts +58 -0
- package/dist/server/reader-store.js +109 -0
- package/dist/server/templates.js +50 -2
- package/dist/server/uploads.d.ts +154 -18
- package/dist/server/uploads.js +227 -80
- package/migrations/0007_uploads.sql +43 -0
- package/migrations/0008_reader_consent.sql +48 -0
- package/package.json +22 -1
- package/sql/reader-consent.sql +47 -0
package/dist/profile/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { isArtifactId } from '../contracts.js';
|
|
2
|
+
import { isWithinMimeCeiling } from '../server/mime.js';
|
|
3
|
+
import { SERVER_MAX_FILE_BYTES, SERVER_MAX_FILES_PER_RELEASE, SERVER_MAX_TOTAL_BYTES } from '../server/publication-limits.js';
|
|
2
4
|
import { ARTIFACT_CAPABILITY_NAMES, ArtifactProfileInputError, PROFILE_CONTRACT_VERSION } from './contracts.js';
|
|
3
5
|
import { copyJson, freezeDeep, isRecord, orderedDigest } from './json.js';
|
|
4
6
|
import { assertCompleteOperation, capabilitySchema } from './schemas.js';
|
|
@@ -38,7 +40,7 @@ export function compileArtifactsProfile(input) {
|
|
|
38
40
|
throw new Error('invalid publication precondition policy');
|
|
39
41
|
}
|
|
40
42
|
if (profile.requireExpectedCurrentReleaseId && requested.some(name => [
|
|
41
|
-
'artifacts_promote', 'artifacts_restore', '
|
|
43
|
+
'artifacts_promote', 'artifacts_restore', 'artifacts_fork',
|
|
42
44
|
].includes(name)))
|
|
43
45
|
throw new Error('strict profile contains a writer without CAS');
|
|
44
46
|
if (new Set(requested).size !== requested.length ||
|
|
@@ -62,6 +64,21 @@ export function compileArtifactsProfile(input) {
|
|
|
62
64
|
if (op.limits[minimum] > op.limits[maximum])
|
|
63
65
|
throw new Error('inconsistent profile bounds');
|
|
64
66
|
}
|
|
67
|
+
// Server maxima are hard ceilings: profile limit keys may only move BELOW
|
|
68
|
+
// them (255 files / 16 MiB per file / 64 MiB per release), never above.
|
|
69
|
+
const limitCeilings = {
|
|
70
|
+
publishFilesMax: SERVER_MAX_FILES_PER_RELEASE,
|
|
71
|
+
releaseFilesMax: SERVER_MAX_FILES_PER_RELEASE,
|
|
72
|
+
maxDecodedFileBytes: SERVER_MAX_FILE_BYTES,
|
|
73
|
+
releaseFileBytesMax: SERVER_MAX_FILE_BYTES,
|
|
74
|
+
maxDecodedTotalBytes: SERVER_MAX_TOTAL_BYTES,
|
|
75
|
+
releaseTotalBytesMax: SERVER_MAX_TOTAL_BYTES,
|
|
76
|
+
};
|
|
77
|
+
for (const [key, ceiling] of Object.entries(limitCeilings)) {
|
|
78
|
+
if (op.limits[key] !== undefined && op.limits[key] > ceiling) {
|
|
79
|
+
throw new Error(`profile limit above the server maximum: ${key}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
65
82
|
operations.add(op.operation);
|
|
66
83
|
}
|
|
67
84
|
const rules = profile.rules;
|
|
@@ -75,6 +92,8 @@ export function compileArtifactsProfile(input) {
|
|
|
75
92
|
typeof rules.keyDerivationAlgorithm !== 'string' || !rules.keyDerivationAlgorithm ||
|
|
76
93
|
!Number.isSafeInteger(rules.pathMaxBytes) || rules.pathMaxBytes < 1 || rules.pathMaxBytes > 1024 ||
|
|
77
94
|
!Array.isArray(rules.mimeTypes) || !rules.mimeTypes.length || rules.mimeTypes.some((v) => typeof v !== 'string' || !v) ||
|
|
95
|
+
// The profile MIME allowlist may only narrow the server MIME ceiling.
|
|
96
|
+
rules.mimeTypes.some((v) => !isWithinMimeCeiling(v)) ||
|
|
78
97
|
!Array.isArray(rules.reservedFirstSegments) || rules.reservedFirstSegments.some((v) => typeof v !== 'string' || !v) ||
|
|
79
98
|
rules.forbiddenPathPattern !== '[\\\\%?#:\\u0000-\\u001f\\u007f]')
|
|
80
99
|
throw new Error('invalid profile semantics');
|
|
@@ -102,7 +121,7 @@ export function compileArtifactsProfile(input) {
|
|
|
102
121
|
if (!Object.hasOwn(props, key) || !matchesSchema(value, props[key]))
|
|
103
122
|
throw new Error('profile/schema default mismatch');
|
|
104
123
|
}
|
|
105
|
-
if (['artifacts_ensure', 'artifacts_publish', 'artifacts_commit_upload', 'artifacts_set_access', 'artifacts_delete', 'artifacts_revert'].includes(name)) {
|
|
124
|
+
if (['artifacts_ensure', 'artifacts_publish', 'artifacts_commit_upload', 'artifacts_publish_bundle', 'artifacts_set_access', 'artifacts_delete', 'artifacts_revert'].includes(name)) {
|
|
106
125
|
idempotency[name] = { required: true, scope: 'principal' };
|
|
107
126
|
}
|
|
108
127
|
}
|
|
@@ -127,18 +146,30 @@ export function compileArtifactsProfile(input) {
|
|
|
127
146
|
name = 'artifacts_ensure';
|
|
128
147
|
if (method === 'POST' && path === '/publish')
|
|
129
148
|
name = 'artifacts_publish';
|
|
149
|
+
if (method === 'POST' && path === '/publish_bundle')
|
|
150
|
+
name = 'artifacts_publish_bundle';
|
|
151
|
+
if (method === 'POST' && path === '/uploads/create')
|
|
152
|
+
name = 'artifacts_create_upload';
|
|
153
|
+
if (method === 'POST' && path === '/uploads/commit')
|
|
154
|
+
name = 'artifacts_commit_upload';
|
|
130
155
|
if (method === 'POST' && path === '/list')
|
|
131
156
|
name = 'artifacts_list';
|
|
132
157
|
if (method === 'POST' && path === '/get_source')
|
|
133
158
|
name = 'artifacts_get_source';
|
|
134
159
|
if (method === 'POST' && path === '/set_access')
|
|
135
160
|
name = 'artifacts_set_access';
|
|
161
|
+
if (method === 'POST' && path === '/lookup_people')
|
|
162
|
+
name = 'artifacts_lookup_people';
|
|
163
|
+
if (method === 'POST' && path === '/list_access')
|
|
164
|
+
name = 'artifacts_list_access';
|
|
136
165
|
if (method === 'POST' && path === '/delete')
|
|
137
166
|
name = 'artifacts_delete';
|
|
138
167
|
if (method === 'POST' && path === '/revert')
|
|
139
168
|
name = 'artifacts_revert';
|
|
140
169
|
if (method === 'POST' && path === '/list_versions')
|
|
141
170
|
name = 'artifacts_list_versions';
|
|
171
|
+
if (method === 'POST' && path === '/revoke_reader_consent')
|
|
172
|
+
name = 'artifacts_revoke_reader_consent';
|
|
142
173
|
if (method === 'GET' && path.startsWith('/meta/') && isArtifactId(path.slice(6)))
|
|
143
174
|
name = 'artifacts_get';
|
|
144
175
|
if (method === 'GET' && path.startsWith('/versions/') && isArtifactId(path.slice(10)))
|
package/dist/profile/radar.js
CHANGED
|
@@ -13,6 +13,13 @@ export const RADAR_ARTIFACTS_PROFILE = freezeDeep({
|
|
|
13
13
|
{ operation: 'list_versions', limits: {}, defaults: {} },
|
|
14
14
|
{ operation: 'get_source', limits: {}, defaults: {} },
|
|
15
15
|
{ operation: 'revert', limits: { idempotencyKeyMaxUnits: 256 }, defaults: {} },
|
|
16
|
+
// G2 sharing operations shipped with the profile (the radar tool selection
|
|
17
|
+
// itself stays the frozen four-tool L0 vector; hosts opt in by selecting
|
|
18
|
+
// the corresponding capabilities).
|
|
19
|
+
{ operation: 'set_access', limits: { idempotencyKeyMaxUnits: 256 }, defaults: {} },
|
|
20
|
+
{ operation: 'lookup_people', limits: { lookupQueryMinUnits: 2, lookupQueryMaxUnits: 120, lookupLimitMax: 10 },
|
|
21
|
+
defaults: { limit: 10 } },
|
|
22
|
+
{ operation: 'list_access', limits: {}, defaults: {} },
|
|
16
23
|
],
|
|
17
24
|
rules: { lengthUnit: 'utf16', textEncoding: 'utf8', callerKeyNormalization: 'none',
|
|
18
25
|
rejectLoneSurrogates: true, provenance: 'inline-original', keyDerivationAlgorithm: 'radar-derive-idempotency-v1', pathMaxBytes: 1024,
|
package/dist/profile/schemas.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SERVER_MAX_FILE_BYTES, SERVER_MAX_FILES_PER_RELEASE, SERVER_MAX_TOTAL_BYTES } from '../server/publication-limits.js';
|
|
1
2
|
const str = { type: 'string', minLength: 1 };
|
|
2
3
|
const integer = (minimum, maximum) => ({ type: 'integer', minimum,
|
|
3
4
|
...(maximum === undefined ? {} : { maximum }) });
|
|
@@ -17,13 +18,21 @@ export function assertCompleteOperation(config) {
|
|
|
17
18
|
const required = {
|
|
18
19
|
ensure: { limits: ['bindingNameMinUnits', 'bindingNameMaxUnits', 'idempotencyKeyMaxUnits'],
|
|
19
20
|
defaults: ['parameters'] },
|
|
21
|
+
// publish additionally accepts the optional release-budget keys
|
|
22
|
+
// releaseFilesMax / releaseFileBytesMax / releaseTotalBytesMax (files parity
|
|
23
|
+
// LOT 1): they bound the final release however its files arrived and default
|
|
24
|
+
// to the inline values below when absent.
|
|
20
25
|
publish: { limits: ['idempotencyKeyMaxUnits', 'publishFilesMin', 'publishFilesMax',
|
|
21
26
|
'maxDecodedFileBytes', 'maxDecodedTotalBytes'], defaults: ['profile'] },
|
|
22
27
|
list: { limits: ['listLimitMin', 'listLimitMax'], defaults: ['limit', 'offset'] },
|
|
23
28
|
commit_upload: { limits: ['idempotencyKeyMaxUnits'], defaults: ['profile'] },
|
|
29
|
+
publish_bundle: { limits: ['idempotencyKeyMaxUnits'], defaults: ['profile'] },
|
|
24
30
|
set_access: { limits: ['idempotencyKeyMaxUnits'], defaults: [] },
|
|
31
|
+
lookup_people: { limits: ['lookupQueryMinUnits', 'lookupQueryMaxUnits', 'lookupLimitMax'], defaults: ['limit'] },
|
|
32
|
+
list_access: { limits: [], defaults: [] },
|
|
25
33
|
delete: { limits: ['idempotencyKeyMaxUnits'], defaults: [] },
|
|
26
34
|
revert: { limits: ['idempotencyKeyMaxUnits'], defaults: [] },
|
|
35
|
+
revoke_reader_consent: { limits: ['idempotencyKeyMaxUnits'], defaults: [] },
|
|
27
36
|
};
|
|
28
37
|
const fields = required[config.operation];
|
|
29
38
|
if (fields && (fields.limits.some((key) => !Object.hasOwn(config.limits, key)) ||
|
|
@@ -86,6 +95,10 @@ export function capabilitySchema(name, profile) {
|
|
|
86
95
|
case 'list_versions': return profile.resultEnvelopeVersion !== 2 ? idOnly : obj({ artifactId: id,
|
|
87
96
|
limit: { ...integer(1, 100), default: 20 }, cursor: { ...str, maxLength: 4096 } }, ['artifactId']);
|
|
88
97
|
case 'get_source': return obj({ artifactId: id, releaseId: id,
|
|
98
|
+
// Frozen ceiling (review finding 5): maxItems 32 and the 256 KiB decoded
|
|
99
|
+
// budget are part of the frozen get_source definition and must NOT move.
|
|
100
|
+
// Server-side caps may only move BELOW this frozen schema; larger listings
|
|
101
|
+
// belong to the new listing tools, not to this one.
|
|
89
102
|
paths: { type: 'array', minItems: 1, maxItems: 32, items: { ...str, maxLength: profile.rules.pathMaxBytes },
|
|
90
103
|
description: 'Unique manifest paths; omit to read the whole snapshot (max 32 files, 256 KiB decoded). ' +
|
|
91
104
|
'Result files are `text` with encoding "utf8" or `base64` with encoding "base64" (never an integer ' +
|
|
@@ -101,12 +114,58 @@ export function capabilitySchema(name, profile) {
|
|
|
101
114
|
case 'create_upload': return obj({ artifactId: id, mimeType: str, maxSize: integer(1) }, ['artifactId', 'mimeType']);
|
|
102
115
|
case 'commit_upload': return obj({ artifactId: id, uploadId: str, path: str, mimeType: str,
|
|
103
116
|
digest: str, size: integer(0), profile: primitiveRecord, idempotencyKey: key }, ['artifactId', 'uploadId', 'path', 'mimeType', 'digest', 'size', 'idempotencyKey']);
|
|
117
|
+
case 'publish_bundle': {
|
|
118
|
+
// Release budgets come from the publish operation (release* keys override the
|
|
119
|
+
// inline values; absent keys default to them, never above the server maxima).
|
|
120
|
+
const publishLimits = profile.operations.find((entry) => entry.operation === 'publish')?.limits;
|
|
121
|
+
const filesMax = publishLimits?.releaseFilesMax ?? publishLimits?.publishFilesMax ?? SERVER_MAX_FILES_PER_RELEASE;
|
|
122
|
+
const fileBytesMax = publishLimits?.releaseFileBytesMax ?? publishLimits?.maxDecodedFileBytes ?? SERVER_MAX_FILE_BYTES;
|
|
123
|
+
const totalBytesMax = publishLimits?.releaseTotalBytesMax ?? publishLimits?.maxDecodedTotalBytes ?? SERVER_MAX_TOTAL_BYTES;
|
|
124
|
+
const inlineFileBytesMax = publishLimits?.maxDecodedFileBytes ?? SERVER_MAX_FILE_BYTES;
|
|
125
|
+
const inlineTotalBytesMax = publishLimits?.maxDecodedTotalBytes ?? SERVER_MAX_TOTAL_BYTES;
|
|
126
|
+
const reserved = profile.rules.reservedFirstSegments.map((s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|');
|
|
127
|
+
const bundlePath = { type: 'string', minLength: 1, maxLength: profile.rules.pathMaxBytes,
|
|
128
|
+
allOf: [{ not: { pattern: profile.rules.forbiddenPathPattern } },
|
|
129
|
+
{ not: { pattern: '(^|/)(\\.\\.?|)(/|$)' } },
|
|
130
|
+
{ not: { pattern: `^(?:${reserved})(?:/|$)` } }],
|
|
131
|
+
description: `At most ${profile.rules.pathMaxBytes} UTF-8 bytes; no empty/dot segments, colon or DEL.` };
|
|
132
|
+
const inlineFile = { ...obj({ path: bundlePath, mimeType: { type: 'string', enum: profile.rules.mimeTypes },
|
|
133
|
+
text: { type: 'string', maxLength: inlineFileBytesMax, description: 'UTF-8 decoded-byte budget applies.' },
|
|
134
|
+
bytes: { type: 'array', maxItems: inlineFileBytesMax, items: integer(0, 255) } }, ['path', 'mimeType']),
|
|
135
|
+
oneOf: [{ required: ['text'], not: { required: ['bytes'] } },
|
|
136
|
+
{ required: ['bytes'], not: { required: ['text'] } }] };
|
|
137
|
+
const uploadAsset = obj({ path: bundlePath, uploadId: id,
|
|
138
|
+
description: 'Staged file committed via artifacts_commit_upload; the server re-reads and re-verifies it.' }, ['path', 'uploadId']);
|
|
139
|
+
const casAsset = obj({ path: bundlePath,
|
|
140
|
+
digest: { type: 'string', pattern: '^sha256:[0-9a-f]{64}$',
|
|
141
|
+
description: 'Canonical sha256:<hex> digest of an already-pinned blob in the same scope.' },
|
|
142
|
+
size: integer(1), mimeType: { type: 'string', enum: profile.rules.mimeTypes } }, ['path', 'digest', 'size', 'mimeType']);
|
|
143
|
+
return { ...obj({ artifactId: id, idempotencyKey: key,
|
|
144
|
+
files: { type: 'array', items: inlineFile, minItems: 1, maxItems: filesMax,
|
|
145
|
+
description: `Inline files (bytes travel through the model, inline budget ${inlineFileBytesMax}/${inlineTotalBytesMax} bytes); at least one of files/assets is required.` },
|
|
146
|
+
assets: { type: 'array', minItems: 1, maxItems: filesMax,
|
|
147
|
+
items: { oneOf: [uploadAsset, casAsset] },
|
|
148
|
+
description: `Assets whose bytes already left the model: an uploadId staged via create_upload/commit_upload, or a CAS reference to an already-pinned blob. Release budget (max ${filesMax} files, ${fileBytesMax} bytes/file, ${totalBytesMax} bytes total) applies to the union of files and assets.` },
|
|
149
|
+
expectedCurrentReleaseId: { ...id, type: ['string', 'null'],
|
|
150
|
+
description: 'Compare the current release atomically; null requires an unpublished artifact. Always required for this tool.' },
|
|
151
|
+
profile: { ...primitiveRecord, default: config.defaults.profile },
|
|
152
|
+
...(part1 ? metadata : {}) }, ['artifactId', 'idempotencyKey', 'expectedCurrentReleaseId']),
|
|
153
|
+
anyOf: [{ required: ['files'] }, { required: ['assets'] }] };
|
|
154
|
+
}
|
|
104
155
|
case 'set_access': return { ...obj({ artifactId: id, action: { type: 'string', enum: ['grant', 'revoke'] },
|
|
105
156
|
principalId: { ...str, maxLength: 256 }, grant: { type: 'string', enum: ['read'] }, idempotencyKey: key }, ['artifactId', 'action', 'principalId', 'idempotencyKey']), oneOf: [
|
|
106
157
|
{ properties: { action: { enum: ['grant'] } }, required: ['grant'] },
|
|
107
158
|
{ properties: { action: { enum: ['revoke'] } }, not: { required: ['grant'] } },
|
|
108
159
|
] };
|
|
160
|
+
case 'lookup_people': return obj({ query: { type: 'string', minLength: limits.lookupQueryMinUnits,
|
|
161
|
+
maxLength: limits.lookupQueryMaxUnits, description: 'Name or email fragment; matched case- and accent-insensitively against approved accounts of the scope.' },
|
|
162
|
+
limit: { ...integer(1, limits.lookupLimitMax), default: config.defaults.limit } }, ['query']);
|
|
163
|
+
case 'list_access': return idOnly;
|
|
109
164
|
case 'promote': return obj({ artifactId: id, releaseId: id, expectedCurrent: id }, ['artifactId', 'releaseId', 'expectedCurrent']);
|
|
165
|
+
case 'revoke_reader_consent': return obj({ artifactId: id,
|
|
166
|
+
scope: { type: 'string', minLength: 1, maxLength: 128,
|
|
167
|
+
description: 'One consent scope of this artifact; omitted revokes every scope of the artifact.' },
|
|
168
|
+
idempotencyKey: key }, ['artifactId', 'idempotencyKey']);
|
|
110
169
|
default: throw new Error(`unsupported operation profile: ${operation}`);
|
|
111
170
|
}
|
|
112
171
|
}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { type JsonValue } from '../contracts.js';
|
|
2
2
|
import { type EffectiveArtifactProfile, type ArtifactSchema } from './contracts.js';
|
|
3
|
+
/** Release budget of a bundle publication: the publish operation's release* keys
|
|
4
|
+
* override its inline values; absent keys default to the inline values, and the
|
|
5
|
+
* server maxima are hard ceilings either way (profile/index.ts enforces them).
|
|
6
|
+
* Exported for the HTTP layer (create_upload/commit_upload/publish_bundle). */
|
|
7
|
+
export declare function releaseBudget(profile: EffectiveArtifactProfile): {
|
|
8
|
+
filesMax: number;
|
|
9
|
+
fileBytesMax: number;
|
|
10
|
+
totalBytesMax: number;
|
|
11
|
+
inlineFileBytesMax: number;
|
|
12
|
+
inlineTotalBytesMax: number;
|
|
13
|
+
};
|
|
3
14
|
/** The generated schema vocabulary, evaluated without a platform dependency. */
|
|
4
15
|
export declare function matchesSchema(value: unknown, schema: ArtifactSchema): boolean;
|
|
5
16
|
export declare function normalizeArguments(profile: EffectiveArtifactProfile, name: string, input: unknown, schema: ArtifactSchema, envelopeKey?: string, options?: {
|
|
@@ -2,6 +2,21 @@ import { isArtifactId } from '../contracts.js';
|
|
|
2
2
|
import { ArtifactProfileInputError } from './contracts.js';
|
|
3
3
|
import { copyJson, freezeDeep, isRecord } from './json.js';
|
|
4
4
|
import { operationProfile } from './schemas.js';
|
|
5
|
+
import { SERVER_MAX_FILE_BYTES, SERVER_MAX_FILES_PER_RELEASE, SERVER_MAX_TOTAL_BYTES } from '../server/publication-limits.js';
|
|
6
|
+
/** Release budget of a bundle publication: the publish operation's release* keys
|
|
7
|
+
* override its inline values; absent keys default to the inline values, and the
|
|
8
|
+
* server maxima are hard ceilings either way (profile/index.ts enforces them).
|
|
9
|
+
* Exported for the HTTP layer (create_upload/commit_upload/publish_bundle). */
|
|
10
|
+
export function releaseBudget(profile) {
|
|
11
|
+
const publishLimits = profile.operations.find((entry) => entry.operation === 'publish')?.limits;
|
|
12
|
+
return {
|
|
13
|
+
filesMax: publishLimits?.releaseFilesMax ?? publishLimits?.publishFilesMax ?? SERVER_MAX_FILES_PER_RELEASE,
|
|
14
|
+
fileBytesMax: publishLimits?.releaseFileBytesMax ?? publishLimits?.maxDecodedFileBytes ?? SERVER_MAX_FILE_BYTES,
|
|
15
|
+
totalBytesMax: publishLimits?.releaseTotalBytesMax ?? publishLimits?.maxDecodedTotalBytes ?? SERVER_MAX_TOTAL_BYTES,
|
|
16
|
+
inlineFileBytesMax: publishLimits?.maxDecodedFileBytes ?? SERVER_MAX_FILE_BYTES,
|
|
17
|
+
inlineTotalBytesMax: publishLimits?.maxDecodedTotalBytes ?? SERVER_MAX_TOTAL_BYTES,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
5
20
|
function requireInput(condition) {
|
|
6
21
|
if (!condition)
|
|
7
22
|
throw new ArtifactProfileInputError();
|
|
@@ -87,7 +102,7 @@ export function normalizeArguments(profile, name, input, schema, envelopeKey, op
|
|
|
87
102
|
const operation = name.slice('artifacts_'.length);
|
|
88
103
|
const { defaults, limits } = operationProfile(profile, operation);
|
|
89
104
|
const normalized = { ...copyJson(defaults), ...args };
|
|
90
|
-
if (['ensure', 'publish', 'commit_upload', 'set_access', 'delete', 'revert'].includes(operation)) {
|
|
105
|
+
if (['ensure', 'publish', 'commit_upload', 'publish_bundle', 'set_access', 'delete', 'revert'].includes(operation)) {
|
|
91
106
|
const key = args.idempotencyKey;
|
|
92
107
|
requireInput(typeof key === 'string' && key.trim().length > 0 && key.length <= limits.idempotencyKeyMaxUnits);
|
|
93
108
|
requireInput(envelopeKey === undefined || envelopeKey === key);
|
|
@@ -104,24 +119,74 @@ export function normalizeArguments(profile, name, input, schema, envelopeKey, op
|
|
|
104
119
|
requireInput(isArtifactId(args.releaseId));
|
|
105
120
|
if (Object.hasOwn(args, 'expectedCurrentReleaseId'))
|
|
106
121
|
requireInput(args.expectedCurrentReleaseId === null || isArtifactId(args.expectedCurrentReleaseId));
|
|
107
|
-
if (operation === 'publish') {
|
|
122
|
+
if (operation === 'publish' || operation === 'publish_bundle') {
|
|
108
123
|
const hasFiles = Object.hasOwn(args, 'files');
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
124
|
+
if (operation === 'publish') {
|
|
125
|
+
const hasEdits = Object.hasOwn(args, 'edits');
|
|
126
|
+
// Exactly one content source: a full file set, or small edits on the current release.
|
|
127
|
+
requireInput(hasFiles !== hasEdits);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
// A bundle needs at least one content source: inline files and/or assets.
|
|
131
|
+
requireInput(hasFiles || Object.hasOwn(args, 'assets'));
|
|
132
|
+
}
|
|
112
133
|
if (hasFiles) {
|
|
113
134
|
const paths = new Set();
|
|
114
135
|
let total = 0;
|
|
136
|
+
const inlineFileBytesMax = operation === 'publish' ? limits.maxDecodedFileBytes : releaseBudget(profile).inlineFileBytesMax;
|
|
137
|
+
const inlineTotalBytesMax = operation === 'publish' ? limits.maxDecodedTotalBytes : releaseBudget(profile).inlineTotalBytesMax;
|
|
115
138
|
normalized.files = args.files.map((file) => {
|
|
116
139
|
const path = file.path;
|
|
117
140
|
requireInput(!paths.has(path) && Buffer.byteLength(path, 'utf8') <= profile.rules.pathMaxBytes);
|
|
118
141
|
paths.add(path);
|
|
119
142
|
const bytes = Object.hasOwn(file, 'text') ? Array.from(Buffer.from(file.text, 'utf8')) : file.bytes;
|
|
120
143
|
total += bytes.length;
|
|
121
|
-
requireInput(bytes.length <=
|
|
144
|
+
requireInput(bytes.length <= inlineFileBytesMax && total <= inlineTotalBytesMax);
|
|
122
145
|
return { path, mimeType: file.mimeType, bytes };
|
|
123
146
|
});
|
|
147
|
+
if (operation === 'publish_bundle' && Object.hasOwn(args, 'assets')) {
|
|
148
|
+
// Duplicate path refused across the files/assets union.
|
|
149
|
+
for (const asset of args.assets) {
|
|
150
|
+
requireInput(!paths.has(asset.path));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (operation === 'publish_bundle' && Object.hasOwn(args, 'assets')) {
|
|
155
|
+
const paths = new Set();
|
|
156
|
+
if (hasFiles)
|
|
157
|
+
for (const file of args.files)
|
|
158
|
+
paths.add(file.path);
|
|
159
|
+
normalized.assets = args.assets.map((asset) => {
|
|
160
|
+
const path = asset.path;
|
|
161
|
+
requireInput(!paths.has(path) && Buffer.byteLength(path, 'utf8') <= profile.rules.pathMaxBytes);
|
|
162
|
+
paths.add(path);
|
|
163
|
+
if (Object.hasOwn(asset, 'uploadId')) {
|
|
164
|
+
requireInput(isArtifactId(asset.uploadId));
|
|
165
|
+
return { path, uploadId: asset.uploadId };
|
|
166
|
+
}
|
|
167
|
+
const digest = asset.digest;
|
|
168
|
+
requireInput(/^sha256:[0-9a-f]{64}$/.test(digest) && Number.isSafeInteger(asset.size) && asset.size >= 1 &&
|
|
169
|
+
profile.rules.mimeTypes.includes(asset.mimeType));
|
|
170
|
+
return { path, digest, size: asset.size, mimeType: asset.mimeType };
|
|
171
|
+
});
|
|
124
172
|
}
|
|
125
173
|
}
|
|
174
|
+
if (operation === 'create_upload') {
|
|
175
|
+
// MIME must be inside the profile allowlist (itself within the server ceiling).
|
|
176
|
+
requireInput(profile.rules.mimeTypes.includes(args.mimeType));
|
|
177
|
+
if (Object.hasOwn(args, 'maxSize')) {
|
|
178
|
+
requireInput(Number.isSafeInteger(args.maxSize) && args.maxSize >= 1 &&
|
|
179
|
+
args.maxSize <= releaseBudget(profile).fileBytesMax);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (operation === 'commit_upload') {
|
|
183
|
+
const path = args.path;
|
|
184
|
+
requireInput(Buffer.byteLength(path, 'utf8') <= profile.rules.pathMaxBytes);
|
|
185
|
+
requireInput(profile.rules.mimeTypes.includes(args.mimeType));
|
|
186
|
+
requireInput(/^sha256:[0-9a-f]{64}$/.test(args.digest));
|
|
187
|
+
requireInput(Number.isSafeInteger(args.size) && args.size >= 1 &&
|
|
188
|
+
args.size <= releaseBudget(profile).fileBytesMax);
|
|
189
|
+
requireInput(isArtifactId(args.uploadId));
|
|
190
|
+
}
|
|
126
191
|
return freezeDeep(normalized);
|
|
127
192
|
}
|
package/dist/server/access.d.ts
CHANGED
|
@@ -44,6 +44,8 @@ export interface AccessEvent {
|
|
|
44
44
|
export interface GrantRecord {
|
|
45
45
|
principalId: string;
|
|
46
46
|
grant: AccessGrant;
|
|
47
|
+
/** Grant creation stamp (migration 0006 `created_at`); absent on legacy rows. */
|
|
48
|
+
createdAt?: string;
|
|
47
49
|
}
|
|
48
50
|
/** Display metadata of one artifact (title/description/icon); cosmetic, owner-set. */
|
|
49
51
|
export interface ArtifactMetadata {
|
|
@@ -8,7 +8,7 @@ export type CallerIdempotencyKey = string & {
|
|
|
8
8
|
export type InternalIdempotencyKey = string & {
|
|
9
9
|
readonly __brand: 'internal-key';
|
|
10
10
|
};
|
|
11
|
-
export type ArtifactCommandOperation = 'ensure' | 'publish' | 'set_access' | 'delete' | 'revert';
|
|
11
|
+
export type ArtifactCommandOperation = 'ensure' | 'publish' | 'set_access' | 'delete' | 'revert' | 'commit_upload' | 'publish_bundle';
|
|
12
12
|
export interface CommandIdentity {
|
|
13
13
|
readonly internalKey: InternalIdempotencyKey;
|
|
14
14
|
readonly commandHash: string;
|
|
@@ -20,7 +20,8 @@ export function createRadarKeyDerivation(config) {
|
|
|
20
20
|
if (other === actor || !other.startsWith(`${actor}|`))
|
|
21
21
|
continue;
|
|
22
22
|
const [operation, objectId] = other.slice(actor.length + 1).split('|');
|
|
23
|
-
if ((operation === 'ensure' && objectId === '') ||
|
|
23
|
+
if ((operation === 'ensure' && objectId === '') ||
|
|
24
|
+
(['publish', 'set_access', 'delete', 'revert', 'commit_upload', 'publish_bundle'].includes(operation) && isArtifactId(objectId))) {
|
|
24
25
|
throw new Error('ambiguous Radar actor domain');
|
|
25
26
|
}
|
|
26
27
|
}
|
|
@@ -30,7 +31,7 @@ export function createRadarKeyDerivation(config) {
|
|
|
30
31
|
derive(input) {
|
|
31
32
|
const { storageScopeId, actorId, operation, objectId, callerKey } = input;
|
|
32
33
|
if (storageScopeId !== scope || !actors.has(actorId) ||
|
|
33
|
-
!['ensure', 'publish', 'set_access', 'delete', 'revert'].includes(operation) ||
|
|
34
|
+
!['ensure', 'publish', 'set_access', 'delete', 'revert', 'commit_upload', 'publish_bundle'].includes(operation) ||
|
|
34
35
|
(operation === 'ensure' ? objectId !== '' : !isArtifactId(objectId)))
|
|
35
36
|
throw new ArtifactProfileInputError();
|
|
36
37
|
assertWellFormed(callerKey);
|
|
@@ -48,7 +49,8 @@ export function createArtifactCommand(profile, name, args, authority, derivation
|
|
|
48
49
|
if (derivation.algorithm !== profile.profile.rules.keyDerivationAlgorithm)
|
|
49
50
|
throw new Error('profile/derivation mismatch');
|
|
50
51
|
const normalized = profile.validate(name, args, envelopeKey, options);
|
|
51
|
-
if (!['artifacts_ensure', 'artifacts_publish', 'artifacts_set_access', 'artifacts_delete', 'artifacts_revert'
|
|
52
|
+
if (!['artifacts_ensure', 'artifacts_publish', 'artifacts_set_access', 'artifacts_delete', 'artifacts_revert',
|
|
53
|
+
'artifacts_commit_upload', 'artifacts_publish_bundle'].includes(name))
|
|
52
54
|
throw new ArtifactProfileInputError(true);
|
|
53
55
|
const operation = name.slice('artifacts_'.length);
|
|
54
56
|
const { idempotencyKey, confirmationRef: _proof, ...payload } = normalized;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lot 1a — persistent reader consent, pure evaluation (design-merged §3.1,
|
|
3
|
+
* §3.2). A consent row authorizes one data class at one scope version; it
|
|
4
|
+
* never substitutes fresh rights. Validity is live row plus current scope
|
|
5
|
+
* version plus fresh rights, evaluated per call. No release, session, device
|
|
6
|
+
* or TTL column exists: the row outlives sessions and releases until revoked.
|
|
7
|
+
*/
|
|
8
|
+
export interface ConsentKey {
|
|
9
|
+
storageScopeId: string;
|
|
10
|
+
readerAccountId: string;
|
|
11
|
+
artifactId: string;
|
|
12
|
+
scopeId: string;
|
|
13
|
+
scopeVersion: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ReaderConsentRecord extends ConsentKey {
|
|
16
|
+
/** UUID, one row per grant episode; re-grant after revoke mints a new row. */
|
|
17
|
+
consentId: string;
|
|
18
|
+
/** ISO-8601 text, aligned with cluster-mesh consent records. */
|
|
19
|
+
grantedAt: string;
|
|
20
|
+
/** Lot 1a: a first-party gesture on the control-origin screen mints consent; the model never grants. */
|
|
21
|
+
grantedVia: 'reader_screen';
|
|
22
|
+
revokedAt?: string;
|
|
23
|
+
revokedBy?: 'self' | 'admin' | 'cascade';
|
|
24
|
+
}
|
|
25
|
+
export interface ReaderConsentEvent {
|
|
26
|
+
consentId: string;
|
|
27
|
+
storageScopeId: string;
|
|
28
|
+
readerAccountId: string;
|
|
29
|
+
artifactId: string;
|
|
30
|
+
scopeId: string;
|
|
31
|
+
scopeVersion: string;
|
|
32
|
+
action: 'grant' | 'revoke';
|
|
33
|
+
actor: string;
|
|
34
|
+
surface: 'screen' | 'api' | 'mcp' | 'cascade';
|
|
35
|
+
at: string;
|
|
36
|
+
}
|
|
37
|
+
export declare function assertConsentScopeId(scopeId: string): void;
|
|
38
|
+
export declare function assertConsentScopeVersion(scopeVersion: string): void;
|
|
39
|
+
/** Live row at the host's current scope version; absence of TTL is the owner requirement. */
|
|
40
|
+
export declare function consentAllows(record: ReaderConsentRecord | undefined, currentScopeVersion: string): record is ReaderConsentRecord;
|
|
41
|
+
/** Fresh-rights input of Gate B: approved account plus ACL read, re-evaluated on this call. */
|
|
42
|
+
export type FreshRights = 'ok' | 'suspended' | 'withdrawn' | 'gone';
|
|
43
|
+
export type GateBDecision = {
|
|
44
|
+
allowed: true;
|
|
45
|
+
} | {
|
|
46
|
+
allowed: false;
|
|
47
|
+
refusal: 'reader_consent_required';
|
|
48
|
+
scopeId: string;
|
|
49
|
+
} | {
|
|
50
|
+
allowed: false;
|
|
51
|
+
refusal: 'refused';
|
|
52
|
+
status: 401 | 404;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Gate B (§3.2): the business call executes only with a live consent at the
|
|
56
|
+
* current scope version AND fresh rights. A suspended account or a withdrawn
|
|
57
|
+
* share is refused with the row kept dormant, so reactivation or re-share
|
|
58
|
+
* resumes without a screen. A non-reader never sees the consent page.
|
|
59
|
+
*/
|
|
60
|
+
export declare function decideGateB(input: {
|
|
61
|
+
consent: ReaderConsentRecord | undefined;
|
|
62
|
+
currentScopeVersion: string;
|
|
63
|
+
rights: FreshRights;
|
|
64
|
+
scopeId: string;
|
|
65
|
+
}): GateBDecision;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lot 1a — persistent reader consent, pure evaluation (design-merged §3.1,
|
|
3
|
+
* §3.2). A consent row authorizes one data class at one scope version; it
|
|
4
|
+
* never substitutes fresh rights. Validity is live row plus current scope
|
|
5
|
+
* version plus fresh rights, evaluated per call. No release, session, device
|
|
6
|
+
* or TTL column exists: the row outlives sessions and releases until revoked.
|
|
7
|
+
*/
|
|
8
|
+
/** Host-declared scope ids are package-opaque: letter start, dots/dashes/underscores, at most 128. */
|
|
9
|
+
const SCOPE_ID_PATTERN = /^[a-z][a-z0-9._-]{0,127}$/;
|
|
10
|
+
/** Scope versions are host content; widening bumps them, narrowing keeps them (§3.1). */
|
|
11
|
+
const SCOPE_VERSION_PATTERN = /^[A-Za-z0-9._-]{1,64}$/;
|
|
12
|
+
export function assertConsentScopeId(scopeId) {
|
|
13
|
+
if (!SCOPE_ID_PATTERN.test(scopeId) || scopeId.startsWith('sentropic:')) {
|
|
14
|
+
throw new Error(`invalid consent scope id: ${scopeId}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function assertConsentScopeVersion(scopeVersion) {
|
|
18
|
+
if (!SCOPE_VERSION_PATTERN.test(scopeVersion))
|
|
19
|
+
throw new Error(`invalid consent scope version: ${scopeVersion}`);
|
|
20
|
+
}
|
|
21
|
+
/** Live row at the host's current scope version; absence of TTL is the owner requirement. */
|
|
22
|
+
export function consentAllows(record, currentScopeVersion) {
|
|
23
|
+
return record !== undefined && record.revokedAt === undefined && record.scopeVersion === currentScopeVersion;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Gate B (§3.2): the business call executes only with a live consent at the
|
|
27
|
+
* current scope version AND fresh rights. A suspended account or a withdrawn
|
|
28
|
+
* share is refused with the row kept dormant, so reactivation or re-share
|
|
29
|
+
* resumes without a screen. A non-reader never sees the consent page.
|
|
30
|
+
*/
|
|
31
|
+
export function decideGateB(input) {
|
|
32
|
+
if (input.rights === 'gone')
|
|
33
|
+
return { allowed: false, refusal: 'refused', status: 404 };
|
|
34
|
+
if (input.rights === 'suspended')
|
|
35
|
+
return { allowed: false, refusal: 'refused', status: 401 };
|
|
36
|
+
if (input.rights === 'withdrawn')
|
|
37
|
+
return { allowed: false, refusal: 'refused', status: 404 };
|
|
38
|
+
if (!consentAllows(input.consent, input.currentScopeVersion)) {
|
|
39
|
+
return { allowed: false, refusal: 'reader_consent_required', scopeId: input.scopeId };
|
|
40
|
+
}
|
|
41
|
+
return { allowed: true };
|
|
42
|
+
}
|
package/dist/server/gc.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CommitExecutor, FinalizeTxClient } from './commit/types.js';
|
|
2
2
|
import { type PublicationBlobStore } from './publication.js';
|
|
3
|
+
import { type StagingStore, type UploadSessionStore } from './uploads.js';
|
|
3
4
|
export interface RefcountStore {
|
|
4
5
|
addRef(digest: string, holder: string): Promise<void>;
|
|
5
6
|
releaseRef(digest: string, holder: string): Promise<void>;
|
|
@@ -62,4 +63,20 @@ export declare function createMemoryDeletionClaimStore(): InspectableDeletionCla
|
|
|
62
63
|
export declare function createClaimGuardedRefs(refs: RefcountStore, claims: DeletionClaimStore): RefcountStore;
|
|
63
64
|
/** Create a GC service over an injected refcount store (no driver imports). */
|
|
64
65
|
export declare function createGcService(refs: RefcountStore): GcService;
|
|
66
|
+
export interface UploadSweepReport {
|
|
67
|
+
expired: string[];
|
|
68
|
+
deletedKeys: string[];
|
|
69
|
+
failures: {
|
|
70
|
+
uploadId: string;
|
|
71
|
+
error: string;
|
|
72
|
+
}[];
|
|
73
|
+
}
|
|
74
|
+
export interface UploadSweeper {
|
|
75
|
+
sweep(now?: Date): Promise<UploadSweepReport>;
|
|
76
|
+
}
|
|
77
|
+
/** Create the enforced staging sweeper over the injected session/staging ports. */
|
|
78
|
+
export declare function createUploadSweeper(deps: {
|
|
79
|
+
sessions: UploadSessionStore;
|
|
80
|
+
staging: Pick<StagingStore, 'delete' | 'listKeys'>;
|
|
81
|
+
}): UploadSweeper;
|
|
65
82
|
export {};
|
package/dist/server/gc.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { createKeyMutex } from './ports.js';
|
|
14
14
|
import { blobDigestOfKey } from './publication.js';
|
|
15
|
+
import { stagingKey } from './uploads.js';
|
|
15
16
|
/** In-memory RefcountStore double (yields mid-update to expose races). */
|
|
16
17
|
export function createMemoryRefcountStore() {
|
|
17
18
|
const holders = new Map();
|
|
@@ -251,3 +252,24 @@ export function createGcService(refs) {
|
|
|
251
252
|
},
|
|
252
253
|
};
|
|
253
254
|
}
|
|
255
|
+
/** Create the enforced staging sweeper over the injected session/staging ports. */
|
|
256
|
+
export function createUploadSweeper(deps) {
|
|
257
|
+
return {
|
|
258
|
+
async sweep(at = new Date()) {
|
|
259
|
+
const report = { expired: [], deletedKeys: [], failures: [] };
|
|
260
|
+
for (const session of await deps.sessions.listExpiredOpen(at)) {
|
|
261
|
+
const key = stagingKey(session.storageScopeId, session.uploadId);
|
|
262
|
+
try {
|
|
263
|
+
await deps.staging.delete(key);
|
|
264
|
+
await deps.sessions.markExpired(session.uploadId);
|
|
265
|
+
report.expired.push(session.uploadId);
|
|
266
|
+
report.deletedKeys.push(key);
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
report.failures.push({ uploadId: session.uploadId, error: String(error) });
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return report;
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AccessEvent, type AccessMode, type ArtifactAcl, type GrantRecord } from './access.js';
|
|
2
|
-
import { type SharingPolicyPort } from './ports.js';
|
|
2
|
+
import { type PrincipalDirectoryPort, type SharingPolicyPort } from './ports.js';
|
|
3
3
|
import type { ArtifactInvocationContext, ArtifactCommitCoordinator, FinalizeTxClient } from './commit/types.js';
|
|
4
4
|
import type { EffectiveArtifactCommand } from './command-identity.js';
|
|
5
5
|
import { ArtifactOperationError, type ArtifactOutcome } from './failures.js';
|
|
@@ -55,4 +55,6 @@ export declare function manageArtifact(deps: {
|
|
|
55
55
|
profileAllowPublicSharing?: boolean;
|
|
56
56
|
/** G1: server-resolved platform admin predicate (never a tool argument). */
|
|
57
57
|
actorIsAdmin?: (actorId: string, storageScopeId: string) => boolean | Promise<boolean>;
|
|
58
|
+
/** G2: host principal directory; required for userRef resolution and output projection. */
|
|
59
|
+
directory?: PrincipalDirectoryPort;
|
|
58
60
|
}, invocation: ArtifactInvocationContext, command: EffectiveArtifactCommand, proof?: string): Promise<ArtifactOutcome<unknown>>;
|