@sentropic/artifacts 0.2.13 → 0.2.15
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 +37 -0
- package/dist/adapters/local-blob.d.ts +3 -0
- package/dist/adapters/local-blob.js +93 -0
- package/dist/adapters/postgres-uploads.d.ts +14 -0
- package/dist/adapters/postgres-uploads.js +174 -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/http.d.ts +16 -0
- package/dist/http.js +435 -97
- package/dist/mcp-core.d.ts +3 -3
- package/dist/mcp-core.js +43 -4
- package/dist/profile/contracts.d.ts +1 -1
- package/dist/profile/contracts.js +4 -0
- package/dist/profile/index.js +12 -2
- package/dist/profile/schemas.js +60 -0
- package/dist/profile/validation.js +31 -4
- package/dist/server/command-identity.d.ts +1 -1
- package/dist/server/command-identity.js +4 -3
- package/dist/server/gc.d.ts +28 -3
- package/dist/server/gc.js +81 -5
- package/dist/server/management.js +10 -5
- package/dist/server/metrics.d.ts +21 -0
- package/dist/server/metrics.js +6 -0
- package/dist/server/ports.d.ts +7 -0
- package/dist/server/ports.js +7 -0
- package/dist/server/publication-limits.d.ts +8 -0
- package/dist/server/publication-limits.js +8 -0
- package/dist/server/publication.d.ts +5 -0
- package/dist/server/publication.js +6 -0
- package/dist/server/source-read.d.ts +12 -9
- package/dist/server/source-read.js +17 -5
- package/dist/server/upload-page.d.ts +157 -0
- package/dist/server/upload-page.js +438 -0
- package/dist/server/uploads.d.ts +75 -1
- package/dist/server/uploads.js +187 -27
- package/migrations/0009_upload_pages.sql +25 -0
- package/package.json +13 -1
- package/sql/sqlite/0001_artifacts.sql +156 -0
- package/sql/sqlite/0002_activation.sql +73 -0
package/dist/http.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/** Selected HTTP control surface over the authorized atomic services. */
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
|
-
import { parseManifest } from './codecs.js';
|
|
3
|
+
import { canonicalManifest, manifestDigest, parseManifest } from './codecs.js';
|
|
4
4
|
import { assertCompiledArtifactsProfile, ArtifactProfileInputError } from './profile/index.js';
|
|
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, maskEmailHint, resolveSharingPolicy } from './server/ports.js';
|
|
9
|
-
import { createGuardedPublicationService
|
|
10
|
-
import { SERVER_MAX_FILE_BYTES, SERVER_MAX_UPLOAD_SESSIONS_PER_PRINCIPAL } from './server/publication-limits.js';
|
|
8
|
+
import { combineSharingPolicy, maskEmailHint, resolveSharingPolicy, UNKNOWN_USER_REF } from './server/ports.js';
|
|
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
11
|
import { releaseBudget } from './profile/validation.js';
|
|
12
|
-
import { createUploadService,
|
|
12
|
+
import { commitStagedUpload, createUploadService, STAGED_FILE_TTL_MS, stagedFileExpired } from './server/uploads.js';
|
|
13
|
+
import { createHmacUploadPageCookieSigner, createMemoryUploadPageStore, createUploadPageService } from './server/upload-page.js';
|
|
13
14
|
import { accessModeOf, evaluateGrant } from './server/access.js';
|
|
14
15
|
import { assertConsentScopeId } from './server/consent.js';
|
|
15
16
|
import { applyEdits } from './server/edits.js';
|
|
@@ -27,7 +28,7 @@ export { projectArtifactHttpOutcome } from './server/outcome-projection.js';
|
|
|
27
28
|
/** Stable content-route error codes; private driver messages never leave the host. */
|
|
28
29
|
export function errorBody(status) {
|
|
29
30
|
return { error: { 400: 'invalid_request', 401: 'anonymous', 403: 'access_denied',
|
|
30
|
-
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',
|
|
31
32
|
500: 'internal_error', 503: 'capability_unavailable' }[status] ?? 'internal_error' };
|
|
32
33
|
}
|
|
33
34
|
/** Retained for consumers describing canonical textual publication inputs. */
|
|
@@ -44,6 +45,7 @@ export function assertArtifactsTransportProfile(value) {
|
|
|
44
45
|
'artifacts_list_versions', 'artifacts_get_source', 'artifacts_revert', 'artifacts_set_access', 'artifacts_delete',
|
|
45
46
|
'artifacts_lookup_people', 'artifacts_list_access',
|
|
46
47
|
'artifacts_create_upload', 'artifacts_commit_upload', 'artifacts_publish_bundle',
|
|
48
|
+
'artifacts_create_upload_page', 'artifacts_list_assets', 'artifacts_publish_bundle_v2',
|
|
47
49
|
'artifacts_revoke_reader_consent'];
|
|
48
50
|
if (value.selectedCapabilities.some((name) => !supported.includes(name))) {
|
|
49
51
|
throw new Error('unsupported artifacts transport capability');
|
|
@@ -67,13 +69,42 @@ export function createHttpArtifactApp(deps) {
|
|
|
67
69
|
throw new Error('artifact delete confirmation port required');
|
|
68
70
|
}
|
|
69
71
|
// Files parity LOT 1: upload ports are required as soon as one upload capability is selected.
|
|
70
|
-
|
|
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'];
|
|
71
75
|
const needsUploads = uploadCapabilities.some((name) => profile.selectedCapabilities.includes(name));
|
|
72
76
|
if (needsUploads && !deps.uploads)
|
|
73
77
|
throw new Error('artifact upload ports required');
|
|
74
78
|
const budget = releaseBudget(profile);
|
|
75
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),
|
|
76
|
-
maxSessionsPerPrincipal: SERVER_MAX_UPLOAD_SESSIONS_PER_PRINCIPAL
|
|
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;
|
|
77
108
|
const ensure = createGuardedEnsureService({ profile, coordinator: deps.coordinator,
|
|
78
109
|
derivation: deps.derivation, host: {
|
|
79
110
|
lockBinding: (client, binding) => deps.ensureHost.lockBinding(client, binding),
|
|
@@ -108,6 +139,144 @@ export function createHttpArtifactApp(deps) {
|
|
|
108
139
|
}
|
|
109
140
|
return acl;
|
|
110
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
|
+
}
|
|
111
280
|
/**
|
|
112
281
|
* G1 management visibility for `set_access` (converged-r2 §2.3 order (2)):
|
|
113
282
|
* readers pass as before; any other actor gets `not_found` unless it is an
|
|
@@ -156,7 +325,7 @@ export function createHttpArtifactApp(deps) {
|
|
|
156
325
|
async function projectUserRef(internalId, storageScopeId) {
|
|
157
326
|
if (!deps.directory)
|
|
158
327
|
return internalId;
|
|
159
|
-
return (await deps.directory.describePrincipal(storageScopeId, internalId))?.userRef ??
|
|
328
|
+
return (await deps.directory.describePrincipal(storageScopeId, internalId))?.userRef ?? UNKNOWN_USER_REF;
|
|
160
329
|
}
|
|
161
330
|
async function projectSummary(summary, storageScopeId) {
|
|
162
331
|
if (!deps.directory)
|
|
@@ -262,15 +431,47 @@ export function createHttpArtifactApp(deps) {
|
|
|
262
431
|
? { base64: Buffer.from(file.bytes).toString('base64'), encoding: 'base64' }
|
|
263
432
|
: { text: file.text, encoding: 'utf8' }) }));
|
|
264
433
|
await visible(artifactId, invocation, 'source');
|
|
434
|
+
const projectedManifest = await projectManifestForOutput(release.manifest, invocation.storageScopeId);
|
|
265
435
|
const failure = { ...outcome.failure, conflict: { ...conflict, currentSource: {
|
|
266
|
-
artifactId, releaseId: release.releaseId, digest:
|
|
436
|
+
artifactId, releaseId: release.releaseId, digest: parseManifest(projectedManifest).digest ?? conflict.currentDigest,
|
|
437
|
+
manifest: projectedManifest,
|
|
267
438
|
files, sourceRef: null, guideRef: API_GUIDE_REF, ...deps.publicationUrls?.(artifactId, release.releaseId),
|
|
268
439
|
} } };
|
|
269
440
|
Object.defineProperty(failure, 'cause', { value: outcome.failure.cause, enumerable: false });
|
|
270
441
|
return { ok: false, failure: Object.freeze(failure) };
|
|
271
442
|
}
|
|
443
|
+
/**
|
|
444
|
+
* R1 output-boundary projection for the release manifest embedded in
|
|
445
|
+
* publish/revert/bundle receipts. Storage keeps the raw internal `ownerId`
|
|
446
|
+
* (the manifest bytes are content-addressed); only this model-visible copy
|
|
447
|
+
* carries the opaque `userRef` (or `UNKNOWN_USER_REF` when the directory
|
|
448
|
+
* has no entry). Without a directory port the stored bytes pass through
|
|
449
|
+
* unchanged (G1 legacy behaviour).
|
|
450
|
+
*/
|
|
451
|
+
async function projectManifestForOutput(rawManifest, storageScopeId) {
|
|
452
|
+
if (!deps.directory)
|
|
453
|
+
return rawManifest;
|
|
454
|
+
let parsed;
|
|
455
|
+
try {
|
|
456
|
+
parsed = JSON.parse(rawManifest);
|
|
457
|
+
}
|
|
458
|
+
catch {
|
|
459
|
+
return rawManifest;
|
|
460
|
+
}
|
|
461
|
+
const rawOwner = parsed.ownerId;
|
|
462
|
+
if (typeof rawOwner !== 'string')
|
|
463
|
+
return rawManifest;
|
|
464
|
+
const projected = (await deps.directory.describePrincipal(storageScopeId, rawOwner))?.userRef
|
|
465
|
+
?? UNKNOWN_USER_REF;
|
|
466
|
+
if (projected === rawOwner)
|
|
467
|
+
return rawManifest;
|
|
468
|
+
const { digest: _drop, ...body } = parsed;
|
|
469
|
+
void _drop;
|
|
470
|
+
const nextDigest = manifestDigest({ ...body, ownerId: projected });
|
|
471
|
+
return canonicalManifest({ ...body, ownerId: projected, digest: nextDigest });
|
|
472
|
+
}
|
|
272
473
|
/** Shared guarded-commit response for publish and revert (same commit path, same receipt shape). */
|
|
273
|
-
function commitOutcome(outcome, artifactId, meta, setCommitState) {
|
|
474
|
+
async function commitOutcome(outcome, artifactId, meta, setCommitState, storageScopeId) {
|
|
274
475
|
if (!outcome.ok) {
|
|
275
476
|
const failure = { ...outcome.failure, kind: 'operational' };
|
|
276
477
|
Object.defineProperty(failure, 'cause', { value: outcome.failure.cause, enumerable: false });
|
|
@@ -281,11 +482,12 @@ export function createHttpArtifactApp(deps) {
|
|
|
281
482
|
if (typeof receipt.releaseId !== 'string' || typeof receipt.manifest !== 'string') {
|
|
282
483
|
throw new Error('invalid publication receipt');
|
|
283
484
|
}
|
|
485
|
+
const manifest = await projectManifestForOutput(receipt.manifest, storageScopeId);
|
|
284
486
|
return { ...outcome, result: { status: 201, body: {
|
|
285
|
-
artifactId, releaseId: receipt.releaseId, manifest
|
|
487
|
+
artifactId, releaseId: receipt.releaseId, manifest,
|
|
286
488
|
previousReleaseId: receipt.previousReleaseId ?? null, updatedAt: receipt.updatedAt ?? null,
|
|
287
489
|
...(typeof receipt.revertedFromReleaseId === 'string' ? { revertedFromReleaseId: receipt.revertedFromReleaseId } : {}),
|
|
288
|
-
digest: parseManifest(
|
|
490
|
+
digest: parseManifest(manifest).digest,
|
|
289
491
|
...deps.publicationUrls?.(artifactId, receipt.releaseId), ...(receipt.metadata ?? meta ?? {}),
|
|
290
492
|
} } };
|
|
291
493
|
}
|
|
@@ -334,7 +536,7 @@ export function createHttpArtifactApp(deps) {
|
|
|
334
536
|
}
|
|
335
537
|
const normalized = profile.validate(capability, args, request.idempotencyKey, { deferPrecondition: true });
|
|
336
538
|
const command = ['artifacts_ensure', 'artifacts_publish', 'artifacts_set_access', 'artifacts_delete', 'artifacts_revert',
|
|
337
|
-
'artifacts_commit_upload', 'artifacts_publish_bundle'].includes(capability)
|
|
539
|
+
'artifacts_commit_upload', 'artifacts_publish_bundle', 'artifacts_publish_bundle_v2'].includes(capability)
|
|
338
540
|
? createArtifactCommand(profile, capability, args, invocation, deps.derivation, request.idempotencyKey, { deferPrecondition: true }) : undefined;
|
|
339
541
|
if (command && ['ensure', 'publish'].includes(command.operation)) {
|
|
340
542
|
phase = 'migration';
|
|
@@ -363,6 +565,9 @@ export function createHttpArtifactApp(deps) {
|
|
|
363
565
|
}
|
|
364
566
|
if (capability === 'artifacts_get_source') {
|
|
365
567
|
const artifactId = normalized.artifactId;
|
|
568
|
+
// LOT 2 §B.3: profile caps instead of hard-coded ceilings (fail-closed
|
|
569
|
+
// at compile time; defaults stay 32 files / 262 144 B total).
|
|
570
|
+
const sourceOp = profile.operations.find((entry) => entry.operation === 'get_source');
|
|
366
571
|
const result = await readArtifactSource({
|
|
367
572
|
storageScopeId: invocation.storageScopeId,
|
|
368
573
|
authorize: async () => {
|
|
@@ -373,11 +578,86 @@ export function createHttpArtifactApp(deps) {
|
|
|
373
578
|
}
|
|
374
579
|
}, getCurrent: deps.publication.getCurrent, getRelease: deps.publication.getRelease,
|
|
375
580
|
getSource: (id) => deps.sources.getSource(id), getBlob: (key) => deps.publication.blobs.getBlob(key),
|
|
376
|
-
urls: deps.publicationUrls,
|
|
581
|
+
urls: deps.publicationUrls,
|
|
582
|
+
maxFiles: sourceOp?.limits['sourceFilesMax'] ?? SERVER_MAX_SOURCE_FILES,
|
|
583
|
+
maxInlineBytes: sourceOp?.limits['sourceInlineFileBytesMax'] ?? SERVER_MAX_SOURCE_INLINE_BYTES,
|
|
584
|
+
maxTotalBytes: sourceOp?.limits['sourceTotalBytesMax'] ?? SERVER_MAX_SOURCE_TOTAL_BYTES,
|
|
377
585
|
}, normalized);
|
|
378
|
-
|
|
586
|
+
const projectedSourceManifest = await projectManifestForOutput(result.manifest, invocation.storageScopeId);
|
|
587
|
+
const projectedSource = projectedSourceManifest === result.manifest ? result
|
|
588
|
+
: { ...result, manifest: projectedSourceManifest,
|
|
589
|
+
digest: parseManifest(projectedSourceManifest).digest ?? result.digest };
|
|
590
|
+
return { ok: true, result: { status: 200, body: projectedSource }, invocationId: invocation.invocationId,
|
|
379
591
|
commitState: 'not_committed', replayed: false };
|
|
380
592
|
}
|
|
593
|
+
if (capability === 'artifacts_list_assets') {
|
|
594
|
+
const artifactId = normalized.artifactId;
|
|
595
|
+
const acl = await visible(artifactId, invocation);
|
|
596
|
+
const listState = normalized.state ?? 'all';
|
|
597
|
+
const wantStaged = listState === 'staged' || listState === 'all';
|
|
598
|
+
const wantReleased = listState === 'released' || listState === 'all';
|
|
599
|
+
// Staged rows are owner-only (access_denied, never a filtered empty list);
|
|
600
|
+
// the source read right gates the released branch below.
|
|
601
|
+
if (wantStaged && acl.ownerId !== invocation.actorId) {
|
|
602
|
+
throw new ArtifactOperationError('access_denied');
|
|
603
|
+
}
|
|
604
|
+
const limit = normalized.limit;
|
|
605
|
+
const cursor = normalized.cursor;
|
|
606
|
+
const releaseId = normalized.releaseId;
|
|
607
|
+
const pageSessionId = normalized.pageSessionId;
|
|
608
|
+
const stagedEntries = [];
|
|
609
|
+
if (wantStaged) {
|
|
610
|
+
if (deps.uploads === undefined)
|
|
611
|
+
throw new ArtifactProfileInputError(true);
|
|
612
|
+
const rows = await deps.uploads.sessions.listStagedFiles(artifactId);
|
|
613
|
+
for (const record of rows
|
|
614
|
+
.filter((entry) => pageSessionId === undefined || entry.pageSessionId === pageSessionId)
|
|
615
|
+
.sort((left, right) => (left.path < right.path ? -1 : left.path > right.path ? 1 : 0))) {
|
|
616
|
+
stagedEntries.push({ path: record.path, mimeType: record.mimeType, size: record.size,
|
|
617
|
+
digest: record.digest, state: 'staged', uploadId: record.uploadId,
|
|
618
|
+
...(record.pageSessionId === undefined ? {} : { pageSessionId: record.pageSessionId }) });
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
const releasedEntries = [];
|
|
622
|
+
let listedReleaseId;
|
|
623
|
+
if (wantReleased) {
|
|
624
|
+
const artifactState = await deps.lifecycle.stateOf(artifactId);
|
|
625
|
+
if (!deps.lifecycle.canRead({ artifactId, state: artifactState }, acl, invocation.actorId, 'source', deps.isApprovedAccount, await sharingPolicyContext(invocation.storageScopeId))) {
|
|
626
|
+
throw new ArtifactOperationError('access_denied');
|
|
627
|
+
}
|
|
628
|
+
const current = releaseId === undefined ? await deps.publication.getCurrent(artifactId)
|
|
629
|
+
: deps.publication.getRelease === undefined ? undefined
|
|
630
|
+
: await deps.publication.getRelease(releaseId);
|
|
631
|
+
// A release of another artifact reads as empty (no cross-artifact oracle).
|
|
632
|
+
if (current !== undefined && (releaseId === undefined || current.artifactId === artifactId)) {
|
|
633
|
+
listedReleaseId = current.releaseId;
|
|
634
|
+
const manifest = parseManifest(current.manifest);
|
|
635
|
+
for (const file of manifest.files ?? []) {
|
|
636
|
+
releasedEntries.push({ path: file.path, mimeType: file.mimeType, size: file.size,
|
|
637
|
+
digest: file.digest, state: 'released', releaseId: current.releaseId });
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
const stagedPaths = new Set(stagedEntries.map((entry) => entry.path));
|
|
642
|
+
const entries = [...stagedEntries,
|
|
643
|
+
...releasedEntries.filter((entry) => !stagedPaths.has(entry.path))];
|
|
644
|
+
let offset = 0;
|
|
645
|
+
if (cursor !== undefined) {
|
|
646
|
+
const decoded = Buffer.from(cursor, 'base64url').toString('utf8');
|
|
647
|
+
const match = /^lot2-assets:(\d+)$/.exec(decoded);
|
|
648
|
+
if (match?.[1] === undefined || !Number.isSafeInteger(Number(match[1]))) {
|
|
649
|
+
throw new ArtifactProfileInputError();
|
|
650
|
+
}
|
|
651
|
+
offset = Math.min(Number(match[1]), entries.length);
|
|
652
|
+
}
|
|
653
|
+
const page = entries.slice(offset, offset + limit);
|
|
654
|
+
const nextCursor = offset + limit < entries.length
|
|
655
|
+
? Buffer.from(`lot2-assets:${offset + limit}`, 'utf8').toString('base64url') : undefined;
|
|
656
|
+
return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
|
|
657
|
+
result: { status: 200, body: { artifactId,
|
|
658
|
+
...(listedReleaseId === undefined ? {} : { releaseId: listedReleaseId }), assets: page,
|
|
659
|
+
total: entries.length, ...(nextCursor === undefined ? {} : { nextCursor }) } } };
|
|
660
|
+
}
|
|
381
661
|
if (capability === 'artifacts_set_access' || capability === 'artifacts_delete') {
|
|
382
662
|
const artifactId = normalized.artifactId;
|
|
383
663
|
const acl = capability === 'artifacts_set_access'
|
|
@@ -442,7 +722,7 @@ export function createHttpArtifactApp(deps) {
|
|
|
442
722
|
expectedCurrentReleaseId: normalized.expectedCurrentReleaseId };
|
|
443
723
|
const replay = await publication.replayFinalized(input);
|
|
444
724
|
if (replay !== undefined)
|
|
445
|
-
return commitOutcome(replay, artifactId, meta, state => { commitState = state; });
|
|
725
|
+
return commitOutcome(replay, artifactId, meta, state => { commitState = state; }, invocation.storageScopeId);
|
|
446
726
|
profile.validate(capability, args, request.idempotencyKey);
|
|
447
727
|
let files;
|
|
448
728
|
let source;
|
|
@@ -484,7 +764,7 @@ export function createHttpArtifactApp(deps) {
|
|
|
484
764
|
const outcome = await publication.publishFinalized({
|
|
485
765
|
...input, source, profile: releaseProfile, files,
|
|
486
766
|
});
|
|
487
|
-
const committed = commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; });
|
|
767
|
+
const committed = await commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; }, invocation.storageScopeId);
|
|
488
768
|
return await conflictSource(committed, normalized, invocation);
|
|
489
769
|
}
|
|
490
770
|
if (capability === 'artifacts_create_upload') {
|
|
@@ -501,10 +781,14 @@ export function createHttpArtifactApp(deps) {
|
|
|
501
781
|
});
|
|
502
782
|
}
|
|
503
783
|
catch (cause) {
|
|
504
|
-
if (cause instanceof Error && /quota
|
|
784
|
+
if (cause instanceof Error && /open upload session quota/.test(cause.message)) {
|
|
505
785
|
throw new ArtifactOperationError('limit_exceeded', { cause,
|
|
506
786
|
publicDetails: { upload: { reason: 'open_session_quota' } } });
|
|
507
787
|
}
|
|
788
|
+
if (cause instanceof Error && /scope staging quota/.test(cause.message)) {
|
|
789
|
+
throw new ArtifactOperationError('limit_exceeded', { cause,
|
|
790
|
+
publicDetails: { upload: { reason: 'scope_staging_quota' } } });
|
|
791
|
+
}
|
|
508
792
|
if (cause instanceof Error && /invalid/.test(cause.message))
|
|
509
793
|
throw new ArtifactProfileInputError();
|
|
510
794
|
throw cause;
|
|
@@ -526,46 +810,34 @@ export function createHttpArtifactApp(deps) {
|
|
|
526
810
|
const path = normalized.path;
|
|
527
811
|
const commitInput = { uploadId, artifactId, storageScopeId: invocation.storageScopeId,
|
|
528
812
|
ownerId: acl.ownerId, path, mimeType, digest, size };
|
|
813
|
+
// LOT 2: the shared commit core — same code as the browser page channel.
|
|
814
|
+
const commitDeps = { sessions: deps.uploads.sessions,
|
|
815
|
+
staging: deps.uploads.staging, blobs: deps.publication.blobs, refs: deps.publication.refs,
|
|
816
|
+
budget: { filesMax: budget.filesMax, totalBytesMax: budget.totalBytesMax },
|
|
817
|
+
...(deps.uploads.metrics === undefined ? {} : { metrics: deps.uploads.metrics }) };
|
|
529
818
|
const work = async () => {
|
|
530
|
-
let
|
|
531
|
-
try {
|
|
532
|
-
session = await uploadService.sessionForCommit(commitInput);
|
|
533
|
-
}
|
|
534
|
-
catch (cause) {
|
|
535
|
-
// One response for unknown, foreign-bound, closed or expired sessions (no oracle).
|
|
536
|
-
throw new ArtifactOperationError('verification_failed', { cause,
|
|
537
|
-
publicDetails: { upload: { reason: 'session unknown, bound elsewhere, closed or expired' } } });
|
|
538
|
-
}
|
|
539
|
-
const key = stagingKey(invocation.storageScopeId, uploadId);
|
|
540
|
-
const bytes = await deps.uploads.staging.get(key);
|
|
541
|
-
if (bytes === undefined) {
|
|
542
|
-
throw new ArtifactOperationError('verification_failed', { publicDetails: { upload: { reason: 'staged object missing' } } });
|
|
543
|
-
}
|
|
544
|
-
// Re-verify declared size + digest + MIME against the staged bytes (review finding 3).
|
|
819
|
+
let staged;
|
|
545
820
|
try {
|
|
546
|
-
|
|
821
|
+
staged = await commitStagedUpload(uploadService, commitDeps, commitInput);
|
|
547
822
|
}
|
|
548
823
|
catch (cause) {
|
|
824
|
+
if (cause instanceof Error && /budget exceeded/.test(cause.message)) {
|
|
825
|
+
throw new ArtifactOperationError('limit_exceeded', { cause,
|
|
826
|
+
publicDetails: { upload: { reason: 'staged_budget' } } });
|
|
827
|
+
}
|
|
828
|
+
if (cause instanceof Error && (/unknown upload/.test(cause.message) || /closed/.test(cause.message))) {
|
|
829
|
+
// One response for unknown, foreign-bound, closed or expired sessions (no oracle).
|
|
830
|
+
throw new ArtifactOperationError('verification_failed', { cause,
|
|
831
|
+
publicDetails: { upload: { reason: 'session unknown, bound elsewhere, closed or expired' } } });
|
|
832
|
+
}
|
|
833
|
+
if (cause instanceof Error && /staged object missing/.test(cause.message)) {
|
|
834
|
+
throw new ArtifactOperationError('verification_failed', { publicDetails: { upload: { reason: 'staged object missing' } } });
|
|
835
|
+
}
|
|
549
836
|
throw new ArtifactOperationError('verification_failed', { cause,
|
|
550
837
|
publicDetails: { upload: { reason: 'size/digest/MIME mismatch' } } });
|
|
551
838
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
const concurrency = resolveBlobConcurrency(deps.publication.blobConcurrency);
|
|
555
|
-
await runBlobPool([{ key: casKey, bytes }], { concurrency }, async (item) => { await deps.publication.blobs.putBlob(item.key, item.bytes); });
|
|
556
|
-
await verifyStagedBlobs(deps.publication.blobs, [{ key: casKey, bytes }], { concurrency });
|
|
557
|
-
const pinReason = `upload:${uploadId}`;
|
|
558
|
-
await deps.publication.refs.pin(digest, pinReason);
|
|
559
|
-
let staged;
|
|
560
|
-
try {
|
|
561
|
-
staged = await uploadService.completeCommit(session, { path, mimeType, digest, size });
|
|
562
|
-
}
|
|
563
|
-
catch (cause) {
|
|
564
|
-
await deps.publication.refs.unpin(digest, pinReason).catch(() => undefined);
|
|
565
|
-
throw cause;
|
|
566
|
-
}
|
|
567
|
-
await deps.uploads.staging.delete(key);
|
|
568
|
-
return { artifactId, uploadId, path, mimeType, digest, size, state: 'staged', stagedAt: staged.createdAt };
|
|
839
|
+
return { artifactId, uploadId, path, mimeType, digest, size,
|
|
840
|
+
state: 'staged', stagedAt: staged.createdAt };
|
|
569
841
|
};
|
|
570
842
|
let body;
|
|
571
843
|
if (deps.uploads.idempotency !== undefined && command !== undefined) {
|
|
@@ -588,6 +860,32 @@ export function createHttpArtifactApp(deps) {
|
|
|
588
860
|
return { ok: true, invocationId: invocation.invocationId, commitState: 'committed', replayed: false,
|
|
589
861
|
result: { status: 201, body } };
|
|
590
862
|
}
|
|
863
|
+
if (capability === 'artifacts_create_upload_page') {
|
|
864
|
+
const artifactId = normalized.artifactId;
|
|
865
|
+
const acl = await visible(artifactId, invocation);
|
|
866
|
+
if (acl.ownerId !== invocation.actorId)
|
|
867
|
+
throw new ArtifactOperationError('access_denied');
|
|
868
|
+
let minted;
|
|
869
|
+
try {
|
|
870
|
+
minted = await pageService.mint({ artifactId, storageScopeId: invocation.storageScopeId,
|
|
871
|
+
ownerId: acl.ownerId,
|
|
872
|
+
...(normalized.maxFiles === undefined ? {} : { maxFiles: normalized.maxFiles }) });
|
|
873
|
+
}
|
|
874
|
+
catch (cause) {
|
|
875
|
+
if (cause instanceof Error && /quota exceeded/.test(cause.message)) {
|
|
876
|
+
throw new ArtifactOperationError('limit_exceeded', { cause,
|
|
877
|
+
publicDetails: { upload: { reason: 'open_page_quota' } } });
|
|
878
|
+
}
|
|
879
|
+
if (cause instanceof Error && /invalid/.test(cause.message))
|
|
880
|
+
throw new ArtifactProfileInputError();
|
|
881
|
+
throw cause;
|
|
882
|
+
}
|
|
883
|
+
return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
|
|
884
|
+
result: { status: 201, body: { pageSessionId: minted.pageSessionId,
|
|
885
|
+
uploadPageUrl: minted.uploadPageUrl, expiresAt: minted.expiresAt, maxFiles: minted.maxFiles,
|
|
886
|
+
maxFileBytes: minted.maxFileBytes, maxTotalBytes: minted.maxTotalBytes,
|
|
887
|
+
allowedMimeTypes: minted.allowedMimeTypes } } };
|
|
888
|
+
}
|
|
591
889
|
if (capability === 'artifacts_publish_bundle') {
|
|
592
890
|
const artifactId = normalized.artifactId;
|
|
593
891
|
const acl = await visible(artifactId, invocation);
|
|
@@ -603,62 +901,90 @@ export function createHttpArtifactApp(deps) {
|
|
|
603
901
|
expectedCurrentReleaseId: normalized.expectedCurrentReleaseId };
|
|
604
902
|
const replay = await publication.replayFinalized(input);
|
|
605
903
|
if (replay !== undefined)
|
|
606
|
-
return commitOutcome(replay, artifactId, meta, state => { commitState = state; });
|
|
904
|
+
return commitOutcome(replay, artifactId, meta, state => { commitState = state; }, invocation.storageScopeId);
|
|
607
905
|
profile.validate(capability, args, request.idempotencyKey);
|
|
608
|
-
// Resolve the files/assets union BEFORE any commit step: one missing
|
|
609
|
-
// digest-mismatched asset fails the whole publish and commits nothing.
|
|
610
|
-
const files =
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
}
|
|
630
|
-
validateFileBytes(staged.mimeType, bytes);
|
|
631
|
-
files.push({ path, mimeType: staged.mimeType, bytes });
|
|
632
|
-
origins[path] = `upload:${staged.uploadId}`;
|
|
906
|
+
// Resolve the files/assets union BEFORE any commit step: one missing,
|
|
907
|
+
// expired or digest-mismatched asset fails the whole publish and commits nothing.
|
|
908
|
+
const { files, origins, uploadPins } = await resolveBundleAssets(invocation, artifactId, {
|
|
909
|
+
files: (normalized.files ?? []),
|
|
910
|
+
assets: (normalized.assets ?? []),
|
|
911
|
+
}, { allowExtendedForms: false, keepUnmodifiedPaths: false, expectedCurrentReleaseId: null });
|
|
912
|
+
const outcome = await publication.publishFinalized({
|
|
913
|
+
...input, source: { kind: 'inline-original' },
|
|
914
|
+
profile: normalized.profile, files,
|
|
915
|
+
});
|
|
916
|
+
const committed = await commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; }, invocation.storageScopeId);
|
|
917
|
+
if (committed.ok) {
|
|
918
|
+
const parsedBundleManifest = parseManifest(committed.result.body.manifest);
|
|
919
|
+
const entries = parsedBundleManifest.files ?? [];
|
|
920
|
+
committed.result.body.files = entries.map((entry) => ({
|
|
921
|
+
path: entry.path, mimeType: entry.mimeType, size: entry.size, digest: entry.digest,
|
|
922
|
+
origin: origins[entry.path] ?? 'inline',
|
|
923
|
+
}));
|
|
924
|
+
// LOT 2 §D.1/D.3: unpin consumed upload pins (sweeper is the
|
|
925
|
+
// backstop) and meter every bundled asset by coarse origin.
|
|
926
|
+
for (const pin of uploadPins) {
|
|
927
|
+
await deps.publication.refs.unpin(pin.digest, `upload:${pin.uploadId}`).catch(() => undefined);
|
|
633
928
|
}
|
|
634
|
-
|
|
635
|
-
const
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
if (bytes === undefined) {
|
|
640
|
-
throw new ArtifactOperationError('verification_failed', { publicDetails: { asset: { path, reason: 'blob missing' } } });
|
|
641
|
-
}
|
|
642
|
-
if (bytes.length !== size || `sha256:${createHash('sha256').update(bytes).digest('hex')}` !== digest) {
|
|
643
|
-
throw new ArtifactOperationError('verification_failed', { publicDetails: { asset: { path, reason: 'size/digest mismatch' } } });
|
|
929
|
+
if (deps.uploads?.metrics !== undefined) {
|
|
930
|
+
for (const file of files) {
|
|
931
|
+
const origin = origins[file.path] ?? 'inline';
|
|
932
|
+
deps.uploads.metrics.emit({ name: 'bundle_assets',
|
|
933
|
+
labels: { origin: origin.startsWith('upload:') ? 'upload' : origin } });
|
|
644
934
|
}
|
|
645
|
-
validateFileBytes(mimeType, bytes);
|
|
646
|
-
files.push({ path, mimeType, bytes });
|
|
647
|
-
origins[path] = 'cas';
|
|
648
935
|
}
|
|
649
936
|
}
|
|
937
|
+
return committed;
|
|
938
|
+
}
|
|
939
|
+
if (capability === 'artifacts_publish_bundle_v2') {
|
|
940
|
+
const artifactId = normalized.artifactId;
|
|
941
|
+
const acl = await visible(artifactId, invocation);
|
|
942
|
+
if (acl.ownerId !== invocation.actorId)
|
|
943
|
+
throw new ArtifactOperationError('access_denied');
|
|
944
|
+
const publication = createGuardedPublicationService({ ...deps.publication, coordinator: deps.coordinator,
|
|
945
|
+
limits: { maxFiles: budget.filesMax, maxFileBytes: budget.fileBytesMax, maxTotalBytes: budget.totalBytesMax } });
|
|
946
|
+
const meta = metadataOf(normalized);
|
|
947
|
+
const input = { ownerId: acl.ownerId, storageScopeId: invocation.storageScopeId, artifactId,
|
|
948
|
+
identity: command.identity, actorId: invocation.actorId, invocationId: invocation.invocationId,
|
|
949
|
+
attemptId: invocation.invocationId, policyRevision: await deps.ensureHost.readPolicyRevision(),
|
|
950
|
+
authorizeCommit: invocation.authorizeCommit, metadata: meta, operation: 'publish',
|
|
951
|
+
expectedCurrentReleaseId: normalized.expectedCurrentReleaseId };
|
|
952
|
+
const replay = await publication.replayFinalized(input);
|
|
953
|
+
if (replay !== undefined)
|
|
954
|
+
return commitOutcome(replay, artifactId, meta, state => { commitState = state; }, invocation.storageScopeId);
|
|
955
|
+
profile.validate(capability, args, request.idempotencyKey);
|
|
956
|
+
const resolved = await resolveBundleAssets(invocation, artifactId, {
|
|
957
|
+
files: (normalized.files ?? []),
|
|
958
|
+
assets: (normalized.assets ?? []),
|
|
959
|
+
}, { allowExtendedForms: true,
|
|
960
|
+
keepUnmodifiedPaths: normalized.keepUnmodifiedPaths === true,
|
|
961
|
+
expectedCurrentReleaseId: normalized.expectedCurrentReleaseId });
|
|
650
962
|
const outcome = await publication.publishFinalized({
|
|
651
963
|
...input, source: { kind: 'inline-original' },
|
|
652
|
-
profile: normalized.profile, files,
|
|
964
|
+
profile: normalized.profile, files: resolved.files,
|
|
653
965
|
});
|
|
654
|
-
const committed = commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; });
|
|
966
|
+
const committed = await commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; }, invocation.storageScopeId);
|
|
655
967
|
if (committed.ok) {
|
|
656
968
|
const parsedBundleManifest = parseManifest(committed.result.body.manifest);
|
|
657
969
|
const entries = parsedBundleManifest.files ?? [];
|
|
658
970
|
committed.result.body.files = entries.map((entry) => ({
|
|
659
971
|
path: entry.path, mimeType: entry.mimeType, size: entry.size, digest: entry.digest,
|
|
660
|
-
origin: origins[entry.path] ?? 'inline',
|
|
972
|
+
origin: resolved.origins[entry.path] ?? 'inline',
|
|
661
973
|
}));
|
|
974
|
+
// LOT 2 §D.1: consumed upload pins leave with the bundle; the
|
|
975
|
+
// release ref keeps the blob alive. Best-effort: the sweeper is
|
|
976
|
+
// the backstop and reports what it unpins.
|
|
977
|
+
for (const pin of resolved.uploadPins) {
|
|
978
|
+
await deps.publication.refs.unpin(pin.digest, `upload:${pin.uploadId}`).catch(() => undefined);
|
|
979
|
+
}
|
|
980
|
+
if (deps.uploads?.metrics !== undefined) {
|
|
981
|
+
for (const file of resolved.files) {
|
|
982
|
+
const origin = resolved.origins[file.path] ?? 'inline';
|
|
983
|
+
const coarse = origin.startsWith('copy:') ? 'copy' : origin.startsWith('carry:') ? 'carry'
|
|
984
|
+
: origin.startsWith('upload:') ? 'upload' : origin;
|
|
985
|
+
deps.uploads.metrics.emit({ name: 'bundle_assets', labels: { origin: coarse } });
|
|
986
|
+
}
|
|
987
|
+
}
|
|
662
988
|
}
|
|
663
989
|
return committed;
|
|
664
990
|
}
|
|
@@ -685,14 +1011,25 @@ export function createHttpArtifactApp(deps) {
|
|
|
685
1011
|
limit: normalized.limit, cursor: normalized.cursor,
|
|
686
1012
|
state: id => deps.lifecycle.getReleaseState(id), urls: deps.publicationUrls });
|
|
687
1013
|
await visible(artifactId, invocation);
|
|
1014
|
+
if (deps.directory) {
|
|
1015
|
+
for (const version of body.versions) {
|
|
1016
|
+
if (typeof version.authorPrincipalId === 'string') {
|
|
1017
|
+
version.authorPrincipalId = (await deps.directory.describePrincipal(invocation.storageScopeId, version.authorPrincipalId))?.userRef ?? UNKNOWN_USER_REF;
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
688
1021
|
return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
|
|
689
1022
|
result: { status: 200, body } };
|
|
690
1023
|
}
|
|
691
1024
|
const releases = [];
|
|
692
1025
|
for (const release of await deps.publication.listReleases(artifactId)) {
|
|
693
1026
|
const manifest = parseManifest(release.manifest);
|
|
1027
|
+
const rawAuthor = typeof manifest.ownerId === 'string' ? manifest.ownerId : null;
|
|
1028
|
+
const author = rawAuthor === null || !deps.directory ? rawAuthor
|
|
1029
|
+
: (await deps.directory.describePrincipal(invocation.storageScopeId, rawAuthor))?.userRef
|
|
1030
|
+
?? UNKNOWN_USER_REF;
|
|
694
1031
|
releases.push({ releaseId: release.releaseId, createdAt: release.createdAt,
|
|
695
|
-
author
|
|
1032
|
+
author,
|
|
696
1033
|
state: await deps.lifecycle.getReleaseState(release.releaseId),
|
|
697
1034
|
isCurrent: current?.releaseId === release.releaseId,
|
|
698
1035
|
digest: release.manifestDigest });
|
|
@@ -726,7 +1063,7 @@ export function createHttpArtifactApp(deps) {
|
|
|
726
1063
|
: acl.grants.filter((grant) => grant.principalId === invocation.actorId);
|
|
727
1064
|
const grants = await Promise.all(visibleGrants.map(async (grant) => {
|
|
728
1065
|
const person = await deps.directory.describePrincipal(invocation.storageScopeId, grant.principalId);
|
|
729
|
-
const userRef = person?.userRef ??
|
|
1066
|
+
const userRef = person?.userRef ?? UNKNOWN_USER_REF;
|
|
730
1067
|
const { effective, blockedBy } = evaluateGrant(acl, grant.principalId, deps.isApprovedAccount ?? (() => false));
|
|
731
1068
|
return { userRef, displayName: person?.displayName ?? userRef,
|
|
732
1069
|
...(person === undefined ? {} : { emailHint: maskEmailHint(person.email) }),
|
|
@@ -736,7 +1073,8 @@ export function createHttpArtifactApp(deps) {
|
|
|
736
1073
|
const owner = await deps.directory.describePrincipal(invocation.storageScopeId, acl.ownerId);
|
|
737
1074
|
return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
|
|
738
1075
|
result: { status: 200, body: { artifactId, accessMode: accessModeOf(acl),
|
|
739
|
-
owner: { userRef: owner?.userRef ??
|
|
1076
|
+
owner: { userRef: owner?.userRef ?? UNKNOWN_USER_REF,
|
|
1077
|
+
displayName: owner?.displayName ?? UNKNOWN_USER_REF },
|
|
740
1078
|
canManage, grants } } };
|
|
741
1079
|
}
|
|
742
1080
|
const visibleArtifacts = [];
|