@sentropic/artifacts 0.2.17 → 0.2.20
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/README.md +14 -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 +131 -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/git-tool-definitions.d.ts +606 -0
- package/dist/git-tool-definitions.js +14 -0
- package/dist/http.d.ts +9 -0
- package/dist/http.js +31 -2
- package/dist/index.d.ts +14 -0
- package/dist/index.js +13 -0
- package/dist/live-host/accept.d.ts +30 -0
- package/dist/live-host/accept.js +43 -0
- package/dist/live-host/api.d.ts +67 -0
- package/dist/live-host/api.js +60 -0
- package/dist/live-host/candidate.d.ts +21 -0
- package/dist/live-host/candidate.js +41 -0
- package/dist/live-host/errors.d.ts +9 -0
- package/dist/live-host/errors.js +14 -0
- package/dist/live-host/handoff.d.ts +63 -0
- package/dist/live-host/handoff.js +66 -0
- package/dist/live-host/index.d.ts +10 -0
- package/dist/live-host/index.js +10 -0
- package/dist/live-host/keys.d.ts +14 -0
- package/dist/live-host/keys.js +8 -0
- package/dist/live-host/live-format.d.ts +70 -0
- package/dist/live-host/live-format.js +100 -0
- package/dist/live-host/recheck.d.ts +59 -0
- package/dist/live-host/recheck.js +45 -0
- package/dist/mcp-core.d.ts +3 -3
- package/dist/mcp-core.js +18 -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 +10 -0
- package/dist/server/git-bindings.js +138 -0
- package/dist/server/git-contracts.d.ts +115 -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/git-tools-attach.d.ts +8 -0
- package/dist/server/git-tools-attach.js +139 -0
- package/dist/server/git-tools-contracts.d.ts +59 -0
- package/dist/server/git-tools-contracts.js +1 -0
- package/dist/server/git-tools-fetch.d.ts +21 -0
- package/dist/server/git-tools-fetch.js +65 -0
- package/dist/server/git-tools-publish.d.ts +13 -0
- package/dist/server/git-tools-publish.js +66 -0
- package/dist/server/git-tools.d.ts +4 -0
- package/dist/server/git-tools.js +18 -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/templates.js +26 -1
- package/migrations/0010_git_bindings.sql +82 -0
- package/migrations/0011_live_drafts.sql +42 -0
- package/migrations/0012_git_attach_intents.sql +19 -0
- package/package.json +17 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { ArtifactOperationError } from './failures.js';
|
|
2
|
+
import { buildJson, buildPath, buildRecord } from './build-contract.js';
|
|
3
|
+
const sections = ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies'];
|
|
4
|
+
function refuse() { throw new ArtifactOperationError('dep_outside_lock'); }
|
|
5
|
+
function registryUrl(value, registries) {
|
|
6
|
+
if (typeof value !== 'string')
|
|
7
|
+
return false;
|
|
8
|
+
try {
|
|
9
|
+
const url = new URL(value);
|
|
10
|
+
return url.protocol === 'https:' && !url.username && !url.password && !url.hash && !url.search
|
|
11
|
+
&& registries.some(registry => {
|
|
12
|
+
const base = new URL(registry.endsWith('/') ? registry : `${registry}/`);
|
|
13
|
+
return base.protocol === 'https:' && !base.username && !base.password
|
|
14
|
+
&& url.origin === base.origin && url.pathname.startsWith(base.pathname);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function registrySpec(value) {
|
|
22
|
+
if (typeof value !== 'string' || !value.trim())
|
|
23
|
+
return false;
|
|
24
|
+
const alias = /^npm:(?:@[^/]+\/)?[^@]+@(.+)$/.exec(value);
|
|
25
|
+
return /^[A-Za-z0-9~^*<>=| .+-]+$/.test(alias ? alias[1] : value);
|
|
26
|
+
}
|
|
27
|
+
/** Validate the lock-indexed install closure, including host-owned lifecycle permissions. */
|
|
28
|
+
export function validateBuildDependencies(snapshot, lock, installDirectory) {
|
|
29
|
+
if ((lock.lockfileVersion !== 2 && lock.lockfileVersion !== 3) || !buildRecord(lock.packages)
|
|
30
|
+
|| !buildRecord(lock.packages['']))
|
|
31
|
+
throw new ArtifactOperationError('build_descriptor_invalid');
|
|
32
|
+
const packages = lock.packages;
|
|
33
|
+
const lockedPackage = (path, name) => {
|
|
34
|
+
let directory = path;
|
|
35
|
+
for (;;) {
|
|
36
|
+
if (Object.hasOwn(packages, `${directory ? `${directory}/` : ''}node_modules/${name}`))
|
|
37
|
+
return true;
|
|
38
|
+
if (!directory)
|
|
39
|
+
return false;
|
|
40
|
+
directory = directory.includes('/') ? directory.slice(0, directory.lastIndexOf('/')) : '';
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const registries = snapshot.allowedRegistries ?? ['https://registry.npmjs.org/'];
|
|
44
|
+
const allowlist = snapshot.postinstallAllowlist ?? [];
|
|
45
|
+
const postinstall = [];
|
|
46
|
+
const repositoryPath = (path) => installDirectory ? `${installDirectory}/${path}` : path;
|
|
47
|
+
const workspaceTargets = new Set();
|
|
48
|
+
for (const [path, raw] of Object.entries(packages)) {
|
|
49
|
+
if (!buildRecord(raw) || (path !== '' && !buildPath(path))
|
|
50
|
+
|| (raw.hasInstallScript !== undefined && typeof raw.hasInstallScript !== 'boolean'))
|
|
51
|
+
refuse();
|
|
52
|
+
if (raw.link === true) {
|
|
53
|
+
if (!path.includes('node_modules/') || !buildPath(raw.resolved)
|
|
54
|
+
|| raw.resolved.split('/').includes('node_modules') || !buildRecord(packages[raw.resolved])
|
|
55
|
+
|| !Object.hasOwn(snapshot.files, repositoryPath(`${raw.resolved}/package.json`)))
|
|
56
|
+
refuse();
|
|
57
|
+
workspaceTargets.add(raw.resolved);
|
|
58
|
+
const workspace = buildJson(snapshot.files[repositoryPath(`${raw.resolved}/package.json`)]);
|
|
59
|
+
if (path.split('node_modules/').at(-1) !== workspace.name)
|
|
60
|
+
refuse();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
for (const [path, raw] of Object.entries(packages)) {
|
|
64
|
+
if (!buildRecord(raw))
|
|
65
|
+
refuse();
|
|
66
|
+
if (raw.link === true)
|
|
67
|
+
continue;
|
|
68
|
+
const local = path === '' || workspaceTargets.has(path);
|
|
69
|
+
if (!local && (!registryUrl(raw.resolved, registries) || typeof raw.version !== 'string'
|
|
70
|
+
|| !/^\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?(?:\+[A-Za-z0-9.-]+)?$/.test(raw.version)
|
|
71
|
+
|| typeof raw.integrity !== 'string' || !raw.integrity))
|
|
72
|
+
refuse();
|
|
73
|
+
const manifestPath = repositoryPath(path ? `${path}/package.json` : 'package.json');
|
|
74
|
+
const manifest = local ? buildJson(snapshot.files[manifestPath]) : raw;
|
|
75
|
+
for (const source of [raw, manifest]) {
|
|
76
|
+
for (const section of sections) {
|
|
77
|
+
const dependencies = source[section];
|
|
78
|
+
if (dependencies === undefined)
|
|
79
|
+
continue;
|
|
80
|
+
if (!buildRecord(dependencies))
|
|
81
|
+
refuse();
|
|
82
|
+
for (const [name, spec] of Object.entries(dependencies)) {
|
|
83
|
+
if (!registrySpec(spec) || !/^(?:@[A-Za-z0-9._-]+\/)?[A-Za-z0-9._-]+$/.test(name))
|
|
84
|
+
refuse();
|
|
85
|
+
if ((section === 'dependencies' || (local && section === 'devDependencies'))
|
|
86
|
+
&& !lockedPackage(path, name))
|
|
87
|
+
refuse();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// npm ci must not resolve an edited workspace manifest beyond its committed lock entry.
|
|
92
|
+
if (local) {
|
|
93
|
+
for (const section of sections) {
|
|
94
|
+
const declared = manifest[section];
|
|
95
|
+
const locked = raw[section];
|
|
96
|
+
if (declared === undefined && locked === undefined)
|
|
97
|
+
continue;
|
|
98
|
+
if (!buildRecord(declared) || !buildRecord(locked)
|
|
99
|
+
|| Object.keys(declared).length !== Object.keys(locked).length
|
|
100
|
+
|| Object.entries(declared).some(([name, spec]) => locked[name] !== spec))
|
|
101
|
+
refuse();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const scripts = buildRecord(manifest.scripts) ? manifest.scripts : {};
|
|
105
|
+
const hasScript = raw.hasInstallScript === true
|
|
106
|
+
|| ['preinstall', 'install', 'postinstall', 'prepare'].some(name => Object.hasOwn(scripts, name));
|
|
107
|
+
if (!hasScript)
|
|
108
|
+
continue;
|
|
109
|
+
const name = typeof raw.name === 'string' ? raw.name : path.split('node_modules/').at(-1);
|
|
110
|
+
const entry = { package: local ? manifest.name : name, version: raw.version, integrity: raw.integrity };
|
|
111
|
+
if (typeof entry.package !== 'string' || typeof entry.version !== 'string' || typeof entry.integrity !== 'string'
|
|
112
|
+
|| !entry.integrity || !allowlist.some(allowed => allowed.package === entry.package
|
|
113
|
+
&& allowed.version === entry.version && allowed.integrity === entry.integrity)) {
|
|
114
|
+
throw new ArtifactOperationError('install_script_not_allowlisted');
|
|
115
|
+
}
|
|
116
|
+
postinstall.push({ package: entry.package, version: entry.version, integrity: entry.integrity });
|
|
117
|
+
}
|
|
118
|
+
const scriptKey = snapshot.subPath.slice(installDirectory ? installDirectory.length + 1 : 0);
|
|
119
|
+
if (scriptKey && !workspaceTargets.has(scriptKey))
|
|
120
|
+
refuse();
|
|
121
|
+
return postinstall;
|
|
122
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic host binding for persistent reader consent
|
|
3
|
+
* (design-merged §4.1, §4.3). Thin host binding over the generic
|
|
4
|
+
* ArtifactReaderStore, scoped to one storage scope per service instance: the
|
|
5
|
+
* reader revokes only their own consents resolved from the verified session
|
|
6
|
+
* (never a body field); a platform admin may revoke any reader's consent
|
|
7
|
+
* (incident response, never grant); the artifact owner cannot revoke consent
|
|
8
|
+
* — the owner's instrument is share revocation. Revoking for an unreadable
|
|
9
|
+
* artifact reads `not_found`, never 403, so the existence oracle stays closed.
|
|
10
|
+
*/
|
|
11
|
+
import { type FreshRights, type GateBDecision } from './consent.js';
|
|
12
|
+
import type { ArtifactReaderStore } from './reader-store.js';
|
|
13
|
+
export { consentScreenPath, renderConsentScreen, type ConsentScreenParams } from './consent-screen.js';
|
|
14
|
+
/** Stable first-party grant refusal; hosts return this body with HTTP 403. */
|
|
15
|
+
export interface ReaderConsentRequired {
|
|
16
|
+
code: 'reader_consent_required';
|
|
17
|
+
scopeId: string;
|
|
18
|
+
retryable: false;
|
|
19
|
+
}
|
|
20
|
+
export declare function readerConsentRequired(scopeId: string): ReaderConsentRequired;
|
|
21
|
+
export interface ConsentGrantInput {
|
|
22
|
+
readerAccountId: string;
|
|
23
|
+
artifactId: string;
|
|
24
|
+
scopeId: string;
|
|
25
|
+
scopeVersion: string;
|
|
26
|
+
}
|
|
27
|
+
export interface ConsentRevokeInput {
|
|
28
|
+
readerAccountId: string;
|
|
29
|
+
artifactId: string;
|
|
30
|
+
scopeId?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface GateCheckInput {
|
|
33
|
+
readerAccountId: string;
|
|
34
|
+
artifactId: string;
|
|
35
|
+
scopeId: string;
|
|
36
|
+
scopeVersion: string;
|
|
37
|
+
rights: FreshRights;
|
|
38
|
+
}
|
|
39
|
+
export declare function createReaderConsentService(deps: {
|
|
40
|
+
store: ArtifactReaderStore;
|
|
41
|
+
storageScopeId: string;
|
|
42
|
+
canReadArtifact: (artifactId: string, readerAccountId: string) => Promise<boolean>;
|
|
43
|
+
isAdmin: (accountId: string) => Promise<boolean>;
|
|
44
|
+
resolveTitle?: (artifactId: string) => Promise<string | undefined>;
|
|
45
|
+
now?: () => string;
|
|
46
|
+
}): {
|
|
47
|
+
/**
|
|
48
|
+
* First-party grant with a locked fresh-rights re-check: the host's
|
|
49
|
+
* checkRights (immo getRights) runs immediately before the store write,
|
|
50
|
+
* under the host's own authority discipline.
|
|
51
|
+
*/
|
|
52
|
+
grantWithFreshRights(input: ConsentGrantInput, checkRights: () => Promise<boolean>): Promise<import("./consent.js").ReaderConsentRecord>;
|
|
53
|
+
/**
|
|
54
|
+
* J1.3b — fresh-rights probe for the first-party grant route: the same
|
|
55
|
+
* readability check the service was built with, so the grant route never
|
|
56
|
+
* invents its own authority rule.
|
|
57
|
+
*/
|
|
58
|
+
checkReaderFreshRights(input: {
|
|
59
|
+
readerAccountId: string;
|
|
60
|
+
artifactId: string;
|
|
61
|
+
}): Promise<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* J1.3b — Gate B for the generic reader gate route: live consent at the
|
|
64
|
+
* host-declared version plus fresh rights, evaluated on this call.
|
|
65
|
+
*/
|
|
66
|
+
evaluateGate(input: GateCheckInput): Promise<GateBDecision>;
|
|
67
|
+
listOwnConsents(readerAccountId: string): Promise<{
|
|
68
|
+
artifactId: string;
|
|
69
|
+
title: string;
|
|
70
|
+
scopeId: string;
|
|
71
|
+
scopeVersion: string;
|
|
72
|
+
grantedAt: string;
|
|
73
|
+
}[]>;
|
|
74
|
+
revokeOwnConsent(input: ConsentRevokeInput): Promise<{
|
|
75
|
+
changed: boolean;
|
|
76
|
+
revokedAt: string | null;
|
|
77
|
+
}>;
|
|
78
|
+
revokeAllOwnConsents(input: Omit<ConsentRevokeInput, 'scopeId'>): Promise<{
|
|
79
|
+
changed: boolean;
|
|
80
|
+
revoked: number;
|
|
81
|
+
}>;
|
|
82
|
+
/**
|
|
83
|
+
* Platform-admin incident revocation. The admin never grants (reduce-only,
|
|
84
|
+
* mirroring canManageAccess); the artifact owner is refused here.
|
|
85
|
+
*/
|
|
86
|
+
adminRevokeConsent(input: ConsentRevokeInput, adminAccountId: string): Promise<{
|
|
87
|
+
changed: boolean;
|
|
88
|
+
revokedAt: string | null;
|
|
89
|
+
}>;
|
|
90
|
+
};
|
|
91
|
+
export type ReaderConsentService = ReturnType<typeof createReaderConsentService>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic host binding for persistent reader consent
|
|
3
|
+
* (design-merged §4.1, §4.3). Thin host binding over the generic
|
|
4
|
+
* ArtifactReaderStore, scoped to one storage scope per service instance: the
|
|
5
|
+
* reader revokes only their own consents resolved from the verified session
|
|
6
|
+
* (never a body field); a platform admin may revoke any reader's consent
|
|
7
|
+
* (incident response, never grant); the artifact owner cannot revoke consent
|
|
8
|
+
* — the owner's instrument is share revocation. Revoking for an unreadable
|
|
9
|
+
* artifact reads `not_found`, never 403, so the existence oracle stays closed.
|
|
10
|
+
*/
|
|
11
|
+
import { assertConsentScopeId, decideGateB } from './consent.js';
|
|
12
|
+
export { consentScreenPath, renderConsentScreen } from './consent-screen.js';
|
|
13
|
+
export function readerConsentRequired(scopeId) {
|
|
14
|
+
return { code: 'reader_consent_required', scopeId, retryable: false };
|
|
15
|
+
}
|
|
16
|
+
const denied = (code) => new Error(code);
|
|
17
|
+
export function createReaderConsentService(deps) {
|
|
18
|
+
const now = deps.now ?? (() => new Date().toISOString());
|
|
19
|
+
const key = (input) => ({ storageScopeId: deps.storageScopeId,
|
|
20
|
+
readerAccountId: input.readerAccountId, artifactId: input.artifactId,
|
|
21
|
+
...(input.scopeId === undefined ? {} : { scopeId: input.scopeId }) });
|
|
22
|
+
return {
|
|
23
|
+
/**
|
|
24
|
+
* First-party grant with a locked fresh-rights re-check: the host's
|
|
25
|
+
* checkRights (immo getRights) runs immediately before the store write,
|
|
26
|
+
* under the host's own authority discipline.
|
|
27
|
+
*/
|
|
28
|
+
async grantWithFreshRights(input, checkRights) {
|
|
29
|
+
assertConsentScopeId(input.scopeId);
|
|
30
|
+
if (!await checkRights())
|
|
31
|
+
throw denied('access_denied');
|
|
32
|
+
return deps.store.grantConsent({ storageScopeId: deps.storageScopeId, ...input,
|
|
33
|
+
consentId: crypto.randomUUID(), grantedAt: now(), grantedVia: 'reader_screen' });
|
|
34
|
+
},
|
|
35
|
+
/**
|
|
36
|
+
* J1.3b — fresh-rights probe for the first-party grant route: the same
|
|
37
|
+
* readability check the service was built with, so the grant route never
|
|
38
|
+
* invents its own authority rule.
|
|
39
|
+
*/
|
|
40
|
+
async checkReaderFreshRights(input) {
|
|
41
|
+
return deps.canReadArtifact(input.artifactId, input.readerAccountId);
|
|
42
|
+
},
|
|
43
|
+
/**
|
|
44
|
+
* J1.3b — Gate B for the generic reader gate route: live consent at the
|
|
45
|
+
* host-declared version plus fresh rights, evaluated on this call.
|
|
46
|
+
*/
|
|
47
|
+
async evaluateGate(input) {
|
|
48
|
+
assertConsentScopeId(input.scopeId);
|
|
49
|
+
const consent = await deps.store.findLiveConsent({ storageScopeId: deps.storageScopeId,
|
|
50
|
+
readerAccountId: input.readerAccountId, artifactId: input.artifactId,
|
|
51
|
+
scopeId: input.scopeId, scopeVersion: input.scopeVersion });
|
|
52
|
+
return decideGateB({ consent, currentScopeVersion: input.scopeVersion,
|
|
53
|
+
rights: input.rights, scopeId: input.scopeId });
|
|
54
|
+
},
|
|
55
|
+
async listOwnConsents(readerAccountId) {
|
|
56
|
+
const rows = await deps.store.listConsentsForReader(deps.storageScopeId, readerAccountId);
|
|
57
|
+
const live = rows.filter((row) => row.revokedAt === undefined);
|
|
58
|
+
return Promise.all(live.map(async (row) => ({ artifactId: row.artifactId,
|
|
59
|
+
title: await deps.resolveTitle?.(row.artifactId) ?? row.artifactId,
|
|
60
|
+
scopeId: row.scopeId, scopeVersion: row.scopeVersion, grantedAt: row.grantedAt })));
|
|
61
|
+
},
|
|
62
|
+
async revokeOwnConsent(input) {
|
|
63
|
+
if (input.scopeId !== undefined)
|
|
64
|
+
assertConsentScopeId(input.scopeId);
|
|
65
|
+
if (!await deps.canReadArtifact(input.artifactId, input.readerAccountId))
|
|
66
|
+
throw denied('not_found');
|
|
67
|
+
const result = await deps.store.revokeAllConsents(key(input), 'self', now(), { actor: input.readerAccountId, surface: 'api' });
|
|
68
|
+
return { changed: result.changed, revokedAt: result.changed ? now() : null };
|
|
69
|
+
},
|
|
70
|
+
async revokeAllOwnConsents(input) {
|
|
71
|
+
if (!await deps.canReadArtifact(input.artifactId, input.readerAccountId))
|
|
72
|
+
throw denied('not_found');
|
|
73
|
+
const result = await deps.store.revokeAllConsents(key(input), 'self', now(), { actor: input.readerAccountId, surface: 'api' });
|
|
74
|
+
return { changed: result.changed, revoked: result.revoked };
|
|
75
|
+
},
|
|
76
|
+
/**
|
|
77
|
+
* Platform-admin incident revocation. The admin never grants (reduce-only,
|
|
78
|
+
* mirroring canManageAccess); the artifact owner is refused here.
|
|
79
|
+
*/
|
|
80
|
+
async adminRevokeConsent(input, adminAccountId) {
|
|
81
|
+
if (input.scopeId !== undefined)
|
|
82
|
+
assertConsentScopeId(input.scopeId);
|
|
83
|
+
if (!await deps.isAdmin(adminAccountId))
|
|
84
|
+
throw denied('access_denied');
|
|
85
|
+
const result = await deps.store.revokeAllConsents(key(input), 'admin', now(), { actor: adminAccountId, surface: 'api' });
|
|
86
|
+
return { changed: result.changed, revokedAt: result.changed ? now() : null };
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Neutral host-parameterizable reader consent screen (generic grant
|
|
3
|
+
* contract). No tenant strings: brand, title and support URL come from the
|
|
4
|
+
* host declaration. The single prescribed navigation from a typed 403 is
|
|
5
|
+
* `consentScreenPath(artifactId, scopeId, workspaceId)`; the screen posts once to the
|
|
6
|
+
* sibling `grant` route (JSON or form), so a reader without consent reaches
|
|
7
|
+
* it in one click with no loop.
|
|
8
|
+
*/
|
|
9
|
+
export interface ConsentScreenParams {
|
|
10
|
+
brand: string;
|
|
11
|
+
title: string;
|
|
12
|
+
supportUrl?: string;
|
|
13
|
+
artifactId: string;
|
|
14
|
+
scopeId: string;
|
|
15
|
+
scopeVersion: string;
|
|
16
|
+
workspaceId: string;
|
|
17
|
+
}
|
|
18
|
+
/** Single prescribed navigation from the typed 403 `{ code, scopeId, retryable: false }`. */
|
|
19
|
+
export declare function consentScreenPath(artifactId: string, scopeId: string, workspaceId: string): string;
|
|
20
|
+
/** Neutral consent screen HTML; posts once to the sibling `grant` route. */
|
|
21
|
+
export declare function renderConsentScreen(params: ConsentScreenParams): string;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Neutral host-parameterizable reader consent screen (generic grant
|
|
3
|
+
* contract). No tenant strings: brand, title and support URL come from the
|
|
4
|
+
* host declaration. The single prescribed navigation from a typed 403 is
|
|
5
|
+
* `consentScreenPath(artifactId, scopeId, workspaceId)`; the screen posts once to the
|
|
6
|
+
* sibling `grant` route (JSON or form), so a reader without consent reaches
|
|
7
|
+
* it in one click with no loop.
|
|
8
|
+
*/
|
|
9
|
+
/** Single prescribed navigation from the typed 403 `{ code, scopeId, retryable: false }`. */
|
|
10
|
+
export function consentScreenPath(artifactId, scopeId, workspaceId) {
|
|
11
|
+
return `reader-consents/screen?artifactId=${encodeURIComponent(artifactId)}&scopeId=${encodeURIComponent(scopeId)}&workspace_id=${encodeURIComponent(workspaceId)}`;
|
|
12
|
+
}
|
|
13
|
+
function esc(value) {
|
|
14
|
+
return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
15
|
+
.replace(/"/g, '"');
|
|
16
|
+
}
|
|
17
|
+
/** Neutral consent screen HTML; posts once to the sibling `grant` route. */
|
|
18
|
+
export function renderConsentScreen(params) {
|
|
19
|
+
const brand = esc(params.brand);
|
|
20
|
+
const title = esc(params.title);
|
|
21
|
+
const artifactId = esc(params.artifactId);
|
|
22
|
+
const scopeId = esc(params.scopeId);
|
|
23
|
+
const scopeVersion = esc(params.scopeVersion);
|
|
24
|
+
const action = `grant?workspace_id=${encodeURIComponent(params.workspaceId)}`;
|
|
25
|
+
const support = params.supportUrl === undefined ? '' :
|
|
26
|
+
`<p><a href="${esc(params.supportUrl)}">Support</a></p>`;
|
|
27
|
+
return `<!doctype html>
|
|
28
|
+
<html lang="en">
|
|
29
|
+
<head>
|
|
30
|
+
<meta charset="utf-8">
|
|
31
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
32
|
+
<title>${title} - ${brand}</title>
|
|
33
|
+
</head>
|
|
34
|
+
<body>
|
|
35
|
+
<main>
|
|
36
|
+
<h1>${title}</h1>
|
|
37
|
+
<p>${brand} requests access to artifact <code>${artifactId}</code>.</p>
|
|
38
|
+
<dl>
|
|
39
|
+
<dt>Scope</dt><dd>${scopeId}</dd>
|
|
40
|
+
<dt>Version</dt><dd>${scopeVersion}</dd>
|
|
41
|
+
</dl>
|
|
42
|
+
<form method="post" action="${esc(action)}">
|
|
43
|
+
<input type="hidden" name="artifactId" value="${artifactId}">
|
|
44
|
+
<input type="hidden" name="scopeId" value="${scopeId}">
|
|
45
|
+
<input type="hidden" name="scopeVersion" value="${scopeVersion}">
|
|
46
|
+
<button type="submit">Allow access</button>
|
|
47
|
+
</form>
|
|
48
|
+
${support}
|
|
49
|
+
</main>
|
|
50
|
+
</body>
|
|
51
|
+
</html>`;
|
|
52
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { type LiveErrorCode } from './live-errors.js';
|
|
1
2
|
/** Trusted server failures (r2 E1–E3). No driver text participates in classification. */
|
|
2
3
|
export type ArtifactCommitState = 'not_committed' | 'committed' | 'unknown';
|
|
3
4
|
/** Structurally identical to L0's server-derived SHA-256 internal key, never a caller key. */
|
|
4
5
|
export type ArtifactInternalKey = string & {
|
|
5
6
|
readonly __brand: 'internal-key';
|
|
6
7
|
};
|
|
7
|
-
export type ArtifactErrorKind = 'provider_unavailable' | 'command_conflict' | 'pointer_conflict' | 'unauthorized_at_commit' | 'capability_unselected' | 'admission_unavailable' | 'invalid_request' | 'anonymous' | 'access_denied' | 'not_found' | 'gone' | 'release_unavailable' | 'limit_exceeded' | 'unprocessable' | 'verification_failed' | 'edit_mismatch' | 'precondition_required';
|
|
8
|
+
export type ArtifactErrorKind = LiveErrorCode | 'provider_unavailable' | 'command_conflict' | 'pointer_conflict' | 'unauthorized_at_commit' | 'capability_unselected' | 'admission_unavailable' | 'invalid_request' | 'anonymous' | 'access_denied' | 'not_found' | 'gone' | 'release_unavailable' | 'limit_exceeded' | 'unprocessable' | 'verification_failed' | 'edit_mismatch' | 'precondition_required' | 'git_binding_conflict' | 'git_repo_not_registered' | 'git_ref_not_allowed' | 'git_head_moved' | 'git_path_refused' | 'git_branch_missing' | 'build_descriptor_invalid' | 'build_script_missing' | 'lock_missing' | 'dep_outside_lock' | 'install_script_not_allowlisted';
|
|
8
9
|
/** Optimistic-concurrency payload: the caller re-reads and merges against this. */
|
|
9
10
|
export interface ArtifactConflictDetails {
|
|
10
11
|
readonly artifactId?: string;
|
|
@@ -48,7 +49,7 @@ export interface ArtifactOperationalFailure extends ArtifactFailureFields {
|
|
|
48
49
|
}
|
|
49
50
|
export interface ArtifactOrdinaryFailure extends Omit<ArtifactFailureFields, 'variant' | 'retriable'> {
|
|
50
51
|
readonly kind: 'ordinary';
|
|
51
|
-
readonly category: 'invalid_request' | 'not_found' | 'gone' | 'release_unavailable' | 'limit_exceeded' | 'unprocessable' | 'verification_failed' | 'edit_mismatch' | 'precondition_required';
|
|
52
|
+
readonly category: 'invalid_request' | 'not_found' | 'gone' | 'release_unavailable' | 'limit_exceeded' | LiveErrorCode | 'unprocessable' | 'verification_failed' | 'edit_mismatch' | 'precondition_required' | 'build_descriptor_invalid' | 'build_script_missing' | 'lock_missing' | 'dep_outside_lock' | 'install_script_not_allowlisted' | 'git_path_refused' | 'git_branch_missing' | 'git_ref_not_allowed' | 'git_repo_not_registered';
|
|
52
53
|
readonly retriable: false;
|
|
53
54
|
}
|
|
54
55
|
/** Entry authority outcomes are separate from ordinary and operational failures. */
|
package/dist/server/failures.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LIVE_FAILURE_STATUS } from './live-errors.js';
|
|
1
2
|
export class ArtifactOperationError extends Error {
|
|
2
3
|
kind;
|
|
3
4
|
details;
|
|
@@ -30,6 +31,9 @@ const DOMAIN_STATUS = {
|
|
|
30
31
|
invalid_request: 400, anonymous: 401, access_denied: 403,
|
|
31
32
|
not_found: 404, gone: 410, release_unavailable: 410, limit_exceeded: 413, unprocessable: 422, verification_failed: 422, edit_mismatch: 422,
|
|
32
33
|
precondition_required: 428,
|
|
34
|
+
build_descriptor_invalid: 422, build_script_missing: 422, lock_missing: 422,
|
|
35
|
+
dep_outside_lock: 422, install_script_not_allowlisted: 422,
|
|
36
|
+
git_path_refused: 422, git_branch_missing: 422, git_ref_not_allowed: 422, git_repo_not_registered: 422,
|
|
33
37
|
};
|
|
34
38
|
function field(value, name) {
|
|
35
39
|
if (typeof value !== 'object' || value === null)
|
|
@@ -61,9 +65,31 @@ const conflict = (variant = 'key_contention') => ({ kind: 'operational', categor
|
|
|
61
65
|
const internal = () => ({ kind: 'operational', category: 'provider_error', variant: 'unclassified', httpStatus: 500, publicCode: 'internal_error', retriable: false });
|
|
62
66
|
function operationProjection(error) {
|
|
63
67
|
const { kind } = error;
|
|
68
|
+
if (Object.hasOwn(LIVE_FAILURE_STATUS, kind)) {
|
|
69
|
+
const status = LIVE_FAILURE_STATUS[kind];
|
|
70
|
+
const details = error.details.publicDetails;
|
|
71
|
+
if (kind === 'git_live_conflict' && !['invalid_phase', 'active_session', 'pending_publication',
|
|
72
|
+
'commit_indeterminate', 'stale_session', 'stale_fence', 'transition_busy'].includes(String(details?.reason)))
|
|
73
|
+
return internal();
|
|
74
|
+
if (status === 409)
|
|
75
|
+
return { ...conflict(kind), publicCode: kind, details };
|
|
76
|
+
if (status === 503)
|
|
77
|
+
return { kind: 'operational', category: 'provider_unavailable',
|
|
78
|
+
httpStatus: status, publicCode: kind, retriable: true, details };
|
|
79
|
+
return { kind: 'ordinary', category: kind, httpStatus: status,
|
|
80
|
+
publicCode: kind, retriable: false, details };
|
|
81
|
+
}
|
|
64
82
|
switch (kind) {
|
|
83
|
+
case 'git_head_moved': return { ...conflict(kind), publicCode: kind, details: error.details.publicDetails };
|
|
84
|
+
case 'git_path_refused':
|
|
85
|
+
case 'git_branch_missing':
|
|
86
|
+
case 'git_ref_not_allowed':
|
|
87
|
+
case 'git_repo_not_registered':
|
|
88
|
+
return { kind: 'ordinary', category: kind, httpStatus: DOMAIN_STATUS[kind], publicCode: kind,
|
|
89
|
+
retriable: false, details: error.details.publicDetails };
|
|
65
90
|
case 'provider_unavailable':
|
|
66
91
|
case 'admission_unavailable': return unavailable(kind);
|
|
92
|
+
case 'git_binding_conflict': return { ...conflict(kind), publicCode: kind, details: error.details.publicDetails };
|
|
67
93
|
case 'command_conflict':
|
|
68
94
|
case 'pointer_conflict': {
|
|
69
95
|
const base = conflict(kind);
|
|
@@ -94,6 +120,10 @@ function operationProjection(error) {
|
|
|
94
120
|
const base = { kind: 'ordinary', category: kind, httpStatus: DOMAIN_STATUS[kind], publicCode: kind, retriable: false };
|
|
95
121
|
if (kind === 'precondition_required')
|
|
96
122
|
return { ...base, details: error.details.publicDetails };
|
|
123
|
+
if (kind === 'limit_exceeded' && error.details.publicDetails?.quota === 'git_write' &&
|
|
124
|
+
['principal', 'artifact'].includes(String(error.details.publicDetails.scope)))
|
|
125
|
+
return { ...base,
|
|
126
|
+
details: { quota: 'git_write', scope: error.details.publicDetails.scope } };
|
|
97
127
|
if (kind === 'release_unavailable' && error.details.release !== undefined)
|
|
98
128
|
return { ...base, release: error.details.release };
|
|
99
129
|
return kind === 'edit_mismatch' && error.details.edit !== undefined ? { ...base, edit: error.details.edit } : base;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { GitAttachIntent, GitBinding, GitBindingEvent, GitBindingStore, GitBindingWrite } from './git-contracts.js';
|
|
2
|
+
export type * from './git-contracts.js';
|
|
3
|
+
export declare function gitBindingReceiptKey(input: GitBindingWrite): string;
|
|
4
|
+
/** Shared invariants run inside the adapter transaction, after receipt replay and before mutation. */
|
|
5
|
+
export declare function validateGitBindingWrite(before: GitBinding | undefined, input: GitBindingWrite): void;
|
|
6
|
+
export declare function gitBindingEvent(input: GitBindingWrite): GitBindingEvent;
|
|
7
|
+
/** Shared attach-intent admission for every adapter, before the put-if-absent. */
|
|
8
|
+
export declare function validateGitAttachIntent(intent: GitAttachIntent): void;
|
|
9
|
+
/** Atomic single-process fake tenant. Outputs never expose mutable internal records. */
|
|
10
|
+
export declare function createMemoryGitBindingStore(): GitBindingStore;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { ArtifactOperationError } from './failures.js';
|
|
3
|
+
import { createKeyMutex } from './ports.js';
|
|
4
|
+
import { isAllowedGitBranch } from './git-registry.js';
|
|
5
|
+
import { isGitSha } from './git-port-policy.js';
|
|
6
|
+
export function gitBindingReceiptKey(input) {
|
|
7
|
+
return 'git-binding:' + createHash('sha256').update(JSON.stringify([
|
|
8
|
+
input.binding.storageScopeId, input.actorId, input.idempotencyKey,
|
|
9
|
+
])).digest('hex');
|
|
10
|
+
}
|
|
11
|
+
/** Shared invariants run inside the adapter transaction, after receipt replay and before mutation. */
|
|
12
|
+
export function validateGitBindingWrite(before, input) {
|
|
13
|
+
const next = input.binding;
|
|
14
|
+
if (!isAllowedGitBranch(next.branch))
|
|
15
|
+
throw new ArtifactOperationError('git_ref_not_allowed');
|
|
16
|
+
if (!input.idempotencyKey.trim() || !input.commandHash || !input.actorId || !next.storageScopeId ||
|
|
17
|
+
!next.repoId || next.live !== undefined ||
|
|
18
|
+
!Number.isSafeInteger(next.version) || !Number.isSafeInteger(next.generation) ||
|
|
19
|
+
next.version < 1 || next.generation < 1 ||
|
|
20
|
+
(next.pendingJobId === null) !== (next.pendingCommitSha === null) ||
|
|
21
|
+
(next.channel === 'shared' ? next.personalPrincipalId !== null : !next.personalPrincipalId)) {
|
|
22
|
+
throw new ArtifactOperationError('invalid_request');
|
|
23
|
+
}
|
|
24
|
+
if (before && before.storageScopeId !== next.storageScopeId)
|
|
25
|
+
throw new ArtifactOperationError('not_found');
|
|
26
|
+
if (input.expectedVersion === null && before)
|
|
27
|
+
throw new ArtifactOperationError('git_binding_conflict', { publicDetails: { artifactId: next.artifactId } });
|
|
28
|
+
if (input.expectedVersion !== (before?.version ?? null))
|
|
29
|
+
throw new ArtifactOperationError('pointer_conflict');
|
|
30
|
+
if (next.version !== (before?.version ?? 0) + 1)
|
|
31
|
+
throw new ArtifactOperationError('invalid_request');
|
|
32
|
+
if (before && before.state !== 'detached' && (next.repoId !== before.repoId || next.branch !== before.branch ||
|
|
33
|
+
next.subPath !== before.subPath))
|
|
34
|
+
throw new ArtifactOperationError('git_binding_conflict', { publicDetails: { artifactId: next.artifactId } });
|
|
35
|
+
const action = input.event.action;
|
|
36
|
+
const active = before !== undefined && before.state !== 'detached';
|
|
37
|
+
const configuring = action === 'attach' && active;
|
|
38
|
+
if (input.event.branchCreated !== undefined && (input.event.branchCreated !== true || action !== 'attach' || active)) {
|
|
39
|
+
throw new ArtifactOperationError('invalid_request');
|
|
40
|
+
}
|
|
41
|
+
const transition = action === 'attach' ? (configuring ? next.state === before.state : next.state === 'attached')
|
|
42
|
+
: action === 'pause' ? active && next.state === 'paused'
|
|
43
|
+
: action === 'resume' ? before?.state === 'paused' && next.state === 'attached' &&
|
|
44
|
+
!['git_branch_missing', 'git_diverged'].includes(before.stateDetail ?? '')
|
|
45
|
+
: action === 'detach' ? before !== undefined && next.state === 'detached'
|
|
46
|
+
: action === 'commit' ? before?.state === 'attached' && ['attached', 'build_pending', 'syncing'].includes(next.state)
|
|
47
|
+
: action === 'inbound' ? (before?.state === 'attached' && ['syncing', 'build_pending'].includes(next.state)) ||
|
|
48
|
+
(before?.state === 'syncing' && ['attached', 'build_pending', 'diverged'].includes(next.state)) ||
|
|
49
|
+
(before?.state === 'build_failed' && next.state === 'build_pending') ||
|
|
50
|
+
(active && next.stateDetail === 'git_branch_missing' && next.state === (before.state === 'paused' ? 'paused' : 'diverged'))
|
|
51
|
+
: action === 'publish' ? before !== undefined && (['attached', 'build_failed'].includes(before.state)
|
|
52
|
+
? next.state === 'build_pending' : before.state === 'build_pending' && ['attached', 'build_failed'].includes(next.state))
|
|
53
|
+
: action === 'conflict' ? active && ['diverged', 'paused'].includes(next.state)
|
|
54
|
+
: action === 'resolve' ? before?.state === 'diverged' && next.state === 'build_pending'
|
|
55
|
+
: action === 'error' && active && next.state === 'error';
|
|
56
|
+
if (!transition)
|
|
57
|
+
throw new ArtifactOperationError('invalid_request');
|
|
58
|
+
const advance = before && ((action === 'attach' && before.state === 'detached') ||
|
|
59
|
+
['detach', 'pause'].includes(action) || (action === 'inbound' && next.stateDetail === 'git_branch_missing'));
|
|
60
|
+
if (next.generation !== (before ? before.generation + (advance ? 1 : 0) : 1) ||
|
|
61
|
+
(advance && (next.pendingJobId !== null || next.pendingCommitSha !== null)) ||
|
|
62
|
+
(before && action !== 'publish' && next.releaseCommitSha !== before.releaseCommitSha)) {
|
|
63
|
+
throw new ArtifactOperationError('invalid_request');
|
|
64
|
+
}
|
|
65
|
+
const fenced = before && (before.state === 'diverged' || ['git_branch_missing', 'git_diverged'].includes(before.stateDetail ?? ''));
|
|
66
|
+
if ((action === 'pause' && fenced && next.stateDetail !== (before.stateDetail ?? 'git_diverged')) ||
|
|
67
|
+
(configuring && (next.headCommitSha !== before.headCommitSha || next.stateDetail !== before.stateDetail ||
|
|
68
|
+
next.baseCommitSha !== before.baseCommitSha || next.channel !== before.channel ||
|
|
69
|
+
next.personalPrincipalId !== before.personalPrincipalId || next.attachedBy !== before.attachedBy ||
|
|
70
|
+
next.attachedAt !== before.attachedAt))) {
|
|
71
|
+
throw new ArtifactOperationError('invalid_request');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export function gitBindingEvent(input) {
|
|
75
|
+
return { id: randomUUID(), artifactId: input.binding.artifactId, storageScopeId: input.binding.storageScopeId,
|
|
76
|
+
actorId: input.actorId, action: input.event.action, beforeSha: input.event.beforeSha,
|
|
77
|
+
afterSha: input.event.afterSha, deliveryId: input.event.deliveryId,
|
|
78
|
+
invocationId: input.event.invocationId, ...(input.event.branchCreated ? { branchCreated: true } : {}),
|
|
79
|
+
createdAt: input.binding.updatedAt };
|
|
80
|
+
}
|
|
81
|
+
/** Shared attach-intent admission for every adapter, before the put-if-absent. */
|
|
82
|
+
export function validateGitAttachIntent(intent) {
|
|
83
|
+
if (!isAllowedGitBranch(intent.branch) || !intent.idempotencyKey.trim() || !intent.commandHash || !intent.actorId ||
|
|
84
|
+
!intent.storageScopeId || !intent.artifactId || !intent.repoId || !isGitSha(intent.baseCommitSha)) {
|
|
85
|
+
throw new ArtifactOperationError('invalid_request');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const intentKey = (scope, actorId, key) => JSON.stringify([scope, actorId, key]);
|
|
89
|
+
/** Atomic single-process fake tenant. Outputs never expose mutable internal records. */
|
|
90
|
+
export function createMemoryGitBindingStore() {
|
|
91
|
+
const rows = new Map();
|
|
92
|
+
const audit = [];
|
|
93
|
+
const receipts = new Map();
|
|
94
|
+
const intents = new Map();
|
|
95
|
+
const mutex = createKeyMutex();
|
|
96
|
+
return {
|
|
97
|
+
async get(scope, id) {
|
|
98
|
+
const binding = rows.get(id);
|
|
99
|
+
return binding?.storageScopeId === scope ? structuredClone(binding) : undefined;
|
|
100
|
+
},
|
|
101
|
+
async events(scope, id) {
|
|
102
|
+
return structuredClone(audit.filter(event => event.storageScopeId === scope && event.artifactId === id));
|
|
103
|
+
},
|
|
104
|
+
async reserveAttachIntent(intent) {
|
|
105
|
+
validateGitAttachIntent(intent);
|
|
106
|
+
const key = intentKey(intent.storageScopeId, intent.actorId, intent.idempotencyKey);
|
|
107
|
+
if (!intents.has(key))
|
|
108
|
+
intents.set(key, structuredClone(intent));
|
|
109
|
+
return structuredClone(intents.get(key));
|
|
110
|
+
},
|
|
111
|
+
async attachIntent(scope, actorId, idempotencyKey) {
|
|
112
|
+
const intent = intents.get(intentKey(scope, actorId, idempotencyKey));
|
|
113
|
+
return intent && structuredClone(intent);
|
|
114
|
+
},
|
|
115
|
+
async write(input) {
|
|
116
|
+
const snapshot = structuredClone(input);
|
|
117
|
+
return mutex.runSerialized('git-bindings', async () => {
|
|
118
|
+
const key = gitBindingReceiptKey(snapshot);
|
|
119
|
+
const receipt = receipts.get(key);
|
|
120
|
+
if (receipt) {
|
|
121
|
+
if (receipt.hash !== snapshot.commandHash)
|
|
122
|
+
throw new ArtifactOperationError('command_conflict');
|
|
123
|
+
return { binding: structuredClone(receipt.binding), replayed: true };
|
|
124
|
+
}
|
|
125
|
+
const binding = snapshot.binding;
|
|
126
|
+
validateGitBindingWrite(rows.get(binding.artifactId), snapshot);
|
|
127
|
+
if (binding.state !== 'detached' && [...rows.values()].some(row => row.artifactId !== binding.artifactId &&
|
|
128
|
+
row.state !== 'detached' && row.repoId === binding.repoId && row.branch === binding.branch)) {
|
|
129
|
+
throw new ArtifactOperationError('git_binding_conflict', { publicDetails: { artifactId: binding.artifactId } });
|
|
130
|
+
}
|
|
131
|
+
rows.set(binding.artifactId, binding);
|
|
132
|
+
audit.push(gitBindingEvent(snapshot));
|
|
133
|
+
receipts.set(key, { hash: snapshot.commandHash, binding: structuredClone(binding) });
|
|
134
|
+
return { binding: structuredClone(binding), replayed: false };
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|