@sentropic/artifacts 0.2.9 → 0.2.12
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 +52 -0
- package/dist/adapters/postgres-management.js +31 -8
- package/dist/adapters/postgres.js +16 -5
- package/dist/content/handler.d.ts +6 -1
- package/dist/content/handler.js +7 -2
- package/dist/http.d.ts +5 -1
- package/dist/http.js +52 -8
- package/dist/mcp-core.d.ts +1 -1
- package/dist/mcp-core.js +1 -1
- package/dist/profile/contracts.d.ts +2 -0
- package/dist/profile/index.js +3 -1
- package/dist/server/access.d.ts +70 -10
- package/dist/server/access.js +91 -8
- package/dist/server/lifecycle.d.ts +2 -2
- package/dist/server/lifecycle.js +2 -2
- package/dist/server/management.d.ts +17 -5
- package/dist/server/management.js +51 -11
- package/dist/server/ports.d.ts +27 -0
- package/dist/server/ports.js +28 -0
- package/dist/server/publication.d.ts +35 -0
- package/dist/server/publication.js +88 -11
- package/dist/server/runtime.d.ts +7 -1
- package/dist/server/runtime.js +2 -1
- package/dist/server/summary.d.ts +2 -1
- package/dist/server/summary.js +2 -2
- package/migrations/0006_sharing.sql +107 -0
- package/package.json +1 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
-- G1 — three-mode sharing ACL (converged-r2 §2.1/§2.2 + owner answers Q1–Q3).
|
|
2
|
+
--
|
|
3
|
+
-- Additive upgrade over 0005: no column is dropped or narrowed, existing rows
|
|
4
|
+
-- keep working. `access_mode` closes the wide audience to the three values;
|
|
5
|
+
-- legacy `is_public = true` maps to 'platform', NEVER 'public' (zero artifacts
|
|
6
|
+
-- become anonymous through the migration). `is_public` stays as a read-only
|
|
7
|
+
-- legacy projection of `access_mode` (`<> 'restricted'`); the adapter writes
|
|
8
|
+
-- both together and the forced `is_public = false` writes are removed in code.
|
|
9
|
+
-- `artifact_access_events` is the append-only audit trail written in the same
|
|
10
|
+
-- transaction as the mutation (actor, action, audience, target principal,
|
|
11
|
+
-- policy revision, timestamp — no tokens, no names).
|
|
12
|
+
-- Owner Q1 is enforced at the schema level: the collab (`source`) right is
|
|
13
|
+
-- nominative only — at most one source grant per artifact, only while the
|
|
14
|
+
-- artifact is `restricted`, and no mode widening while a source grant exists.
|
|
15
|
+
-- Legacy 0002 data may hold several `source` grants on one artifact (direct
|
|
16
|
+
-- writes; MCP could only create `read`): they are deduped deterministically
|
|
17
|
+
-- BEFORE the unique index exists — the oldest source grant per artifact
|
|
18
|
+
-- (created_at, tie-break principal_id) stays `source`, every later duplicate
|
|
19
|
+
-- is demoted to `read`. No grant row is ever deleted (every grantee keeps at
|
|
20
|
+
-- least read access) and the outcome never depends on physical row order.
|
|
21
|
+
|
|
22
|
+
ALTER TABLE artifacts.artifacts
|
|
23
|
+
ADD COLUMN IF NOT EXISTS access_mode TEXT NOT NULL DEFAULT 'restricted'
|
|
24
|
+
CHECK (access_mode IN ('restricted', 'platform', 'public'));
|
|
25
|
+
|
|
26
|
+
-- Legacy public flag reads as platform, never public.
|
|
27
|
+
UPDATE artifacts.artifacts SET access_mode = 'platform' WHERE is_public = true;
|
|
28
|
+
|
|
29
|
+
-- Append-only access audit events (same transaction as the mutation).
|
|
30
|
+
CREATE TABLE IF NOT EXISTS artifacts.artifact_access_events (
|
|
31
|
+
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
32
|
+
artifact_id UUID NOT NULL REFERENCES artifacts.artifacts (id) ON DELETE CASCADE,
|
|
33
|
+
actor_id TEXT NOT NULL,
|
|
34
|
+
action TEXT NOT NULL CHECK (action IN ('grant', 'revoke')),
|
|
35
|
+
audience TEXT NOT NULL CHECK (audience IN ('user', 'platform', 'public')),
|
|
36
|
+
principal_id TEXT,
|
|
37
|
+
policy_revision TEXT NOT NULL,
|
|
38
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
39
|
+
);
|
|
40
|
+
CREATE INDEX IF NOT EXISTS access_events_by_artifact ON artifacts.artifact_access_events (artifact_id);
|
|
41
|
+
|
|
42
|
+
CREATE OR REPLACE FUNCTION artifacts.reject_access_event_mutation() RETURNS trigger AS $$
|
|
43
|
+
BEGIN
|
|
44
|
+
RAISE EXCEPTION 'append-only: artifact_access_events is immutable';
|
|
45
|
+
END;
|
|
46
|
+
$$ LANGUAGE plpgsql;
|
|
47
|
+
|
|
48
|
+
DROP TRIGGER IF EXISTS artifact_access_events_append_only ON artifacts.artifact_access_events;
|
|
49
|
+
CREATE TRIGGER artifact_access_events_append_only
|
|
50
|
+
BEFORE UPDATE OR DELETE OR TRUNCATE ON artifacts.artifact_access_events
|
|
51
|
+
FOR EACH STATEMENT EXECUTE FUNCTION artifacts.reject_access_event_mutation();
|
|
52
|
+
|
|
53
|
+
-- Deterministic dedupe of legacy multi-source artifacts (see header): the
|
|
54
|
+
-- oldest `source` grant per artifact stays `source`; later duplicates demote
|
|
55
|
+
-- to `read`. No row is deleted; ties on created_at break on principal_id.
|
|
56
|
+
UPDATE artifacts.artifact_access AS dup
|
|
57
|
+
SET permission = 'read'
|
|
58
|
+
WHERE dup.permission = 'source'
|
|
59
|
+
AND EXISTS (
|
|
60
|
+
SELECT 1
|
|
61
|
+
FROM artifacts.artifact_access AS keep
|
|
62
|
+
WHERE keep.artifact_id = dup.artifact_id
|
|
63
|
+
AND keep.permission = 'source'
|
|
64
|
+
AND (keep.created_at, keep.principal_id) < (dup.created_at, dup.principal_id)
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
-- Owner Q1, schema level: at most one collab (source) grant per artifact.
|
|
68
|
+
CREATE UNIQUE INDEX IF NOT EXISTS artifact_access_one_source
|
|
69
|
+
ON artifacts.artifact_access (artifact_id) WHERE permission = 'source';
|
|
70
|
+
|
|
71
|
+
CREATE OR REPLACE FUNCTION artifacts.reject_source_outside_restricted() RETURNS trigger AS $$
|
|
72
|
+
DECLARE
|
|
73
|
+
current_mode TEXT;
|
|
74
|
+
BEGIN
|
|
75
|
+
IF NEW.permission = 'source' THEN
|
|
76
|
+
SELECT access_mode INTO current_mode FROM artifacts.artifacts WHERE id = NEW.artifact_id;
|
|
77
|
+
IF current_mode IS DISTINCT FROM 'restricted' THEN
|
|
78
|
+
RAISE EXCEPTION 'source grant requires restricted mode (artifact % is %)', NEW.artifact_id, current_mode;
|
|
79
|
+
END IF;
|
|
80
|
+
END IF;
|
|
81
|
+
RETURN NEW;
|
|
82
|
+
END;
|
|
83
|
+
$$ LANGUAGE plpgsql;
|
|
84
|
+
|
|
85
|
+
DROP TRIGGER IF EXISTS artifact_access_source_guard ON artifacts.artifact_access;
|
|
86
|
+
CREATE TRIGGER artifact_access_source_guard
|
|
87
|
+
BEFORE INSERT OR UPDATE OF permission ON artifacts.artifact_access
|
|
88
|
+
FOR EACH ROW EXECUTE FUNCTION artifacts.reject_source_outside_restricted();
|
|
89
|
+
|
|
90
|
+
-- Owner Q1, schema level: no mode widening while a collab (source) grant exists.
|
|
91
|
+
CREATE OR REPLACE FUNCTION artifacts.reject_widening_with_source_grant() RETURNS trigger AS $$
|
|
92
|
+
BEGIN
|
|
93
|
+
IF (OLD.access_mode = 'restricted' AND NEW.access_mode IN ('platform', 'public'))
|
|
94
|
+
OR (OLD.access_mode = 'platform' AND NEW.access_mode = 'public') THEN
|
|
95
|
+
IF EXISTS (SELECT 1 FROM artifacts.artifact_access
|
|
96
|
+
WHERE artifact_id = NEW.id AND permission = 'source') THEN
|
|
97
|
+
RAISE EXCEPTION 'cannot widen access_mode of artifact % while a source grant exists', NEW.id;
|
|
98
|
+
END IF;
|
|
99
|
+
END IF;
|
|
100
|
+
RETURN NEW;
|
|
101
|
+
END;
|
|
102
|
+
$$ LANGUAGE plpgsql;
|
|
103
|
+
|
|
104
|
+
DROP TRIGGER IF EXISTS artifacts_widening_source_guard ON artifacts.artifacts;
|
|
105
|
+
CREATE TRIGGER artifacts_widening_source_guard
|
|
106
|
+
BEFORE UPDATE OF access_mode ON artifacts.artifacts
|
|
107
|
+
FOR EACH ROW EXECUTE FUNCTION artifacts.reject_widening_with_source_grant();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentropic/artifacts",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.12",
|
|
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",
|