@sentropic/artifacts 0.2.12 → 0.2.14
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 +93 -0
- package/README.md +45 -10
- package/dist/adapters/local-blob.d.ts +3 -0
- package/dist/adapters/local-blob.js +93 -0
- 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-uploads.d.ts +14 -0
- package/dist/adapters/postgres-uploads.js +174 -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/adapters/s3.js +23 -0
- package/dist/adapters/sqlite-activation.d.ts +20 -0
- package/dist/adapters/sqlite-activation.js +205 -0
- package/dist/adapters/sqlite-commit.d.ts +15 -0
- package/dist/adapters/sqlite-commit.js +89 -0
- package/dist/adapters/sqlite-management.d.ts +10 -0
- package/dist/adapters/sqlite-management.js +60 -0
- package/dist/adapters/sqlite-sql.d.ts +32 -0
- package/dist/adapters/sqlite-sql.js +36 -0
- package/dist/adapters/sqlite-store.d.ts +12 -0
- package/dist/adapters/sqlite-store.js +410 -0
- package/dist/adapters/sqlite.d.ts +33 -0
- package/dist/adapters/sqlite.js +95 -0
- package/dist/content/handler.d.ts +5 -0
- package/dist/content/handler.js +80 -9
- package/dist/content/headers.js +12 -0
- package/dist/http.d.ts +32 -2
- package/dist/http.js +615 -13
- package/dist/mcp-core.d.ts +3 -3
- package/dist/mcp-core.js +90 -4
- package/dist/profile/contracts.d.ts +1 -1
- package/dist/profile/contracts.js +7 -0
- package/dist/profile/index.js +43 -2
- package/dist/profile/radar.js +7 -0
- package/dist/profile/schemas.js +119 -0
- package/dist/profile/validation.d.ts +11 -0
- package/dist/profile/validation.js +98 -6
- package/dist/server/access.d.ts +2 -0
- package/dist/server/command-identity.d.ts +1 -1
- package/dist/server/command-identity.js +6 -3
- package/dist/server/consent.d.ts +65 -0
- package/dist/server/consent.js +42 -0
- package/dist/server/gc.d.ts +42 -0
- package/dist/server/gc.js +98 -0
- package/dist/server/management.d.ts +3 -1
- package/dist/server/management.js +48 -7
- package/dist/server/metrics.d.ts +21 -0
- package/dist/server/metrics.js +6 -0
- 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 +20 -0
- package/dist/server/publication-limits.js +27 -1
- package/dist/server/publication.d.ts +14 -0
- package/dist/server/publication.js +10 -2
- package/dist/server/reader-store.d.ts +58 -0
- package/dist/server/reader-store.js +109 -0
- package/dist/server/source-read.d.ts +12 -9
- package/dist/server/source-read.js +17 -5
- package/dist/server/templates.js +50 -2
- package/dist/server/upload-page.d.ts +157 -0
- package/dist/server/upload-page.js +438 -0
- package/dist/server/uploads.d.ts +229 -19
- package/dist/server/uploads.js +387 -80
- package/migrations/0007_uploads.sql +43 -0
- package/migrations/0008_reader_consent.sql +48 -0
- package/migrations/0009_upload_pages.sql +25 -0
- package/package.json +34 -1
- package/sql/reader-consent.sql +47 -0
- package/sql/sqlite/0001_artifacts.sql +156 -0
- package/sql/sqlite/0002_activation.sql +73 -0
package/dist/http.js
CHANGED
|
@@ -5,8 +5,14 @@ import { assertCompiledArtifactsProfile, ArtifactProfileInputError } from './pro
|
|
|
5
5
|
import { createArtifactCommand } from './server/command-identity.js';
|
|
6
6
|
import { createGuardedEnsureService } from './server/service.js';
|
|
7
7
|
import { assertArtifactReplayMigration } from './server/idempotency.js';
|
|
8
|
-
import { combineSharingPolicy, resolveSharingPolicy } from './server/ports.js';
|
|
8
|
+
import { combineSharingPolicy, maskEmailHint, resolveSharingPolicy } from './server/ports.js';
|
|
9
9
|
import { createGuardedPublicationService } from './server/publication.js';
|
|
10
|
+
import { SERVER_MAX_FILE_BYTES, SERVER_MAX_SOURCE_FILES, SERVER_MAX_SOURCE_INLINE_BYTES, SERVER_MAX_SOURCE_TOTAL_BYTES, SERVER_MAX_UPLOAD_SESSIONS_PER_PRINCIPAL } from './server/publication-limits.js';
|
|
11
|
+
import { releaseBudget } from './profile/validation.js';
|
|
12
|
+
import { commitStagedUpload, createUploadService, STAGED_FILE_TTL_MS, stagedFileExpired } from './server/uploads.js';
|
|
13
|
+
import { createHmacUploadPageCookieSigner, createMemoryUploadPageStore, createUploadPageService } from './server/upload-page.js';
|
|
14
|
+
import { accessModeOf, evaluateGrant } from './server/access.js';
|
|
15
|
+
import { assertConsentScopeId } from './server/consent.js';
|
|
10
16
|
import { applyEdits } from './server/edits.js';
|
|
11
17
|
import { CommitQuarantineError } from './server/commit/types.js';
|
|
12
18
|
import { ArtifactOperationError, classifyArtifactFailure } from './server/failures.js';
|
|
@@ -16,13 +22,13 @@ import { artifactSummary } from './server/summary.js';
|
|
|
16
22
|
import { artifactVersions } from './server/versions.js';
|
|
17
23
|
import { manageArtifact } from './server/management.js';
|
|
18
24
|
import { createPostgresManagementUnit } from './adapters/postgres-management.js';
|
|
19
|
-
import { TEXT_MIME_RE } from './server/mime.js';
|
|
25
|
+
import { TEXT_MIME_RE, validateFileBytes } from './server/mime.js';
|
|
20
26
|
import { API_GUIDE_REF } from './server/templates.js';
|
|
21
27
|
export { projectArtifactHttpOutcome } from './server/outcome-projection.js';
|
|
22
28
|
/** Stable content-route error codes; private driver messages never leave the host. */
|
|
23
29
|
export function errorBody(status) {
|
|
24
30
|
return { error: { 400: 'invalid_request', 401: 'anonymous', 403: 'access_denied',
|
|
25
|
-
404: 'not_found', 409: 'conflict', 410: 'gone', 422: 'verification_failed',
|
|
31
|
+
404: 'not_found', 409: 'conflict', 410: 'gone', 416: 'range_not_satisfiable', 422: 'verification_failed',
|
|
26
32
|
500: 'internal_error', 503: 'capability_unavailable' }[status] ?? 'internal_error' };
|
|
27
33
|
}
|
|
28
34
|
/** Retained for consumers describing canonical textual publication inputs. */
|
|
@@ -36,7 +42,11 @@ function object(value) {
|
|
|
36
42
|
export function assertArtifactsTransportProfile(value) {
|
|
37
43
|
assertCompiledArtifactsProfile(value);
|
|
38
44
|
const supported = ['artifacts_ensure', 'artifacts_publish', 'artifacts_list', 'artifacts_get',
|
|
39
|
-
'artifacts_list_versions', 'artifacts_get_source', 'artifacts_revert', 'artifacts_set_access', 'artifacts_delete'
|
|
45
|
+
'artifacts_list_versions', 'artifacts_get_source', 'artifacts_revert', 'artifacts_set_access', 'artifacts_delete',
|
|
46
|
+
'artifacts_lookup_people', 'artifacts_list_access',
|
|
47
|
+
'artifacts_create_upload', 'artifacts_commit_upload', 'artifacts_publish_bundle',
|
|
48
|
+
'artifacts_create_upload_page', 'artifacts_list_assets', 'artifacts_publish_bundle_v2',
|
|
49
|
+
'artifacts_revoke_reader_consent'];
|
|
40
50
|
if (value.selectedCapabilities.some((name) => !supported.includes(name))) {
|
|
41
51
|
throw new Error('unsupported artifacts transport capability');
|
|
42
52
|
}
|
|
@@ -58,6 +68,43 @@ export function createHttpArtifactApp(deps) {
|
|
|
58
68
|
if (profile.selectedCapabilities.includes('artifacts_delete') && !deps.management?.confirmation) {
|
|
59
69
|
throw new Error('artifact delete confirmation port required');
|
|
60
70
|
}
|
|
71
|
+
// Files parity LOT 1: upload ports are required as soon as one upload capability is selected.
|
|
72
|
+
// list_assets needs only the session ledger (released listing works without staging/signer).
|
|
73
|
+
const uploadCapabilities = ['artifacts_create_upload', 'artifacts_commit_upload', 'artifacts_publish_bundle',
|
|
74
|
+
'artifacts_create_upload_page', 'artifacts_publish_bundle_v2'];
|
|
75
|
+
const needsUploads = uploadCapabilities.some((name) => profile.selectedCapabilities.includes(name));
|
|
76
|
+
if (needsUploads && !deps.uploads)
|
|
77
|
+
throw new Error('artifact upload ports required');
|
|
78
|
+
const budget = releaseBudget(profile);
|
|
79
|
+
const uploadService = deps.uploads === undefined ? undefined : createUploadService({ sessions: deps.uploads.sessions, staging: deps.uploads.staging, signer: deps.uploads.signer }, { maxUploadBytes: Math.min(budget.fileBytesMax, SERVER_MAX_FILE_BYTES),
|
|
80
|
+
maxSessionsPerPrincipal: SERVER_MAX_UPLOAD_SESSIONS_PER_PRINCIPAL,
|
|
81
|
+
...(deps.uploads.stagedFileTtlMs === undefined ? {} : { stagedFileTtlMs: deps.uploads.stagedFileTtlMs }),
|
|
82
|
+
...(deps.uploads.stagingQuotaBytesPerScope === undefined ? {}
|
|
83
|
+
: { stagingQuotaBytesPerScope: deps.uploads.stagingQuotaBytesPerScope }),
|
|
84
|
+
...(deps.uploads.metrics === undefined ? {} : { metrics: deps.uploads.metrics }) });
|
|
85
|
+
// LOT 2 §A: the browser page shares the session ledger, the CAS blobs and
|
|
86
|
+
// the refs with the agent channel, so quotas cover both together.
|
|
87
|
+
if (profile.selectedCapabilities.includes('artifacts_create_upload_page') && deps.uploadPage === undefined) {
|
|
88
|
+
throw new Error('artifacts control plane needs upload page host wiring (uploadPage)');
|
|
89
|
+
}
|
|
90
|
+
const pageService = profile.selectedCapabilities.includes('artifacts_create_upload_page') &&
|
|
91
|
+
uploadService !== undefined ? createUploadPageService({
|
|
92
|
+
pages: deps.uploadPage?.pages ?? createMemoryUploadPageStore(),
|
|
93
|
+
sessions: deps.uploads.sessions, staging: deps.uploads.staging, signer: deps.uploads.signer,
|
|
94
|
+
blobs: deps.publication.blobs, refs: deps.publication.refs,
|
|
95
|
+
...(deps.uploads.idempotency === undefined ? {} : { idempotency: deps.uploads.idempotency }),
|
|
96
|
+
cookieSigner: createHmacUploadPageCookieSigner({ secret: deps.uploadPage.cookieSecret }),
|
|
97
|
+
controlOrigin: deps.uploadPage.controlOrigin, pageBaseUrl: deps.uploadPage.pageBaseUrl,
|
|
98
|
+
s3Origins: deps.uploadPage.s3Origins,
|
|
99
|
+
profile: { maxFiles: budget.filesMax, maxFileBytes: budget.fileBytesMax,
|
|
100
|
+
maxTotalBytes: budget.totalBytesMax, mimeTypes: profile.rules.mimeTypes,
|
|
101
|
+
pathMaxBytes: profile.rules.pathMaxBytes },
|
|
102
|
+
budget: { filesMax: budget.filesMax, totalBytesMax: budget.totalBytesMax },
|
|
103
|
+
...(deps.uploads.stagingQuotaBytesPerScope === undefined ? {}
|
|
104
|
+
: { stagingQuotaBytesPerScope: deps.uploads.stagingQuotaBytesPerScope }),
|
|
105
|
+
...(deps.uploads.metrics === undefined ? {} : { metrics: deps.uploads.metrics }),
|
|
106
|
+
}) : undefined;
|
|
107
|
+
const stagedFileTtlMs = deps.uploads?.stagedFileTtlMs ?? STAGED_FILE_TTL_MS;
|
|
61
108
|
const ensure = createGuardedEnsureService({ profile, coordinator: deps.coordinator,
|
|
62
109
|
derivation: deps.derivation, host: {
|
|
63
110
|
lockBinding: (client, binding) => deps.ensureHost.lockBinding(client, binding),
|
|
@@ -92,6 +139,144 @@ export function createHttpArtifactApp(deps) {
|
|
|
92
139
|
}
|
|
93
140
|
return acl;
|
|
94
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Files parity LOT 2 — resolve the files/assets union to bytes BEFORE any
|
|
144
|
+
* commit step. One missing, expired, digest-mismatched or unauthorized asset
|
|
145
|
+
* fails the whole publish and commits nothing. v1 only produces inline,
|
|
146
|
+
* upload and cas forms; v2 additionally resolves copy/carry and the
|
|
147
|
+
* keep-unmodified carry of the expected current release.
|
|
148
|
+
*/
|
|
149
|
+
async function resolveBundleAssets(invocation, artifactId, entries, options) {
|
|
150
|
+
const fail = (path, reason) => {
|
|
151
|
+
throw new ArtifactOperationError('verification_failed', { publicDetails: { asset: { path, reason } } });
|
|
152
|
+
};
|
|
153
|
+
const checkBytes = (path, mimeType, bytes) => {
|
|
154
|
+
if (!profile.rules.mimeTypes.includes(mimeType))
|
|
155
|
+
fail(path, 'MIME type not allowed by profile');
|
|
156
|
+
validateFileBytes(mimeType, bytes);
|
|
157
|
+
};
|
|
158
|
+
const readCas = async (path, digest, size) => {
|
|
159
|
+
const bytes = await deps.publication.blobs.getBlob(blobKey(invocation.storageScopeId, digest)) ??
|
|
160
|
+
fail(path, 'blob missing');
|
|
161
|
+
if (bytes.length !== size ||
|
|
162
|
+
`sha256:${createHash('sha256').update(bytes).digest('hex')}` !== digest) {
|
|
163
|
+
fail(path, 'size/digest mismatch');
|
|
164
|
+
}
|
|
165
|
+
return bytes;
|
|
166
|
+
};
|
|
167
|
+
const files = [];
|
|
168
|
+
const origins = {};
|
|
169
|
+
const uploadPins = [];
|
|
170
|
+
for (const file of entries.files) {
|
|
171
|
+
const bytes = Uint8Array.from(file.bytes);
|
|
172
|
+
checkBytes(file.path, file.mimeType, bytes);
|
|
173
|
+
files.push({ path: file.path, mimeType: file.mimeType, bytes });
|
|
174
|
+
origins[file.path] = 'inline';
|
|
175
|
+
}
|
|
176
|
+
for (const asset of entries.assets) {
|
|
177
|
+
const path = asset.path;
|
|
178
|
+
if (Object.hasOwn(asset, 'uploadId')) {
|
|
179
|
+
const staged = await deps.uploads.sessions.getStagedFile(asset.uploadId) ??
|
|
180
|
+
fail(path, 'unknown upload');
|
|
181
|
+
if (staged.artifactId !== artifactId)
|
|
182
|
+
fail(path, 'unknown upload');
|
|
183
|
+
if (stagedFileExpired(staged, Date.now(), stagedFileTtlMs))
|
|
184
|
+
fail(path, 'staged file expired');
|
|
185
|
+
const bytes = await deps.publication.blobs.getBlob(blobKey(invocation.storageScopeId, staged.digest)) ??
|
|
186
|
+
fail(path, 'staged blob missing or digest mismatch');
|
|
187
|
+
if (bytes.length !== staged.size ||
|
|
188
|
+
`sha256:${createHash('sha256').update(bytes).digest('hex')}` !== staged.digest) {
|
|
189
|
+
fail(path, 'staged blob missing or digest mismatch');
|
|
190
|
+
}
|
|
191
|
+
checkBytes(path, staged.mimeType, bytes);
|
|
192
|
+
files.push({ path, mimeType: staged.mimeType, bytes });
|
|
193
|
+
origins[path] = `upload:${staged.uploadId}`;
|
|
194
|
+
uploadPins.push({ digest: staged.digest, uploadId: staged.uploadId });
|
|
195
|
+
}
|
|
196
|
+
else if (Object.hasOwn(asset, 'sourceArtifactId') || Object.hasOwn(asset, 'carryFromReleaseId')) {
|
|
197
|
+
if (!options.allowExtendedForms)
|
|
198
|
+
fail(path, 'extended asset form needs publish_bundle_v2');
|
|
199
|
+
const copy = await resolveCopiedAsset(invocation, artifactId, asset, fail);
|
|
200
|
+
// The copied/carried MIME comes from a manifest, not the caller: it
|
|
201
|
+
// must still be inside the target profile allowlist (v1 forms keep
|
|
202
|
+
// their LOT 1 magic-only check; only the staged TTL is new there).
|
|
203
|
+
if (!profile.rules.mimeTypes.includes(copy.mimeType))
|
|
204
|
+
fail(path, 'MIME type not allowed by profile');
|
|
205
|
+
checkBytes(path, copy.mimeType, copy.bytes);
|
|
206
|
+
files.push({ path, mimeType: copy.mimeType, bytes: copy.bytes });
|
|
207
|
+
origins[path] = copy.origin;
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
const digest = asset.digest;
|
|
211
|
+
const size = asset.size;
|
|
212
|
+
const mimeType = asset.mimeType;
|
|
213
|
+
const bytes = await readCas(path, digest, size);
|
|
214
|
+
checkBytes(path, mimeType, bytes);
|
|
215
|
+
files.push({ path, mimeType, bytes });
|
|
216
|
+
origins[path] = 'cas';
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (options.keepUnmodifiedPaths && options.expectedCurrentReleaseId !== null) {
|
|
220
|
+
const base = await deps.publication.getRelease(options.expectedCurrentReleaseId) ??
|
|
221
|
+
fail('(base release)', 'unknown release');
|
|
222
|
+
if (base.artifactId !== artifactId)
|
|
223
|
+
fail('(base release)', 'unknown release');
|
|
224
|
+
const manifest = parseManifest(base.manifest);
|
|
225
|
+
for (const file of manifest.files ?? []) {
|
|
226
|
+
if (Object.hasOwn(origins, file.path))
|
|
227
|
+
continue;
|
|
228
|
+
const bytes = await readCas(file.path, file.digest, file.size);
|
|
229
|
+
checkBytes(file.path, file.mimeType, bytes);
|
|
230
|
+
files.push({ path: file.path, mimeType: file.mimeType, bytes });
|
|
231
|
+
origins[file.path] = `carry:${options.expectedCurrentReleaseId}`;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return { files, origins, uploadPins };
|
|
235
|
+
}
|
|
236
|
+
/** Copy/carry resolution for `artifacts_publish_bundle_v2` (same failure contract). */
|
|
237
|
+
async function resolveCopiedAsset(invocation, artifactId, asset, fail) {
|
|
238
|
+
const path = asset.path;
|
|
239
|
+
const readManifestFile = async (sourceArtifactId, sourceReleaseId, sourcePath) => {
|
|
240
|
+
const sourceAcl = await deps.acls.getArtifactAcl(sourceArtifactId) ??
|
|
241
|
+
fail(path, 'unknown source artifact');
|
|
242
|
+
if (sourceAcl.storageScopeId !== invocation.storageScopeId)
|
|
243
|
+
fail(path, 'cross-scope copy not supported');
|
|
244
|
+
const sourceState = await deps.lifecycle.stateOf(sourceArtifactId);
|
|
245
|
+
if (!deps.lifecycle.canRead({ artifactId: sourceArtifactId, state: sourceState }, sourceAcl, invocation.actorId, 'source', deps.isApprovedAccount, await sharingPolicyContext(invocation.storageScopeId))) {
|
|
246
|
+
throw new ArtifactOperationError('access_denied');
|
|
247
|
+
}
|
|
248
|
+
const release = (sourceReleaseId === undefined ? await deps.publication.getCurrent(sourceArtifactId)
|
|
249
|
+
: deps.publication.getRelease === undefined ? undefined
|
|
250
|
+
: await deps.publication.getRelease(sourceReleaseId)) ?? fail(path, 'unknown source release');
|
|
251
|
+
if (release.artifactId !== sourceArtifactId)
|
|
252
|
+
fail(path, 'unknown source release');
|
|
253
|
+
const manifest = parseManifest(release.manifest);
|
|
254
|
+
const wanted = sourcePath ?? path;
|
|
255
|
+
const entry = (manifest.files ?? []).find((file) => file.path === wanted) ??
|
|
256
|
+
fail(path, 'source path missing');
|
|
257
|
+
const bytes = await deps.publication.blobs.getBlob(blobKey(invocation.storageScopeId, entry.digest)) ??
|
|
258
|
+
fail(path, 'source blob missing or digest mismatch');
|
|
259
|
+
if (bytes.length !== entry.size ||
|
|
260
|
+
`sha256:${createHash('sha256').update(bytes).digest('hex')}` !== entry.digest) {
|
|
261
|
+
fail(path, 'source blob missing or digest mismatch');
|
|
262
|
+
}
|
|
263
|
+
return { mimeType: entry.mimeType, bytes };
|
|
264
|
+
};
|
|
265
|
+
if (Object.hasOwn(asset, 'sourceArtifactId')) {
|
|
266
|
+
const sourceArtifactId = asset.sourceArtifactId;
|
|
267
|
+
const { mimeType, bytes } = await readManifestFile(sourceArtifactId, asset.sourceReleaseId, asset.sourcePath);
|
|
268
|
+
const release = asset.sourceReleaseId ??
|
|
269
|
+
await deps.publication.getCurrent(sourceArtifactId).then((current) => current?.releaseId);
|
|
270
|
+
return { mimeType, bytes, origin: `copy:${sourceArtifactId}:${release ?? 'current'}` };
|
|
271
|
+
}
|
|
272
|
+
const carryFromReleaseId = asset.carryFromReleaseId;
|
|
273
|
+
const release = await deps.publication.getRelease(carryFromReleaseId) ??
|
|
274
|
+
fail(path, 'unknown release');
|
|
275
|
+
if (release.artifactId !== artifactId)
|
|
276
|
+
fail(path, 'unknown release');
|
|
277
|
+
const { mimeType, bytes } = await readManifestFile(artifactId, carryFromReleaseId, asset.sourcePath);
|
|
278
|
+
return { mimeType, bytes, origin: `carry:${carryFromReleaseId}` };
|
|
279
|
+
}
|
|
95
280
|
/**
|
|
96
281
|
* G1 management visibility for `set_access` (converged-r2 §2.3 order (2)):
|
|
97
282
|
* readers pass as before; any other actor gets `not_found` unless it is an
|
|
@@ -130,6 +315,54 @@ export function createHttpArtifactApp(deps) {
|
|
|
130
315
|
meta.icon = normalized.icon;
|
|
131
316
|
return Object.keys(meta).length > 0 ? meta : undefined;
|
|
132
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* G2 projection (converged-r2 §2.3): no internal principal id (`sub`) ever
|
|
320
|
+
* reaches a model payload. When a directory port is wired, every summary
|
|
321
|
+
* `ownerId` and grant `principalId` keeps its field name but carries the
|
|
322
|
+
* opaque `userRef` (re-injectable into `set_access`). Without a port the
|
|
323
|
+
* legacy trusted form is kept (G1 behaviour).
|
|
324
|
+
*/
|
|
325
|
+
async function projectUserRef(internalId, storageScopeId) {
|
|
326
|
+
if (!deps.directory)
|
|
327
|
+
return internalId;
|
|
328
|
+
return (await deps.directory.describePrincipal(storageScopeId, internalId))?.userRef ?? internalId;
|
|
329
|
+
}
|
|
330
|
+
async function projectSummary(summary, storageScopeId) {
|
|
331
|
+
if (!deps.directory)
|
|
332
|
+
return summary;
|
|
333
|
+
return { ...summary, ownerId: await projectUserRef(summary.ownerId, storageScopeId) };
|
|
334
|
+
}
|
|
335
|
+
async function projectGrants(grants, storageScopeId) {
|
|
336
|
+
if (!deps.directory)
|
|
337
|
+
return grants;
|
|
338
|
+
return Promise.all(grants.map(async (grant) => ({ ...grant,
|
|
339
|
+
principalId: await projectUserRef(grant.principalId, storageScopeId) })));
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* G2 visibility for `artifacts_list_access` (§2.3 order (2), same admin
|
|
343
|
+
* exception as `set_access`): the owner, a grant holder, a content reader
|
|
344
|
+
* or an APPROVED platform admin of the SAME storageScopeId pass; any other
|
|
345
|
+
* actor gets `not_found` so the artifact's existence never leaks. The
|
|
346
|
+
* exception never makes the admin a content reader.
|
|
347
|
+
*/
|
|
348
|
+
async function visibleForAccessList(artifactId, invocation) {
|
|
349
|
+
const acl = await deps.acls.getArtifactAcl(artifactId);
|
|
350
|
+
if (!acl || acl.storageScopeId !== invocation.storageScopeId)
|
|
351
|
+
throw new ArtifactOperationError('not_found');
|
|
352
|
+
if (acl.ownerId === invocation.actorId)
|
|
353
|
+
return acl;
|
|
354
|
+
if (acl.grants.some((grant) => grant.principalId === invocation.actorId))
|
|
355
|
+
return acl;
|
|
356
|
+
const state = await deps.lifecycle.stateOf(artifactId);
|
|
357
|
+
const policy = await sharingPolicyContext(invocation.storageScopeId);
|
|
358
|
+
if (deps.lifecycle.canRead({ artifactId, state }, acl, invocation.actorId, 'read', deps.isApprovedAccount, policy)) {
|
|
359
|
+
return acl;
|
|
360
|
+
}
|
|
361
|
+
if (await deps.actorIsAdmin?.(invocation.actorId, invocation.storageScopeId) === true &&
|
|
362
|
+
deps.isApprovedAccount?.(invocation.actorId) === true)
|
|
363
|
+
return acl;
|
|
364
|
+
throw new ArtifactOperationError('not_found');
|
|
365
|
+
}
|
|
133
366
|
function blobKey(storageScopeId, digest) {
|
|
134
367
|
// Manifest digests are `sha256:<hex>`; physical keys are `.../blobs/sha256/<hex>`.
|
|
135
368
|
return `artifacts/${storageScopeId}/blobs/${digest.replace(':', '/')}`;
|
|
@@ -269,7 +502,8 @@ export function createHttpArtifactApp(deps) {
|
|
|
269
502
|
}
|
|
270
503
|
}
|
|
271
504
|
const normalized = profile.validate(capability, args, request.idempotencyKey, { deferPrecondition: true });
|
|
272
|
-
const command = ['artifacts_ensure', 'artifacts_publish', 'artifacts_set_access', 'artifacts_delete', 'artifacts_revert'
|
|
505
|
+
const command = ['artifacts_ensure', 'artifacts_publish', 'artifacts_set_access', 'artifacts_delete', 'artifacts_revert',
|
|
506
|
+
'artifacts_commit_upload', 'artifacts_publish_bundle', 'artifacts_publish_bundle_v2'].includes(capability)
|
|
273
507
|
? createArtifactCommand(profile, capability, args, invocation, deps.derivation, request.idempotencyKey, { deferPrecondition: true }) : undefined;
|
|
274
508
|
if (command && ['ensure', 'publish'].includes(command.operation)) {
|
|
275
509
|
phase = 'migration';
|
|
@@ -289,15 +523,18 @@ export function createHttpArtifactApp(deps) {
|
|
|
289
523
|
return outcome;
|
|
290
524
|
const artifactId = outcome.result.artifactId;
|
|
291
525
|
const acl = await visible(artifactId, invocation);
|
|
292
|
-
const summary = artifactSummary({ artifactId, acl, actorId: invocation.actorId,
|
|
526
|
+
const summary = await projectSummary(artifactSummary({ artifactId, acl, actorId: invocation.actorId,
|
|
293
527
|
state: await deps.lifecycle.stateOf(artifactId), current: await deps.publication.getCurrent(artifactId),
|
|
294
528
|
urls: deps.publicationUrls, approved: deps.isApprovedAccount,
|
|
295
|
-
policy: await sharingPolicyContext(invocation.storageScopeId) });
|
|
529
|
+
policy: await sharingPolicyContext(invocation.storageScopeId) }), invocation.storageScopeId);
|
|
296
530
|
return { ...outcome, result: { status: 201, body: profile.resultEnvelopeVersion === 2
|
|
297
531
|
? { ...summary, ...outcome.result } : { ...outcome.result, ...acl.metadata } } };
|
|
298
532
|
}
|
|
299
533
|
if (capability === 'artifacts_get_source') {
|
|
300
534
|
const artifactId = normalized.artifactId;
|
|
535
|
+
// LOT 2 §B.3: profile caps instead of hard-coded ceilings (fail-closed
|
|
536
|
+
// at compile time; defaults stay 32 files / 262 144 B total).
|
|
537
|
+
const sourceOp = profile.operations.find((entry) => entry.operation === 'get_source');
|
|
301
538
|
const result = await readArtifactSource({
|
|
302
539
|
storageScopeId: invocation.storageScopeId,
|
|
303
540
|
authorize: async () => {
|
|
@@ -308,11 +545,82 @@ export function createHttpArtifactApp(deps) {
|
|
|
308
545
|
}
|
|
309
546
|
}, getCurrent: deps.publication.getCurrent, getRelease: deps.publication.getRelease,
|
|
310
547
|
getSource: (id) => deps.sources.getSource(id), getBlob: (key) => deps.publication.blobs.getBlob(key),
|
|
311
|
-
urls: deps.publicationUrls,
|
|
548
|
+
urls: deps.publicationUrls,
|
|
549
|
+
maxFiles: sourceOp?.limits['sourceFilesMax'] ?? SERVER_MAX_SOURCE_FILES,
|
|
550
|
+
maxInlineBytes: sourceOp?.limits['sourceInlineFileBytesMax'] ?? SERVER_MAX_SOURCE_INLINE_BYTES,
|
|
551
|
+
maxTotalBytes: sourceOp?.limits['sourceTotalBytesMax'] ?? SERVER_MAX_SOURCE_TOTAL_BYTES,
|
|
312
552
|
}, normalized);
|
|
313
553
|
return { ok: true, result: { status: 200, body: result }, invocationId: invocation.invocationId,
|
|
314
554
|
commitState: 'not_committed', replayed: false };
|
|
315
555
|
}
|
|
556
|
+
if (capability === 'artifacts_list_assets') {
|
|
557
|
+
const artifactId = normalized.artifactId;
|
|
558
|
+
const acl = await visible(artifactId, invocation);
|
|
559
|
+
const listState = normalized.state ?? 'all';
|
|
560
|
+
const wantStaged = listState === 'staged' || listState === 'all';
|
|
561
|
+
const wantReleased = listState === 'released' || listState === 'all';
|
|
562
|
+
// Staged rows are owner-only (access_denied, never a filtered empty list);
|
|
563
|
+
// the source read right gates the released branch below.
|
|
564
|
+
if (wantStaged && acl.ownerId !== invocation.actorId) {
|
|
565
|
+
throw new ArtifactOperationError('access_denied');
|
|
566
|
+
}
|
|
567
|
+
const limit = normalized.limit;
|
|
568
|
+
const cursor = normalized.cursor;
|
|
569
|
+
const releaseId = normalized.releaseId;
|
|
570
|
+
const pageSessionId = normalized.pageSessionId;
|
|
571
|
+
const stagedEntries = [];
|
|
572
|
+
if (wantStaged) {
|
|
573
|
+
if (deps.uploads === undefined)
|
|
574
|
+
throw new ArtifactProfileInputError(true);
|
|
575
|
+
const rows = await deps.uploads.sessions.listStagedFiles(artifactId);
|
|
576
|
+
for (const record of rows
|
|
577
|
+
.filter((entry) => pageSessionId === undefined || entry.pageSessionId === pageSessionId)
|
|
578
|
+
.sort((left, right) => (left.path < right.path ? -1 : left.path > right.path ? 1 : 0))) {
|
|
579
|
+
stagedEntries.push({ path: record.path, mimeType: record.mimeType, size: record.size,
|
|
580
|
+
digest: record.digest, state: 'staged', uploadId: record.uploadId,
|
|
581
|
+
...(record.pageSessionId === undefined ? {} : { pageSessionId: record.pageSessionId }) });
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
const releasedEntries = [];
|
|
585
|
+
let listedReleaseId;
|
|
586
|
+
if (wantReleased) {
|
|
587
|
+
const artifactState = await deps.lifecycle.stateOf(artifactId);
|
|
588
|
+
if (!deps.lifecycle.canRead({ artifactId, state: artifactState }, acl, invocation.actorId, 'source', deps.isApprovedAccount, await sharingPolicyContext(invocation.storageScopeId))) {
|
|
589
|
+
throw new ArtifactOperationError('access_denied');
|
|
590
|
+
}
|
|
591
|
+
const current = releaseId === undefined ? await deps.publication.getCurrent(artifactId)
|
|
592
|
+
: deps.publication.getRelease === undefined ? undefined
|
|
593
|
+
: await deps.publication.getRelease(releaseId);
|
|
594
|
+
// A release of another artifact reads as empty (no cross-artifact oracle).
|
|
595
|
+
if (current !== undefined && (releaseId === undefined || current.artifactId === artifactId)) {
|
|
596
|
+
listedReleaseId = current.releaseId;
|
|
597
|
+
const manifest = parseManifest(current.manifest);
|
|
598
|
+
for (const file of manifest.files ?? []) {
|
|
599
|
+
releasedEntries.push({ path: file.path, mimeType: file.mimeType, size: file.size,
|
|
600
|
+
digest: file.digest, state: 'released', releaseId: current.releaseId });
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
const stagedPaths = new Set(stagedEntries.map((entry) => entry.path));
|
|
605
|
+
const entries = [...stagedEntries,
|
|
606
|
+
...releasedEntries.filter((entry) => !stagedPaths.has(entry.path))];
|
|
607
|
+
let offset = 0;
|
|
608
|
+
if (cursor !== undefined) {
|
|
609
|
+
const decoded = Buffer.from(cursor, 'base64url').toString('utf8');
|
|
610
|
+
const match = /^lot2-assets:(\d+)$/.exec(decoded);
|
|
611
|
+
if (match?.[1] === undefined || !Number.isSafeInteger(Number(match[1]))) {
|
|
612
|
+
throw new ArtifactProfileInputError();
|
|
613
|
+
}
|
|
614
|
+
offset = Math.min(Number(match[1]), entries.length);
|
|
615
|
+
}
|
|
616
|
+
const page = entries.slice(offset, offset + limit);
|
|
617
|
+
const nextCursor = offset + limit < entries.length
|
|
618
|
+
? Buffer.from(`lot2-assets:${offset + limit}`, 'utf8').toString('base64url') : undefined;
|
|
619
|
+
return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
|
|
620
|
+
result: { status: 200, body: { artifactId,
|
|
621
|
+
...(listedReleaseId === undefined ? {} : { releaseId: listedReleaseId }), assets: page,
|
|
622
|
+
total: entries.length, ...(nextCursor === undefined ? {} : { nextCursor }) } } };
|
|
623
|
+
}
|
|
316
624
|
if (capability === 'artifacts_set_access' || capability === 'artifacts_delete') {
|
|
317
625
|
const artifactId = normalized.artifactId;
|
|
318
626
|
const acl = capability === 'artifacts_set_access'
|
|
@@ -328,10 +636,37 @@ export function createHttpArtifactApp(deps) {
|
|
|
328
636
|
sharingPolicy: deps.sharingPolicy,
|
|
329
637
|
profileAllowPublicSharing: profile.rules.allowPublicSharing,
|
|
330
638
|
actorIsAdmin: deps.actorIsAdmin,
|
|
639
|
+
directory: deps.directory,
|
|
331
640
|
validateNewCommand: () => { profile.validate(capability, args, request.idempotencyKey); },
|
|
332
641
|
}, invocation, command, normalized.confirmationRef);
|
|
333
642
|
return outcome.ok ? { ...outcome, result: { status: 200, body: outcome.result } } : outcome;
|
|
334
643
|
}
|
|
644
|
+
if (capability === 'artifacts_revoke_reader_consent') {
|
|
645
|
+
// Self-revocation only: the reader is the invocation principal
|
|
646
|
+
// (mcp-core.ts:225); no principalId argument exists, so the model
|
|
647
|
+
// can never target another person. Error order: syntax (validated
|
|
648
|
+
// above) → visibility (not_found, no existence oracle) → store
|
|
649
|
+
// gate (capability_unavailable when no port is wired).
|
|
650
|
+
const artifactId = normalized.artifactId;
|
|
651
|
+
await visible(artifactId, invocation);
|
|
652
|
+
const store = deps.readerConsent;
|
|
653
|
+
if (!store)
|
|
654
|
+
throw new ArtifactProfileInputError(true);
|
|
655
|
+
const scope = normalized.scope;
|
|
656
|
+
if (scope !== undefined)
|
|
657
|
+
assertConsentScopeId(scope);
|
|
658
|
+
const at = new Date().toISOString();
|
|
659
|
+
// The route serves the MCP revocation tool; the api binding records
|
|
660
|
+
// first-party screen/api surfaces through the service layer instead.
|
|
661
|
+
const audit = { actor: invocation.actorId, surface: 'mcp' };
|
|
662
|
+
const result = await store.revokeAllConsents({ storageScopeId: invocation.storageScopeId,
|
|
663
|
+
readerAccountId: invocation.actorId, artifactId, ...(scope === undefined ? {} : { scopeId: scope }) }, 'self', at, audit);
|
|
664
|
+
return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed',
|
|
665
|
+
replayed: false, result: { status: 200, body: scope === undefined
|
|
666
|
+
? { artifactId, scopeId: null, changed: result.changed, revoked: result.revoked }
|
|
667
|
+
: { artifactId, scopeId: scope, changed: result.changed,
|
|
668
|
+
revokedAt: result.changed ? at : null } } };
|
|
669
|
+
}
|
|
335
670
|
if (capability === 'artifacts_publish' || capability === 'artifacts_revert') {
|
|
336
671
|
const artifactId = normalized.artifactId;
|
|
337
672
|
const acl = await visible(artifactId, invocation);
|
|
@@ -383,23 +718,251 @@ export function createHttpArtifactApp(deps) {
|
|
|
383
718
|
source = { kind: 'base-commit', commit: releaseId };
|
|
384
719
|
releaseProfile = (targetManifest.profile ?? {});
|
|
385
720
|
}
|
|
721
|
+
if (capability === 'artifacts_publish') {
|
|
722
|
+
// B.2 MIME ceiling: magic-byte / strict-UTF-8 / SVG validation on every
|
|
723
|
+
// newly published file (revert re-releases already-verified blobs).
|
|
724
|
+
for (const file of files)
|
|
725
|
+
validateFileBytes(file.mimeType, file.bytes);
|
|
726
|
+
}
|
|
386
727
|
const outcome = await publication.publishFinalized({
|
|
387
728
|
...input, source, profile: releaseProfile, files,
|
|
388
729
|
});
|
|
389
730
|
const committed = commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; });
|
|
390
731
|
return await conflictSource(committed, normalized, invocation);
|
|
391
732
|
}
|
|
733
|
+
if (capability === 'artifacts_create_upload') {
|
|
734
|
+
const artifactId = normalized.artifactId;
|
|
735
|
+
const acl = await visible(artifactId, invocation);
|
|
736
|
+
if (acl.ownerId !== invocation.actorId)
|
|
737
|
+
throw new ArtifactOperationError('access_denied');
|
|
738
|
+
let created;
|
|
739
|
+
try {
|
|
740
|
+
created = await uploadService.create({
|
|
741
|
+
artifactId, storageScopeId: invocation.storageScopeId, ownerId: acl.ownerId,
|
|
742
|
+
mimeType: normalized.mimeType,
|
|
743
|
+
...(normalized.maxSize === undefined ? {} : { maxSize: normalized.maxSize }),
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
catch (cause) {
|
|
747
|
+
if (cause instanceof Error && /open upload session quota/.test(cause.message)) {
|
|
748
|
+
throw new ArtifactOperationError('limit_exceeded', { cause,
|
|
749
|
+
publicDetails: { upload: { reason: 'open_session_quota' } } });
|
|
750
|
+
}
|
|
751
|
+
if (cause instanceof Error && /scope staging quota/.test(cause.message)) {
|
|
752
|
+
throw new ArtifactOperationError('limit_exceeded', { cause,
|
|
753
|
+
publicDetails: { upload: { reason: 'scope_staging_quota' } } });
|
|
754
|
+
}
|
|
755
|
+
if (cause instanceof Error && /invalid/.test(cause.message))
|
|
756
|
+
throw new ArtifactProfileInputError();
|
|
757
|
+
throw cause;
|
|
758
|
+
}
|
|
759
|
+
return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
|
|
760
|
+
result: { status: 201, body: { uploadId: created.uploadId, uploadUrl: created.uploadUrl,
|
|
761
|
+
method: created.method, expiresAt: created.expiresAt, maxSize: created.maxSize,
|
|
762
|
+
requiredHeaders: created.requiredHeaders, checksumHeader: created.checksumHeader } } };
|
|
763
|
+
}
|
|
764
|
+
if (capability === 'artifacts_commit_upload') {
|
|
765
|
+
const artifactId = normalized.artifactId;
|
|
766
|
+
const acl = await visible(artifactId, invocation);
|
|
767
|
+
if (acl.ownerId !== invocation.actorId)
|
|
768
|
+
throw new ArtifactOperationError('access_denied');
|
|
769
|
+
const uploadId = normalized.uploadId;
|
|
770
|
+
const digest = normalized.digest;
|
|
771
|
+
const size = normalized.size;
|
|
772
|
+
const mimeType = normalized.mimeType;
|
|
773
|
+
const path = normalized.path;
|
|
774
|
+
const commitInput = { uploadId, artifactId, storageScopeId: invocation.storageScopeId,
|
|
775
|
+
ownerId: acl.ownerId, path, mimeType, digest, size };
|
|
776
|
+
// LOT 2: the shared commit core — same code as the browser page channel.
|
|
777
|
+
const commitDeps = { sessions: deps.uploads.sessions,
|
|
778
|
+
staging: deps.uploads.staging, blobs: deps.publication.blobs, refs: deps.publication.refs,
|
|
779
|
+
budget: { filesMax: budget.filesMax, totalBytesMax: budget.totalBytesMax },
|
|
780
|
+
...(deps.uploads.metrics === undefined ? {} : { metrics: deps.uploads.metrics }) };
|
|
781
|
+
const work = async () => {
|
|
782
|
+
let staged;
|
|
783
|
+
try {
|
|
784
|
+
staged = await commitStagedUpload(uploadService, commitDeps, commitInput);
|
|
785
|
+
}
|
|
786
|
+
catch (cause) {
|
|
787
|
+
if (cause instanceof Error && /budget exceeded/.test(cause.message)) {
|
|
788
|
+
throw new ArtifactOperationError('limit_exceeded', { cause,
|
|
789
|
+
publicDetails: { upload: { reason: 'staged_budget' } } });
|
|
790
|
+
}
|
|
791
|
+
if (cause instanceof Error && (/unknown upload/.test(cause.message) || /closed/.test(cause.message))) {
|
|
792
|
+
// One response for unknown, foreign-bound, closed or expired sessions (no oracle).
|
|
793
|
+
throw new ArtifactOperationError('verification_failed', { cause,
|
|
794
|
+
publicDetails: { upload: { reason: 'session unknown, bound elsewhere, closed or expired' } } });
|
|
795
|
+
}
|
|
796
|
+
if (cause instanceof Error && /staged object missing/.test(cause.message)) {
|
|
797
|
+
throw new ArtifactOperationError('verification_failed', { publicDetails: { upload: { reason: 'staged object missing' } } });
|
|
798
|
+
}
|
|
799
|
+
throw new ArtifactOperationError('verification_failed', { cause,
|
|
800
|
+
publicDetails: { upload: { reason: 'size/digest/MIME mismatch' } } });
|
|
801
|
+
}
|
|
802
|
+
return { artifactId, uploadId, path, mimeType, digest, size,
|
|
803
|
+
state: 'staged', stagedAt: staged.createdAt };
|
|
804
|
+
};
|
|
805
|
+
let body;
|
|
806
|
+
if (deps.uploads.idempotency !== undefined && command !== undefined) {
|
|
807
|
+
// Same key + same digest replays; same key + different payload is command_conflict.
|
|
808
|
+
const storeKey = JSON.stringify(['commit_upload', acl.ownerId, normalized.idempotencyKey]);
|
|
809
|
+
try {
|
|
810
|
+
const { result } = await deps.uploads.idempotency.execute(storeKey, command.identity.commandHash, work);
|
|
811
|
+
body = result;
|
|
812
|
+
}
|
|
813
|
+
catch (cause) {
|
|
814
|
+
if (cause instanceof Error && /idempotency conflict/.test(cause.message)) {
|
|
815
|
+
throw new ArtifactOperationError('command_conflict', { cause });
|
|
816
|
+
}
|
|
817
|
+
throw cause;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
else {
|
|
821
|
+
body = await work();
|
|
822
|
+
}
|
|
823
|
+
return { ok: true, invocationId: invocation.invocationId, commitState: 'committed', replayed: false,
|
|
824
|
+
result: { status: 201, body } };
|
|
825
|
+
}
|
|
826
|
+
if (capability === 'artifacts_create_upload_page') {
|
|
827
|
+
const artifactId = normalized.artifactId;
|
|
828
|
+
const acl = await visible(artifactId, invocation);
|
|
829
|
+
if (acl.ownerId !== invocation.actorId)
|
|
830
|
+
throw new ArtifactOperationError('access_denied');
|
|
831
|
+
let minted;
|
|
832
|
+
try {
|
|
833
|
+
minted = await pageService.mint({ artifactId, storageScopeId: invocation.storageScopeId,
|
|
834
|
+
ownerId: acl.ownerId,
|
|
835
|
+
...(normalized.maxFiles === undefined ? {} : { maxFiles: normalized.maxFiles }) });
|
|
836
|
+
}
|
|
837
|
+
catch (cause) {
|
|
838
|
+
if (cause instanceof Error && /quota exceeded/.test(cause.message)) {
|
|
839
|
+
throw new ArtifactOperationError('limit_exceeded', { cause,
|
|
840
|
+
publicDetails: { upload: { reason: 'open_page_quota' } } });
|
|
841
|
+
}
|
|
842
|
+
if (cause instanceof Error && /invalid/.test(cause.message))
|
|
843
|
+
throw new ArtifactProfileInputError();
|
|
844
|
+
throw cause;
|
|
845
|
+
}
|
|
846
|
+
return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
|
|
847
|
+
result: { status: 201, body: { pageSessionId: minted.pageSessionId,
|
|
848
|
+
uploadPageUrl: minted.uploadPageUrl, expiresAt: minted.expiresAt, maxFiles: minted.maxFiles,
|
|
849
|
+
maxFileBytes: minted.maxFileBytes, maxTotalBytes: minted.maxTotalBytes,
|
|
850
|
+
allowedMimeTypes: minted.allowedMimeTypes } } };
|
|
851
|
+
}
|
|
852
|
+
if (capability === 'artifacts_publish_bundle') {
|
|
853
|
+
const artifactId = normalized.artifactId;
|
|
854
|
+
const acl = await visible(artifactId, invocation);
|
|
855
|
+
if (acl.ownerId !== invocation.actorId)
|
|
856
|
+
throw new ArtifactOperationError('access_denied');
|
|
857
|
+
const publication = createGuardedPublicationService({ ...deps.publication, coordinator: deps.coordinator,
|
|
858
|
+
limits: { maxFiles: budget.filesMax, maxFileBytes: budget.fileBytesMax, maxTotalBytes: budget.totalBytesMax } });
|
|
859
|
+
const meta = metadataOf(normalized);
|
|
860
|
+
const input = { ownerId: acl.ownerId, storageScopeId: invocation.storageScopeId, artifactId,
|
|
861
|
+
identity: command.identity, actorId: invocation.actorId, invocationId: invocation.invocationId,
|
|
862
|
+
attemptId: invocation.invocationId, policyRevision: await deps.ensureHost.readPolicyRevision(),
|
|
863
|
+
authorizeCommit: invocation.authorizeCommit, metadata: meta, operation: 'publish',
|
|
864
|
+
expectedCurrentReleaseId: normalized.expectedCurrentReleaseId };
|
|
865
|
+
const replay = await publication.replayFinalized(input);
|
|
866
|
+
if (replay !== undefined)
|
|
867
|
+
return commitOutcome(replay, artifactId, meta, state => { commitState = state; });
|
|
868
|
+
profile.validate(capability, args, request.idempotencyKey);
|
|
869
|
+
// Resolve the files/assets union BEFORE any commit step: one missing,
|
|
870
|
+
// expired or digest-mismatched asset fails the whole publish and commits nothing.
|
|
871
|
+
const { files, origins, uploadPins } = await resolveBundleAssets(invocation, artifactId, {
|
|
872
|
+
files: (normalized.files ?? []),
|
|
873
|
+
assets: (normalized.assets ?? []),
|
|
874
|
+
}, { allowExtendedForms: false, keepUnmodifiedPaths: false, expectedCurrentReleaseId: null });
|
|
875
|
+
const outcome = await publication.publishFinalized({
|
|
876
|
+
...input, source: { kind: 'inline-original' },
|
|
877
|
+
profile: normalized.profile, files,
|
|
878
|
+
});
|
|
879
|
+
const committed = commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; });
|
|
880
|
+
if (committed.ok) {
|
|
881
|
+
const parsedBundleManifest = parseManifest(committed.result.body.manifest);
|
|
882
|
+
const entries = parsedBundleManifest.files ?? [];
|
|
883
|
+
committed.result.body.files = entries.map((entry) => ({
|
|
884
|
+
path: entry.path, mimeType: entry.mimeType, size: entry.size, digest: entry.digest,
|
|
885
|
+
origin: origins[entry.path] ?? 'inline',
|
|
886
|
+
}));
|
|
887
|
+
// LOT 2 §D.1/D.3: unpin consumed upload pins (sweeper is the
|
|
888
|
+
// backstop) and meter every bundled asset by coarse origin.
|
|
889
|
+
for (const pin of uploadPins) {
|
|
890
|
+
await deps.publication.refs.unpin(pin.digest, `upload:${pin.uploadId}`).catch(() => undefined);
|
|
891
|
+
}
|
|
892
|
+
if (deps.uploads?.metrics !== undefined) {
|
|
893
|
+
for (const file of files) {
|
|
894
|
+
const origin = origins[file.path] ?? 'inline';
|
|
895
|
+
deps.uploads.metrics.emit({ name: 'bundle_assets',
|
|
896
|
+
labels: { origin: origin.startsWith('upload:') ? 'upload' : origin } });
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
return committed;
|
|
901
|
+
}
|
|
902
|
+
if (capability === 'artifacts_publish_bundle_v2') {
|
|
903
|
+
const artifactId = normalized.artifactId;
|
|
904
|
+
const acl = await visible(artifactId, invocation);
|
|
905
|
+
if (acl.ownerId !== invocation.actorId)
|
|
906
|
+
throw new ArtifactOperationError('access_denied');
|
|
907
|
+
const publication = createGuardedPublicationService({ ...deps.publication, coordinator: deps.coordinator,
|
|
908
|
+
limits: { maxFiles: budget.filesMax, maxFileBytes: budget.fileBytesMax, maxTotalBytes: budget.totalBytesMax } });
|
|
909
|
+
const meta = metadataOf(normalized);
|
|
910
|
+
const input = { ownerId: acl.ownerId, storageScopeId: invocation.storageScopeId, artifactId,
|
|
911
|
+
identity: command.identity, actorId: invocation.actorId, invocationId: invocation.invocationId,
|
|
912
|
+
attemptId: invocation.invocationId, policyRevision: await deps.ensureHost.readPolicyRevision(),
|
|
913
|
+
authorizeCommit: invocation.authorizeCommit, metadata: meta, operation: 'publish',
|
|
914
|
+
expectedCurrentReleaseId: normalized.expectedCurrentReleaseId };
|
|
915
|
+
const replay = await publication.replayFinalized(input);
|
|
916
|
+
if (replay !== undefined)
|
|
917
|
+
return commitOutcome(replay, artifactId, meta, state => { commitState = state; });
|
|
918
|
+
profile.validate(capability, args, request.idempotencyKey);
|
|
919
|
+
const resolved = await resolveBundleAssets(invocation, artifactId, {
|
|
920
|
+
files: (normalized.files ?? []),
|
|
921
|
+
assets: (normalized.assets ?? []),
|
|
922
|
+
}, { allowExtendedForms: true,
|
|
923
|
+
keepUnmodifiedPaths: normalized.keepUnmodifiedPaths === true,
|
|
924
|
+
expectedCurrentReleaseId: normalized.expectedCurrentReleaseId });
|
|
925
|
+
const outcome = await publication.publishFinalized({
|
|
926
|
+
...input, source: { kind: 'inline-original' },
|
|
927
|
+
profile: normalized.profile, files: resolved.files,
|
|
928
|
+
});
|
|
929
|
+
const committed = commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; });
|
|
930
|
+
if (committed.ok) {
|
|
931
|
+
const parsedBundleManifest = parseManifest(committed.result.body.manifest);
|
|
932
|
+
const entries = parsedBundleManifest.files ?? [];
|
|
933
|
+
committed.result.body.files = entries.map((entry) => ({
|
|
934
|
+
path: entry.path, mimeType: entry.mimeType, size: entry.size, digest: entry.digest,
|
|
935
|
+
origin: resolved.origins[entry.path] ?? 'inline',
|
|
936
|
+
}));
|
|
937
|
+
// LOT 2 §D.1: consumed upload pins leave with the bundle; the
|
|
938
|
+
// release ref keeps the blob alive. Best-effort: the sweeper is
|
|
939
|
+
// the backstop and reports what it unpins.
|
|
940
|
+
for (const pin of resolved.uploadPins) {
|
|
941
|
+
await deps.publication.refs.unpin(pin.digest, `upload:${pin.uploadId}`).catch(() => undefined);
|
|
942
|
+
}
|
|
943
|
+
if (deps.uploads?.metrics !== undefined) {
|
|
944
|
+
for (const file of resolved.files) {
|
|
945
|
+
const origin = resolved.origins[file.path] ?? 'inline';
|
|
946
|
+
const coarse = origin.startsWith('copy:') ? 'copy' : origin.startsWith('carry:') ? 'carry'
|
|
947
|
+
: origin.startsWith('upload:') ? 'upload' : origin;
|
|
948
|
+
deps.uploads.metrics.emit({ name: 'bundle_assets', labels: { origin: coarse } });
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
return committed;
|
|
953
|
+
}
|
|
392
954
|
if (capability === 'artifacts_get') {
|
|
393
955
|
const artifactId = normalized.artifactId;
|
|
394
956
|
const acl = await visible(artifactId, invocation);
|
|
395
957
|
const state = await deps.lifecycle.stateOf(artifactId);
|
|
396
958
|
const current = await deps.publication.getCurrent(artifactId);
|
|
397
959
|
return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
|
|
398
|
-
result: { status: 200, body: { ...artifactSummary({ artifactId, acl, state, current,
|
|
960
|
+
result: { status: 200, body: { ...await projectSummary(artifactSummary({ artifactId, acl, state, current,
|
|
399
961
|
actorId: invocation.actorId, urls: deps.publicationUrls, approved: deps.isApprovedAccount,
|
|
400
|
-
policy: await sharingPolicyContext(invocation.storageScopeId) }),
|
|
962
|
+
policy: await sharingPolicyContext(invocation.storageScopeId) }), invocation.storageScopeId),
|
|
401
963
|
...(acl.metadata !== undefined ? { metadata: acl.metadata } : {}),
|
|
402
|
-
...(acl.ownerId === invocation.actorId
|
|
964
|
+
...(acl.ownerId === invocation.actorId
|
|
965
|
+
? { grants: await projectGrants(acl.grants, invocation.storageScopeId) } : {}) } } };
|
|
403
966
|
}
|
|
404
967
|
if (capability === 'artifacts_list_versions') {
|
|
405
968
|
const artifactId = normalized.artifactId;
|
|
@@ -426,6 +989,45 @@ export function createHttpArtifactApp(deps) {
|
|
|
426
989
|
return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
|
|
427
990
|
result: { status: 200, body: { artifactId, total: releases.length, releases } } };
|
|
428
991
|
}
|
|
992
|
+
if (capability === 'artifacts_lookup_people') {
|
|
993
|
+
// G2 approved-caller guard: the tool has no artifactId, so no visible()
|
|
994
|
+
// carries this check — a pending/disabled account gets access_denied
|
|
995
|
+
// before any directory enumeration.
|
|
996
|
+
if (deps.isApprovedAccount?.(invocation.actorId) !== true)
|
|
997
|
+
throw new ArtifactOperationError('access_denied');
|
|
998
|
+
if (!deps.directory)
|
|
999
|
+
throw new ArtifactProfileInputError(true);
|
|
1000
|
+
const matches = await deps.directory.searchPeople(invocation.storageScopeId, normalized.query, normalized.limit);
|
|
1001
|
+
return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
|
|
1002
|
+
result: { status: 200, body: { matches: matches.map((person) => ({ userRef: person.userRef,
|
|
1003
|
+
displayName: person.displayName, emailHint: maskEmailHint(person.email) })) } } };
|
|
1004
|
+
}
|
|
1005
|
+
if (capability === 'artifacts_list_access') {
|
|
1006
|
+
const artifactId = normalized.artifactId;
|
|
1007
|
+
const acl = await visibleForAccessList(artifactId, invocation);
|
|
1008
|
+
if (!deps.directory)
|
|
1009
|
+
throw new ArtifactProfileInputError(true);
|
|
1010
|
+
const admin = await deps.actorIsAdmin?.(invocation.actorId, invocation.storageScopeId) === true &&
|
|
1011
|
+
deps.isApprovedAccount?.(invocation.actorId) === true;
|
|
1012
|
+
const canManage = acl.ownerId === invocation.actorId || admin;
|
|
1013
|
+
// Owner and admin see the full list; a simple reader sees the mode and its own entry only.
|
|
1014
|
+
const visibleGrants = canManage ? acl.grants
|
|
1015
|
+
: acl.grants.filter((grant) => grant.principalId === invocation.actorId);
|
|
1016
|
+
const grants = await Promise.all(visibleGrants.map(async (grant) => {
|
|
1017
|
+
const person = await deps.directory.describePrincipal(invocation.storageScopeId, grant.principalId);
|
|
1018
|
+
const userRef = person?.userRef ?? grant.principalId;
|
|
1019
|
+
const { effective, blockedBy } = evaluateGrant(acl, grant.principalId, deps.isApprovedAccount ?? (() => false));
|
|
1020
|
+
return { userRef, displayName: person?.displayName ?? userRef,
|
|
1021
|
+
...(person === undefined ? {} : { emailHint: maskEmailHint(person.email) }),
|
|
1022
|
+
grant: grant.grant, createdAt: grant.createdAt ?? null, effective,
|
|
1023
|
+
...(blockedBy === undefined ? {} : { blockedBy }) };
|
|
1024
|
+
}));
|
|
1025
|
+
const owner = await deps.directory.describePrincipal(invocation.storageScopeId, acl.ownerId);
|
|
1026
|
+
return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
|
|
1027
|
+
result: { status: 200, body: { artifactId, accessMode: accessModeOf(acl),
|
|
1028
|
+
owner: { userRef: owner?.userRef ?? acl.ownerId, displayName: owner?.displayName ?? acl.ownerId },
|
|
1029
|
+
canManage, grants } } };
|
|
1030
|
+
}
|
|
429
1031
|
const visibleArtifacts = [];
|
|
430
1032
|
const listPolicy = await sharingPolicyContext(invocation.storageScopeId);
|
|
431
1033
|
for (const artifactId of await deps.acls.listArtifactIds()) {
|
|
@@ -434,9 +1036,9 @@ export function createHttpArtifactApp(deps) {
|
|
|
434
1036
|
continue;
|
|
435
1037
|
const state = await deps.lifecycle.stateOf(artifactId);
|
|
436
1038
|
if (deps.lifecycle.canRead({ artifactId, state }, acl, invocation.actorId, 'read', deps.isApprovedAccount, listPolicy)) {
|
|
437
|
-
visibleArtifacts.push(artifactSummary({ artifactId, acl, state, actorId: invocation.actorId,
|
|
1039
|
+
visibleArtifacts.push(await projectSummary(artifactSummary({ artifactId, acl, state, actorId: invocation.actorId,
|
|
438
1040
|
current: await deps.publication.getCurrent(artifactId), urls: deps.publicationUrls,
|
|
439
|
-
approved: deps.isApprovedAccount, policy: listPolicy }));
|
|
1041
|
+
approved: deps.isApprovedAccount, policy: listPolicy }), invocation.storageScopeId));
|
|
440
1042
|
}
|
|
441
1043
|
}
|
|
442
1044
|
const offset = normalized.offset;
|