@sentropic/artifacts 0.2.16 → 0.2.18
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 +39 -0
- package/dist/adapters/github-forge.d.ts +4 -0
- package/dist/adapters/github-forge.js +88 -0
- package/dist/adapters/github-git-port.d.ts +5 -0
- package/dist/adapters/github-git-port.js +102 -0
- package/dist/adapters/github-http.d.ts +5 -0
- package/dist/adapters/github-http.js +57 -0
- package/dist/adapters/github-receive-pack.d.ts +4 -0
- package/dist/adapters/github-receive-pack.js +49 -0
- package/dist/adapters/postgres-git-bindings.d.ts +7 -0
- package/dist/adapters/postgres-git-bindings.js +110 -0
- package/dist/adapters/postgres-live.d.ts +4 -0
- package/dist/adapters/postgres-live.js +97 -0
- package/dist/adapters/postgres.d.ts +1 -0
- package/dist/adapters/postgres.js +1 -0
- package/dist/content/handler.d.ts +7 -0
- package/dist/content/handler.js +28 -5
- package/dist/content/headers.d.ts +13 -0
- package/dist/content/headers.js +40 -2
- package/dist/git-tool-definitions.d.ts +606 -0
- package/dist/git-tool-definitions.js +14 -0
- package/dist/http.d.ts +6 -0
- package/dist/http.js +20 -2
- package/dist/index.d.ts +13 -0
- package/dist/index.js +12 -0
- package/dist/mcp-core.d.ts +3 -3
- package/dist/mcp-core.js +15 -2
- package/dist/profile/contracts.d.ts +1 -1
- package/dist/profile/contracts.js +4 -0
- package/dist/profile/index.js +8 -1
- package/dist/profile/schemas.js +19 -0
- package/dist/profile/validation.js +5 -1
- package/dist/server/build-contract.d.ts +64 -0
- package/dist/server/build-contract.js +58 -0
- package/dist/server/build-dependencies.d.ts +3 -0
- package/dist/server/build-dependencies.js +122 -0
- package/dist/server/consent-grant.d.ts +91 -0
- package/dist/server/consent-grant.js +89 -0
- package/dist/server/consent-screen.d.ts +21 -0
- package/dist/server/consent-screen.js +52 -0
- package/dist/server/failures.d.ts +3 -2
- package/dist/server/failures.js +30 -0
- package/dist/server/git-bindings.d.ts +8 -0
- package/dist/server/git-bindings.js +113 -0
- package/dist/server/git-contracts.d.ts +98 -0
- package/dist/server/git-contracts.js +1 -0
- package/dist/server/git-port-policy.d.ts +9 -0
- package/dist/server/git-port-policy.js +76 -0
- package/dist/server/git-port-read.d.ts +3 -0
- package/dist/server/git-port-read.js +95 -0
- package/dist/server/git-port-session.d.ts +38 -0
- package/dist/server/git-port-session.js +59 -0
- package/dist/server/git-port-tree.d.ts +8 -0
- package/dist/server/git-port-tree.js +92 -0
- package/dist/server/git-port-write.d.ts +6 -0
- package/dist/server/git-port-write.js +102 -0
- package/dist/server/git-port.d.ts +147 -0
- package/dist/server/git-port.js +8 -0
- package/dist/server/git-projection.d.ts +16 -0
- package/dist/server/git-projection.js +20 -0
- package/dist/server/git-registry.d.ts +37 -0
- package/dist/server/git-registry.js +39 -0
- package/dist/server/live-body.d.ts +3 -0
- package/dist/server/live-body.js +28 -0
- package/dist/server/live-commit-outcome.d.ts +6 -0
- package/dist/server/live-commit-outcome.js +10 -0
- package/dist/server/live-commit.d.ts +11 -0
- package/dist/server/live-commit.js +133 -0
- package/dist/server/live-contracts.d.ts +62 -0
- package/dist/server/live-contracts.js +8 -0
- package/dist/server/live-crypto.d.ts +14 -0
- package/dist/server/live-crypto.js +50 -0
- package/dist/server/live-drafts.d.ts +61 -0
- package/dist/server/live-drafts.js +119 -0
- package/dist/server/live-errors.d.ts +23 -0
- package/dist/server/live-errors.js +9 -0
- package/dist/server/live-mutations.d.ts +18 -0
- package/dist/server/live-mutations.js +83 -0
- package/dist/server/live-read.d.ts +15 -0
- package/dist/server/live-read.js +95 -0
- package/dist/server/live-service.d.ts +3 -0
- package/dist/server/live-service.js +181 -0
- package/dist/server/live-store.d.ts +111 -0
- package/dist/server/live-store.js +80 -0
- package/dist/server/live-tree.d.ts +22 -0
- package/dist/server/live-tree.js +148 -0
- package/dist/server/live-worker.d.ts +10 -0
- package/dist/server/live-worker.js +55 -0
- package/dist/server/mime.d.ts +9 -0
- package/dist/server/mime.js +47 -0
- package/dist/server/upload-page.d.ts +7 -0
- package/dist/server/upload-page.js +16 -1
- package/migrations/0010_git_bindings.sql +82 -0
- package/migrations/0011_live_drafts.sql +42 -0
- package/package.json +13 -1
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { ArtifactOperationError } from './failures.js';
|
|
3
|
+
import { assertGitTarget, gitPath } from './git-port-policy.js';
|
|
4
|
+
import { liveTextValid, overlayBytes } from './live-crypto.js';
|
|
5
|
+
export function validateLiveMutation(repo, target, input, maxPaths = 255, maxBytes = 2 * 1024 * 1024) {
|
|
6
|
+
assertGitTarget(repo, target, true);
|
|
7
|
+
const seen = new Set();
|
|
8
|
+
let bytes = 0;
|
|
9
|
+
for (const kind of ['edits', 'files', 'deletes']) {
|
|
10
|
+
const array = input[kind];
|
|
11
|
+
if (array === undefined)
|
|
12
|
+
continue;
|
|
13
|
+
if (!Array.isArray(array) || !array.length)
|
|
14
|
+
throw new ArtifactOperationError('invalid_request');
|
|
15
|
+
if (kind === 'edits' && array.length > 100)
|
|
16
|
+
throw new ArtifactOperationError('limit_exceeded');
|
|
17
|
+
for (const value of array) {
|
|
18
|
+
const path = typeof value === 'string' ? value : value?.path;
|
|
19
|
+
if (typeof path !== 'string' || seen.has(path))
|
|
20
|
+
throw new ArtifactOperationError('invalid_request');
|
|
21
|
+
gitPath(repo, target, path, true);
|
|
22
|
+
seen.add(path);
|
|
23
|
+
if (path.split('/').some(part => /^package.*\.json$/i.test(part)) ||
|
|
24
|
+
['.github/**', 'deploy/**', 'api/**', '.track/**', 'packages/immo-mcp/**'].some(glob => path === glob.slice(0, -3) || path.startsWith(glob.slice(0, -2))))
|
|
25
|
+
throw new ArtifactOperationError('git_path_refused');
|
|
26
|
+
if (typeof value !== 'string') {
|
|
27
|
+
const keys = kind === 'edits' ? ['path', 'oldStr', 'newStr'] : ['path', 'text'];
|
|
28
|
+
if (Object.keys(value).some(key => !keys.includes(key)))
|
|
29
|
+
throw new ArtifactOperationError('invalid_request');
|
|
30
|
+
for (const key of keys.filter(key => key !== 'path')) {
|
|
31
|
+
const text = value[key];
|
|
32
|
+
if (typeof text !== 'string' || !liveTextValid(text) || (key === 'oldStr' && !text))
|
|
33
|
+
throw new ArtifactOperationError('invalid_request');
|
|
34
|
+
if (/-----BEGIN (?:[A-Z ]+ )?PRIVATE KEY-----/.test(text))
|
|
35
|
+
throw new ArtifactOperationError('git_path_refused');
|
|
36
|
+
bytes += Buffer.byteLength(text);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (!seen.size)
|
|
42
|
+
throw new ArtifactOperationError('invalid_request');
|
|
43
|
+
if (seen.size > maxPaths || bytes > maxBytes)
|
|
44
|
+
throw new ArtifactOperationError('limit_exceeded');
|
|
45
|
+
}
|
|
46
|
+
/** Compute actual Git object IDs without creating forge objects, preserving all excluded base entries. */
|
|
47
|
+
export function liveTreeSha(base, overlay, target) {
|
|
48
|
+
const algorithm = base.treeSha.length === 64 ? 'sha256' : 'sha1';
|
|
49
|
+
const objectId = (kind, bytes) => createHash(algorithm)
|
|
50
|
+
.update(Buffer.from(`${kind} ${bytes.length}\0`)).update(bytes).digest('hex');
|
|
51
|
+
const files = new Map(base.entries.map(entry => [entry.path, { mode: entry.mode, sha: entry.sha, type: entry.type }]));
|
|
52
|
+
for (const entry of overlay) {
|
|
53
|
+
const path = target.subPath ? target.subPath + '/' + entry.path : entry.path;
|
|
54
|
+
if (entry.text === null)
|
|
55
|
+
files.delete(path);
|
|
56
|
+
else
|
|
57
|
+
files.set(path, { mode: entry.mode, sha: objectId('blob', Buffer.from(entry.text)), type: 'blob' });
|
|
58
|
+
}
|
|
59
|
+
const node = () => ({ files: new Map(), directories: new Map() });
|
|
60
|
+
const root = node();
|
|
61
|
+
for (const [path, file] of files) {
|
|
62
|
+
const parts = path.split('/');
|
|
63
|
+
let current = root;
|
|
64
|
+
for (const part of file.type === 'tree' ? parts : parts.slice(0, -1)) {
|
|
65
|
+
if (!current.directories.has(part))
|
|
66
|
+
current.directories.set(part, node());
|
|
67
|
+
current = current.directories.get(part);
|
|
68
|
+
}
|
|
69
|
+
if (file.type !== 'tree')
|
|
70
|
+
current.files.set(parts.at(-1), file);
|
|
71
|
+
}
|
|
72
|
+
function hash(current) {
|
|
73
|
+
const entries = [...current.files].map(([name, entry]) => ({ name, ...entry, directory: false }));
|
|
74
|
+
for (const [name, child] of current.directories)
|
|
75
|
+
entries.push({ name, mode: '40000', sha: hash(child), directory: true });
|
|
76
|
+
entries.sort((a, b) => Buffer.compare(Buffer.from(a.name + (a.directory ? '/' : '')), Buffer.from(b.name + (b.directory ? '/' : ''))));
|
|
77
|
+
return objectId('tree', Buffer.concat(entries.map(entry => Buffer.concat([
|
|
78
|
+
Buffer.from(`${entry.mode.replace(/^0/, '')} ${entry.name}\0`), Buffer.from(entry.sha, 'hex')
|
|
79
|
+
]))));
|
|
80
|
+
}
|
|
81
|
+
return hash(root);
|
|
82
|
+
}
|
|
83
|
+
export async function applyLiveMutation(git, target, base, baseHeadSha, before, input) {
|
|
84
|
+
const overlay = new Map(before.map(entry => [entry.path, entry]));
|
|
85
|
+
const baseEntry = (path) => base.entries.find(entry => entry.path === (target.subPath ? target.subPath + '/' : '') + path);
|
|
86
|
+
const cache = new Map();
|
|
87
|
+
async function textAtBase(path) {
|
|
88
|
+
if (!baseEntry(path))
|
|
89
|
+
return undefined;
|
|
90
|
+
if (!cache.has(path)) {
|
|
91
|
+
const file = (await git.read(target, { commitSha: baseHeadSha, paths: [path] })).files[0];
|
|
92
|
+
if (!file || !('text' in file))
|
|
93
|
+
throw new ArtifactOperationError('edit_mismatch');
|
|
94
|
+
cache.set(path, file.text);
|
|
95
|
+
}
|
|
96
|
+
return cache.get(path);
|
|
97
|
+
}
|
|
98
|
+
async function put(path, text) {
|
|
99
|
+
const full = (target.subPath ? target.subPath + '/' : '') + path;
|
|
100
|
+
const entry = baseEntry(path);
|
|
101
|
+
if (base.entries.some(e => e.path.startsWith(full + '/') || (full.startsWith(e.path + '/') && e.type !== 'tree')) ||
|
|
102
|
+
(entry && (entry.type !== 'blob' || !['100644', '100755'].includes(entry.mode))))
|
|
103
|
+
throw new ArtifactOperationError('git_path_refused');
|
|
104
|
+
if (text === null && !entry) {
|
|
105
|
+
if (overlay.get(path)?.text === undefined || overlay.get(path)?.text === null)
|
|
106
|
+
throw new ArtifactOperationError('invalid_request');
|
|
107
|
+
overlay.delete(path);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (text !== null && Buffer.byteLength(text) > 1024 * 1024)
|
|
111
|
+
throw new ArtifactOperationError('limit_exceeded');
|
|
112
|
+
if (text !== null && entry && text === await textAtBase(path))
|
|
113
|
+
overlay.delete(path);
|
|
114
|
+
else
|
|
115
|
+
overlay.set(path, { path, text, mode: entry?.mode ?? '100644' });
|
|
116
|
+
}
|
|
117
|
+
for (const edit of input.edits ?? []) {
|
|
118
|
+
const text = overlay.has(edit.path) ? overlay.get(edit.path).text : await textAtBase(edit.path);
|
|
119
|
+
const first = text?.indexOf(edit.oldStr) ?? -1;
|
|
120
|
+
if (text === null || text === undefined || first < 0 || text.indexOf(edit.oldStr, first + 1) >= 0)
|
|
121
|
+
throw new ArtifactOperationError('edit_mismatch');
|
|
122
|
+
await put(edit.path, text.slice(0, first) + edit.newStr + text.slice(first + edit.oldStr.length));
|
|
123
|
+
}
|
|
124
|
+
for (const file of input.files ?? [])
|
|
125
|
+
await put(file.path, file.text);
|
|
126
|
+
for (const path of input.deletes ?? [])
|
|
127
|
+
await put(path, null);
|
|
128
|
+
const result = [...overlay.values()].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
129
|
+
const paths = new Set(base.entries.filter(entry => entry.type !== 'tree').map(entry => entry.path));
|
|
130
|
+
for (const entry of result) {
|
|
131
|
+
const full = (target.subPath ? target.subPath + '/' : '') + entry.path;
|
|
132
|
+
if (entry.text === null)
|
|
133
|
+
paths.delete(full);
|
|
134
|
+
else
|
|
135
|
+
paths.add(full);
|
|
136
|
+
}
|
|
137
|
+
for (const path of paths) {
|
|
138
|
+
const parents = path.split('/');
|
|
139
|
+
parents.pop();
|
|
140
|
+
while (parents.length) {
|
|
141
|
+
if (paths.has(parents.join('/')))
|
|
142
|
+
throw new ArtifactOperationError('git_path_refused');
|
|
143
|
+
parents.pop();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
overlayBytes(result);
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LiveIdentity } from './live-store.js';
|
|
2
|
+
import type { LiveServiceDeps } from './live-contracts.js';
|
|
3
|
+
/** Side effects follow durable intents. Failure leaves the accepted source recoverable and pending. */
|
|
4
|
+
export declare function settleLiveWorker(input: {
|
|
5
|
+
deps: LiveServiceDeps;
|
|
6
|
+
identity: LiveIdentity;
|
|
7
|
+
action: 'project' | 'stop';
|
|
8
|
+
result: Record<string, any>;
|
|
9
|
+
now: number;
|
|
10
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { expireLiveDraft, persistLiveOverlay, readLiveOverlay } from './live-drafts.js';
|
|
2
|
+
/** Side effects follow durable intents. Failure leaves the accepted source recoverable and pending. */
|
|
3
|
+
export async function settleLiveWorker(input) {
|
|
4
|
+
const { deps, identity, action, result, now } = input;
|
|
5
|
+
if (!deps.worker)
|
|
6
|
+
return;
|
|
7
|
+
try {
|
|
8
|
+
if (action === 'stop') {
|
|
9
|
+
const runtime = await deps.store.transaction(identity, async (tx) => tx.record?.runtime);
|
|
10
|
+
if (!runtime || runtime.liveSessionId !== result.liveSessionId)
|
|
11
|
+
return;
|
|
12
|
+
await deps.worker.stop({ ...identity, liveSessionId: runtime.liveSessionId, leaseEpoch: runtime.leaseEpoch });
|
|
13
|
+
await deps.store.transaction(identity, async (tx) => {
|
|
14
|
+
if (tx.record?.runtime?.liveSessionId === runtime.liveSessionId && tx.record.runtime.leaseEpoch === runtime.leaseEpoch &&
|
|
15
|
+
['QUIESCING', 'SAVING', 'DECOMMISSIONING'].includes(tx.record.runtime.phase)) {
|
|
16
|
+
tx.record.runtime.phase = 'DORMANT';
|
|
17
|
+
tx.record.runtime.appliedRevision = null;
|
|
18
|
+
result.state = 'DORMANT';
|
|
19
|
+
result.runtimeState = 'DORMANT';
|
|
20
|
+
result.appliedRevision = null;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const ack = await deps.worker.reconcile(identity);
|
|
26
|
+
if (!ack?.ready)
|
|
27
|
+
return;
|
|
28
|
+
await deps.store.transaction(identity, async (tx) => {
|
|
29
|
+
const record = tx.record;
|
|
30
|
+
const runtime = record?.runtime;
|
|
31
|
+
if (!record || !runtime || ack.liveSessionId !== runtime.liveSessionId || ack.leaseEpoch !== runtime.leaseEpoch ||
|
|
32
|
+
ack.routeEpoch !== runtime.routeEpoch || ack.revision !== record.revision || !['REVIVING', 'LIVE'].includes(runtime.phase))
|
|
33
|
+
return;
|
|
34
|
+
const at = (deps.now ?? Date.now)();
|
|
35
|
+
if (expireLiveDraft(tx, at))
|
|
36
|
+
return;
|
|
37
|
+
if (runtime.renewOnReady && record.changedPaths) {
|
|
38
|
+
const overlay = await readLiveOverlay(tx, deps.keys);
|
|
39
|
+
const renewed = await persistLiveOverlay(tx, deps.keys, { identity, expectedRevision: record.revision,
|
|
40
|
+
baseHeadSha: record.baseHeadSha, baseTreeSha: record.baseTreeSha, liveTreeSha: record.liveTreeSha, overlay }, at, true, true);
|
|
41
|
+
// Source revision remains fenced to the worker ACK; reauthentication is handled by the vault.
|
|
42
|
+
result.draftExpiresAt = renewed.expiresAt;
|
|
43
|
+
}
|
|
44
|
+
runtime.renewOnReady = false;
|
|
45
|
+
runtime.appliedRevision = ack.revision;
|
|
46
|
+
runtime.phase = 'LIVE';
|
|
47
|
+
result.appliedRevision = ack.revision;
|
|
48
|
+
result.workerPending = false;
|
|
49
|
+
result.runtimeState = 'LIVE';
|
|
50
|
+
result.state = 'LIVE';
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch { /* The durable intent remains available to the controller's fenced reconciliation. */ }
|
|
55
|
+
}
|
package/dist/server/mime.d.ts
CHANGED
|
@@ -20,6 +20,15 @@ export declare const TEXT_MIME_RE: RegExp;
|
|
|
20
20
|
* single-label content origin, and sandbox CSP on SVG/PDF.
|
|
21
21
|
*/
|
|
22
22
|
export declare const SERVER_MIME_CEILING: readonly string[];
|
|
23
|
+
/**
|
|
24
|
+
* J1.1a — generic extension to MIME map (binding J1.0 relay). `.geojson`
|
|
25
|
+
* serves as `application/json`, `.mjs` as `text/javascript` and `.woff2` as
|
|
26
|
+
* `font/woff2`; `.wasm` and `.pbf` stay mapped as the owner asked. Every
|
|
27
|
+
* value stays inside the server ceiling.
|
|
28
|
+
*/
|
|
29
|
+
export declare const EXTENSION_TO_MIME: Readonly<Record<string, string>>;
|
|
30
|
+
/** MIME type for a manifest path by extension, case-insensitive, undefined off-map. */
|
|
31
|
+
export declare function mimeTypeForPath(path: string): string | undefined;
|
|
23
32
|
/** True when the MIME type is inside the generic ceiling. */
|
|
24
33
|
export declare function isWithinMimeCeiling(mimeType: string): boolean;
|
|
25
34
|
/**
|
package/dist/server/mime.js
CHANGED
|
@@ -26,7 +26,49 @@ export const SERVER_MIME_CEILING = Object.freeze([
|
|
|
26
26
|
'application/pdf',
|
|
27
27
|
'font/woff', 'font/woff2', 'font/ttf', 'font/otf',
|
|
28
28
|
'video/mp4', 'video/webm',
|
|
29
|
+
// J1.1a: bound application assets. Served bytes can never compile without
|
|
30
|
+
// `wasm-unsafe-eval`, which no served policy carries.
|
|
31
|
+
'application/wasm',
|
|
32
|
+
'application/x-protobuf',
|
|
29
33
|
]);
|
|
34
|
+
/**
|
|
35
|
+
* J1.1a — generic extension to MIME map (binding J1.0 relay). `.geojson`
|
|
36
|
+
* serves as `application/json`, `.mjs` as `text/javascript` and `.woff2` as
|
|
37
|
+
* `font/woff2`; `.wasm` and `.pbf` stay mapped as the owner asked. Every
|
|
38
|
+
* value stays inside the server ceiling.
|
|
39
|
+
*/
|
|
40
|
+
export const EXTENSION_TO_MIME = Object.freeze({
|
|
41
|
+
'.html': 'text/html',
|
|
42
|
+
'.js': 'text/javascript',
|
|
43
|
+
'.mjs': 'text/javascript',
|
|
44
|
+
'.css': 'text/css',
|
|
45
|
+
'.json': 'application/json',
|
|
46
|
+
'.geojson': 'application/json',
|
|
47
|
+
'.svg': 'image/svg+xml',
|
|
48
|
+
'.png': 'image/png',
|
|
49
|
+
'.jpg': 'image/jpeg',
|
|
50
|
+
'.jpeg': 'image/jpeg',
|
|
51
|
+
'.gif': 'image/gif',
|
|
52
|
+
'.webp': 'image/webp',
|
|
53
|
+
'.avif': 'image/avif',
|
|
54
|
+
'.ico': 'image/x-icon',
|
|
55
|
+
'.pdf': 'application/pdf',
|
|
56
|
+
'.woff': 'font/woff',
|
|
57
|
+
'.woff2': 'font/woff2',
|
|
58
|
+
'.ttf': 'font/ttf',
|
|
59
|
+
'.otf': 'font/otf',
|
|
60
|
+
'.mp4': 'video/mp4',
|
|
61
|
+
'.webm': 'video/webm',
|
|
62
|
+
'.wasm': 'application/wasm',
|
|
63
|
+
'.pbf': 'application/x-protobuf',
|
|
64
|
+
});
|
|
65
|
+
/** MIME type for a manifest path by extension, case-insensitive, undefined off-map. */
|
|
66
|
+
export function mimeTypeForPath(path) {
|
|
67
|
+
const dot = path.lastIndexOf('.');
|
|
68
|
+
if (dot === -1)
|
|
69
|
+
return undefined;
|
|
70
|
+
return EXTENSION_TO_MIME[path.slice(dot).toLowerCase()];
|
|
71
|
+
}
|
|
30
72
|
/** True when the MIME type is inside the generic ceiling. */
|
|
31
73
|
export function isWithinMimeCeiling(mimeType) {
|
|
32
74
|
return SERVER_MIME_CEILING.includes(mimeType);
|
|
@@ -42,6 +84,7 @@ const MAGIC_BYTES = Object.freeze({
|
|
|
42
84
|
'application/pdf': [[0x25, 0x50, 0x44, 0x46, 0x2d]], // %PDF-
|
|
43
85
|
'font/woff': [[0x77, 0x4f, 0x46, 0x46]], // wOFF
|
|
44
86
|
'font/woff2': [[0x77, 0x4f, 0x46, 0x32]], // wOF2
|
|
87
|
+
'application/wasm': [[0x00, 0x61, 0x73, 0x6d]], // \0asm
|
|
45
88
|
'font/ttf': [[0x00, 0x01, 0x00, 0x00]],
|
|
46
89
|
'font/otf': [[0x4f, 0x54, 0x54, 0x4f]], // OTTO
|
|
47
90
|
'video/mp4': [[0x66, 0x74, 0x79, 0x70]], // ftyp (brand checked loosely: isom/iso2/mp41/mp42/avc1/dash/msdh/m4v...)
|
|
@@ -120,6 +163,10 @@ export function validateFileBytes(mimeType, bytes) {
|
|
|
120
163
|
throw new Error('mp4 magic bytes mismatch');
|
|
121
164
|
return;
|
|
122
165
|
}
|
|
166
|
+
// Opaque protobuf has no magic: any bytes pass (the ceiling allowlist and
|
|
167
|
+
// the serving policy without `wasm-unsafe-eval` stay the guards).
|
|
168
|
+
if (mimeType === 'application/x-protobuf')
|
|
169
|
+
return;
|
|
123
170
|
const magics = MAGIC_BYTES[mimeType];
|
|
124
171
|
if (magics === undefined)
|
|
125
172
|
throw new Error(`no magic-byte rule for ${mimeType}`);
|
|
@@ -50,6 +50,13 @@ export declare function buildUploadPageCookie(value: string, maxAgeSeconds: numb
|
|
|
50
50
|
export declare function parseUploadPageCookie(header: string | undefined): string | undefined;
|
|
51
51
|
/** Page CSP (§A.4): no external assets; S3 origins are host-supplied. */
|
|
52
52
|
export declare function uploadPageCsp(s3Origins: readonly string[]): string;
|
|
53
|
+
/**
|
|
54
|
+
* J1.1a — browser fallback MIME by extension for the upload page, used only
|
|
55
|
+
* when the browser reports no `File.type`: `.geojson` as `application/json`,
|
|
56
|
+
* `.mjs` as `text/javascript`, `.woff2` as `font/woff2`, plus owner-kept
|
|
57
|
+
* `.wasm` and `.pbf`. Rendered into the page as JSON.
|
|
58
|
+
*/
|
|
59
|
+
export declare const BROWSER_EXTENSION_FALLBACK_MIME: Readonly<Record<string, string>>;
|
|
53
60
|
/**
|
|
54
61
|
* Self-contained static upload page (no external assets). Bytes travel
|
|
55
62
|
* browser → S3 via raw PUT (FormData is banned: multipart wrapping changes
|
|
@@ -132,6 +132,21 @@ export function uploadPageCsp(s3Origins) {
|
|
|
132
132
|
'img-src \'self\' blob:', 'font-src \'self\'', `connect-src 'self' ${s3Origins.join(' ')}`,
|
|
133
133
|
'base-uri \'none\'', 'form-action \'none\'', 'frame-ancestors \'none\''].join('; ');
|
|
134
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* J1.1a — browser fallback MIME by extension for the upload page, used only
|
|
137
|
+
* when the browser reports no `File.type`: `.geojson` as `application/json`,
|
|
138
|
+
* `.mjs` as `text/javascript`, `.woff2` as `font/woff2`, plus owner-kept
|
|
139
|
+
* `.wasm` and `.pbf`. Rendered into the page as JSON.
|
|
140
|
+
*/
|
|
141
|
+
export const BROWSER_EXTENSION_FALLBACK_MIME = Object.freeze({
|
|
142
|
+
geojson: 'application/json',
|
|
143
|
+
mjs: 'text/javascript',
|
|
144
|
+
woff2: 'font/woff2',
|
|
145
|
+
wasm: 'application/wasm',
|
|
146
|
+
pbf: 'application/x-protobuf',
|
|
147
|
+
avif: 'image/avif',
|
|
148
|
+
ico: 'image/x-icon',
|
|
149
|
+
});
|
|
135
150
|
/**
|
|
136
151
|
* Self-contained static upload page (no external assets). Bytes travel
|
|
137
152
|
* browser → S3 via raw PUT (FormData is banned: multipart wrapping changes
|
|
@@ -181,7 +196,7 @@ const api = async (path, body, method) => {
|
|
|
181
196
|
if (!response.ok) throw new Error(path + ' failed: ' + response.status);
|
|
182
197
|
return response.json();
|
|
183
198
|
};
|
|
184
|
-
const EXT_TYPES = {
|
|
199
|
+
const EXT_TYPES = ${JSON.stringify(BROWSER_EXTENSION_FALLBACK_MIME)};
|
|
185
200
|
const chunked = (bytes, f) => {
|
|
186
201
|
const view = new Uint8Array(bytes);
|
|
187
202
|
let out = '';
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
-- SG1, G0 FROZEN v3 §2. Additive; live sessions have a separate later migration.
|
|
2
|
+
CREATE UNIQUE INDEX artifacts_id_scope_git ON artifacts.artifacts(id, storage_scope_id);
|
|
3
|
+
CREATE TABLE artifacts.git_bindings (
|
|
4
|
+
artifact_id UUID PRIMARY KEY,
|
|
5
|
+
storage_scope_id TEXT NOT NULL,
|
|
6
|
+
repo_id TEXT NOT NULL,
|
|
7
|
+
branch TEXT NOT NULL CHECK (branch LIKE 'artifact/%'),
|
|
8
|
+
channel TEXT NOT NULL CHECK (channel IN ('personal', 'shared')),
|
|
9
|
+
personal_principal_id TEXT,
|
|
10
|
+
sub_path TEXT NOT NULL,
|
|
11
|
+
base_commit_sha TEXT NOT NULL,
|
|
12
|
+
head_commit_sha TEXT,
|
|
13
|
+
release_commit_sha TEXT,
|
|
14
|
+
auto_publish BOOLEAN NOT NULL DEFAULT false,
|
|
15
|
+
executor TEXT NOT NULL CHECK (executor IN ('caller', 'ci', 'sandbox')),
|
|
16
|
+
pending_job_id TEXT,
|
|
17
|
+
pending_commit_sha TEXT,
|
|
18
|
+
state TEXT NOT NULL CHECK (state IN ('attached', 'syncing', 'build_pending', 'build_failed',
|
|
19
|
+
'diverged', 'paused', 'detached', 'error')),
|
|
20
|
+
state_detail TEXT,
|
|
21
|
+
generation INTEGER NOT NULL CHECK (generation > 0),
|
|
22
|
+
version INTEGER NOT NULL CHECK (version > 0),
|
|
23
|
+
attached_by TEXT NOT NULL,
|
|
24
|
+
attached_at TIMESTAMPTZ NOT NULL,
|
|
25
|
+
updated_at TIMESTAMPTZ NOT NULL,
|
|
26
|
+
FOREIGN KEY (artifact_id, storage_scope_id) REFERENCES artifacts.artifacts(id, storage_scope_id),
|
|
27
|
+
CHECK ((channel = 'personal') = (personal_principal_id IS NOT NULL)),
|
|
28
|
+
CHECK ((pending_job_id IS NULL) = (pending_commit_sha IS NULL))
|
|
29
|
+
);
|
|
30
|
+
CREATE UNIQUE INDEX git_bindings_active_artifact ON artifacts.git_bindings(artifact_id) WHERE state <> 'detached';
|
|
31
|
+
CREATE UNIQUE INDEX git_bindings_active_branch ON artifacts.git_bindings(repo_id, branch) WHERE state <> 'detached';
|
|
32
|
+
CREATE INDEX git_bindings_scope ON artifacts.git_bindings(storage_scope_id, artifact_id);
|
|
33
|
+
|
|
34
|
+
CREATE TABLE artifacts.git_binding_events (
|
|
35
|
+
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
36
|
+
artifact_id UUID NOT NULL,
|
|
37
|
+
storage_scope_id TEXT NOT NULL,
|
|
38
|
+
actor_id TEXT NOT NULL,
|
|
39
|
+
action TEXT NOT NULL CHECK (action IN ('attach', 'pause', 'resume', 'detach', 'commit', 'inbound',
|
|
40
|
+
'publish', 'conflict', 'resolve', 'error')),
|
|
41
|
+
before_sha TEXT,
|
|
42
|
+
after_sha TEXT,
|
|
43
|
+
delivery_id TEXT,
|
|
44
|
+
invocation_id TEXT,
|
|
45
|
+
created_at TIMESTAMPTZ NOT NULL,
|
|
46
|
+
FOREIGN KEY (artifact_id, storage_scope_id) REFERENCES artifacts.artifacts(id, storage_scope_id)
|
|
47
|
+
);
|
|
48
|
+
CREATE INDEX git_binding_events_scope ON artifacts.git_binding_events(storage_scope_id, artifact_id, created_at);
|
|
49
|
+
|
|
50
|
+
ALTER TABLE artifacts.releases ADD COLUMN git_commit TEXT NULL;
|
|
51
|
+
CREATE UNIQUE INDEX releases_id_artifact_git ON artifacts.releases(id, artifact_id);
|
|
52
|
+
CREATE TABLE artifacts.git_release_index (
|
|
53
|
+
release_id UUID PRIMARY KEY,
|
|
54
|
+
artifact_id UUID NOT NULL,
|
|
55
|
+
storage_scope_id TEXT NOT NULL,
|
|
56
|
+
repo_id TEXT NOT NULL,
|
|
57
|
+
branch TEXT NOT NULL,
|
|
58
|
+
commit_sha TEXT NOT NULL,
|
|
59
|
+
tree_sha TEXT,
|
|
60
|
+
manifest_digest TEXT NOT NULL,
|
|
61
|
+
candidate_digest TEXT NOT NULL,
|
|
62
|
+
executor TEXT NOT NULL CHECK (executor IN ('caller', 'ci', 'sandbox')),
|
|
63
|
+
verification TEXT NOT NULL CHECK (verification IN ('declared', 'sha-verified', 'builder-attested')),
|
|
64
|
+
receipt_id TEXT NOT NULL,
|
|
65
|
+
job_id TEXT NOT NULL,
|
|
66
|
+
build_run_id TEXT,
|
|
67
|
+
attempt INTEGER CHECK (attempt > 0),
|
|
68
|
+
created_at TIMESTAMPTZ NOT NULL,
|
|
69
|
+
FOREIGN KEY (artifact_id, storage_scope_id) REFERENCES artifacts.artifacts(id, storage_scope_id),
|
|
70
|
+
FOREIGN KEY (release_id, artifact_id) REFERENCES artifacts.releases(id, artifact_id)
|
|
71
|
+
);
|
|
72
|
+
CREATE INDEX git_release_index_commit ON artifacts.git_release_index(storage_scope_id, artifact_id, commit_sha);
|
|
73
|
+
|
|
74
|
+
CREATE FUNCTION artifacts.reject_git_record_mutation() RETURNS trigger AS $$
|
|
75
|
+
BEGIN
|
|
76
|
+
RAISE EXCEPTION 'append-only: git audit and release index are immutable';
|
|
77
|
+
END;
|
|
78
|
+
$$ LANGUAGE plpgsql;
|
|
79
|
+
CREATE TRIGGER git_binding_events_append_only BEFORE UPDATE OR DELETE OR TRUNCATE ON artifacts.git_binding_events
|
|
80
|
+
FOR EACH STATEMENT EXECUTE FUNCTION artifacts.reject_git_record_mutation();
|
|
81
|
+
CREATE TRIGGER git_release_index_append_only BEFORE UPDATE OR DELETE OR TRUNCATE ON artifacts.git_release_index
|
|
82
|
+
FOR EACH STATEMENT EXECUTE FUNCTION artifacts.reject_git_record_mutation();
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
-- Private draft namespace: no publication blob key, manifest or reader grant references it.
|
|
2
|
+
CREATE TABLE IF NOT EXISTS artifacts.live_drafts (
|
|
3
|
+
storage_scope_id text NOT NULL,
|
|
4
|
+
artifact_id uuid NOT NULL,
|
|
5
|
+
binding_generation bigint NOT NULL CHECK (binding_generation > 0),
|
|
6
|
+
record jsonb NOT NULL,
|
|
7
|
+
PRIMARY KEY (storage_scope_id, artifact_id, binding_generation)
|
|
8
|
+
);
|
|
9
|
+
CREATE TABLE IF NOT EXISTS artifacts.live_draft_objects (
|
|
10
|
+
storage_scope_id text NOT NULL,
|
|
11
|
+
artifact_id uuid NOT NULL,
|
|
12
|
+
binding_generation bigint NOT NULL,
|
|
13
|
+
object_ref uuid NOT NULL,
|
|
14
|
+
envelope jsonb NOT NULL,
|
|
15
|
+
PRIMARY KEY (storage_scope_id, artifact_id, binding_generation, object_ref)
|
|
16
|
+
);
|
|
17
|
+
CREATE TABLE IF NOT EXISTS artifacts.live_commands (
|
|
18
|
+
storage_scope_id text NOT NULL,
|
|
19
|
+
actor_id text NOT NULL,
|
|
20
|
+
command_key text NOT NULL,
|
|
21
|
+
command_hash text NOT NULL,
|
|
22
|
+
result jsonb NOT NULL,
|
|
23
|
+
PRIMARY KEY (storage_scope_id, actor_id, command_key)
|
|
24
|
+
);
|
|
25
|
+
CREATE TABLE IF NOT EXISTS artifacts.live_commit_quota (
|
|
26
|
+
storage_scope_id text NOT NULL,
|
|
27
|
+
actor_id text NOT NULL,
|
|
28
|
+
artifact_id uuid NOT NULL,
|
|
29
|
+
invocation_id text NOT NULL,
|
|
30
|
+
created_at timestamptz NOT NULL,
|
|
31
|
+
PRIMARY KEY (storage_scope_id, actor_id, invocation_id)
|
|
32
|
+
);
|
|
33
|
+
CREATE INDEX IF NOT EXISTS live_commit_quota_window ON artifacts.live_commit_quota(storage_scope_id, created_at);
|
|
34
|
+
|
|
35
|
+
CREATE OR REPLACE FUNCTION artifacts.reject_live_object_update() RETURNS trigger LANGUAGE plpgsql AS $$
|
|
36
|
+
BEGIN
|
|
37
|
+
RAISE EXCEPTION 'live draft objects are immutable';
|
|
38
|
+
END;
|
|
39
|
+
$$;
|
|
40
|
+
DROP TRIGGER IF EXISTS live_object_immutable ON artifacts.live_draft_objects;
|
|
41
|
+
CREATE TRIGGER live_object_immutable BEFORE UPDATE ON artifacts.live_draft_objects
|
|
42
|
+
FOR EACH STATEMENT EXECUTE FUNCTION artifacts.reject_live_object_update();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentropic/artifacts",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.18",
|
|
4
4
|
"description": "Generic configurable artifacts MCP and artifact service: StorageScope/Artifact/Binding/Release model, canonical manifests, object authorization, idempotent intents (spec-v8 §9).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -67,6 +67,10 @@
|
|
|
67
67
|
},
|
|
68
68
|
"./sql/*": "./sql/*",
|
|
69
69
|
"./migrations/*": "./migrations/*",
|
|
70
|
+
"./server/build-contract": {
|
|
71
|
+
"types": "./dist/server/build-contract.d.ts",
|
|
72
|
+
"import": "./dist/server/build-contract.js"
|
|
73
|
+
},
|
|
70
74
|
"./server/ports": {
|
|
71
75
|
"types": "./dist/server/ports.d.ts",
|
|
72
76
|
"import": "./dist/server/ports.js"
|
|
@@ -75,6 +79,14 @@
|
|
|
75
79
|
"types": "./dist/server/consent.d.ts",
|
|
76
80
|
"import": "./dist/server/consent.js"
|
|
77
81
|
},
|
|
82
|
+
"./server/consent-grant": {
|
|
83
|
+
"types": "./dist/server/consent-grant.d.ts",
|
|
84
|
+
"import": "./dist/server/consent-grant.js"
|
|
85
|
+
},
|
|
86
|
+
"./server/mime": {
|
|
87
|
+
"types": "./dist/server/mime.d.ts",
|
|
88
|
+
"import": "./dist/server/mime.js"
|
|
89
|
+
},
|
|
78
90
|
"./server/reader-store": {
|
|
79
91
|
"types": "./dist/server/reader-store.d.ts",
|
|
80
92
|
"import": "./dist/server/reader-store.js"
|