@sentropic/artifacts 0.2.12 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +93 -0
- package/README.md +45 -10
- package/dist/adapters/local-blob.d.ts +3 -0
- package/dist/adapters/local-blob.js +93 -0
- package/dist/adapters/postgres-management.js +3 -2
- package/dist/adapters/postgres-reader-consent.d.ts +11 -0
- package/dist/adapters/postgres-reader-consent.js +109 -0
- package/dist/adapters/postgres-uploads.d.ts +14 -0
- package/dist/adapters/postgres-uploads.js +174 -0
- package/dist/adapters/postgres.js +4 -3
- package/dist/adapters/s3-uploads.d.ts +33 -0
- package/dist/adapters/s3-uploads.js +105 -0
- package/dist/adapters/s3.js +23 -0
- package/dist/adapters/sqlite-activation.d.ts +20 -0
- package/dist/adapters/sqlite-activation.js +205 -0
- package/dist/adapters/sqlite-commit.d.ts +15 -0
- package/dist/adapters/sqlite-commit.js +89 -0
- package/dist/adapters/sqlite-management.d.ts +10 -0
- package/dist/adapters/sqlite-management.js +60 -0
- package/dist/adapters/sqlite-sql.d.ts +32 -0
- package/dist/adapters/sqlite-sql.js +36 -0
- package/dist/adapters/sqlite-store.d.ts +12 -0
- package/dist/adapters/sqlite-store.js +410 -0
- package/dist/adapters/sqlite.d.ts +33 -0
- package/dist/adapters/sqlite.js +95 -0
- package/dist/content/handler.d.ts +5 -0
- package/dist/content/handler.js +80 -9
- package/dist/content/headers.js +12 -0
- package/dist/http.d.ts +32 -2
- package/dist/http.js +615 -13
- package/dist/mcp-core.d.ts +3 -3
- package/dist/mcp-core.js +90 -4
- package/dist/profile/contracts.d.ts +1 -1
- package/dist/profile/contracts.js +7 -0
- package/dist/profile/index.js +43 -2
- package/dist/profile/radar.js +7 -0
- package/dist/profile/schemas.js +119 -0
- package/dist/profile/validation.d.ts +11 -0
- package/dist/profile/validation.js +98 -6
- package/dist/server/access.d.ts +2 -0
- package/dist/server/command-identity.d.ts +1 -1
- package/dist/server/command-identity.js +6 -3
- package/dist/server/consent.d.ts +65 -0
- package/dist/server/consent.js +42 -0
- package/dist/server/gc.d.ts +42 -0
- package/dist/server/gc.js +98 -0
- package/dist/server/management.d.ts +3 -1
- package/dist/server/management.js +48 -7
- package/dist/server/metrics.d.ts +21 -0
- package/dist/server/metrics.js +6 -0
- package/dist/server/mime.d.ts +26 -2
- package/dist/server/mime.js +124 -2
- package/dist/server/ports.d.ts +29 -0
- package/dist/server/ports.js +11 -0
- package/dist/server/publication-limits.d.ts +20 -0
- package/dist/server/publication-limits.js +27 -1
- package/dist/server/publication.d.ts +14 -0
- package/dist/server/publication.js +10 -2
- package/dist/server/reader-store.d.ts +58 -0
- package/dist/server/reader-store.js +109 -0
- package/dist/server/source-read.d.ts +12 -9
- package/dist/server/source-read.js +17 -5
- package/dist/server/templates.js +50 -2
- package/dist/server/upload-page.d.ts +157 -0
- package/dist/server/upload-page.js +438 -0
- package/dist/server/uploads.d.ts +229 -19
- package/dist/server/uploads.js +387 -80
- package/migrations/0007_uploads.sql +43 -0
- package/migrations/0008_reader_consent.sql +48 -0
- package/migrations/0009_upload_pages.sql +25 -0
- package/package.json +34 -1
- package/sql/reader-consent.sql +47 -0
- package/sql/sqlite/0001_artifacts.sql +156 -0
- package/sql/sqlite/0002_activation.sql +73 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentropic/artifacts",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.14",
|
|
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",
|
|
@@ -33,6 +33,10 @@
|
|
|
33
33
|
"types": "./dist/adapters/s3.d.ts",
|
|
34
34
|
"import": "./dist/adapters/s3.js"
|
|
35
35
|
},
|
|
36
|
+
"./adapters/s3-uploads": {
|
|
37
|
+
"types": "./dist/adapters/s3-uploads.d.ts",
|
|
38
|
+
"import": "./dist/adapters/s3-uploads.js"
|
|
39
|
+
},
|
|
36
40
|
"./adapters/postgres": {
|
|
37
41
|
"types": "./dist/adapters/postgres.d.ts",
|
|
38
42
|
"import": "./dist/adapters/postgres.js"
|
|
@@ -41,6 +45,14 @@
|
|
|
41
45
|
"types": "./dist/adapters/postgres-commit.d.ts",
|
|
42
46
|
"import": "./dist/adapters/postgres-commit.js"
|
|
43
47
|
},
|
|
48
|
+
"./adapters/postgres-reader-consent": {
|
|
49
|
+
"types": "./dist/adapters/postgres-reader-consent.d.ts",
|
|
50
|
+
"import": "./dist/adapters/postgres-reader-consent.js"
|
|
51
|
+
},
|
|
52
|
+
"./adapters/postgres-uploads": {
|
|
53
|
+
"types": "./dist/adapters/postgres-uploads.d.ts",
|
|
54
|
+
"import": "./dist/adapters/postgres-uploads.js"
|
|
55
|
+
},
|
|
44
56
|
"./adapters/postgres-activation": {
|
|
45
57
|
"types": "./dist/adapters/postgres-activation.d.ts",
|
|
46
58
|
"import": "./dist/adapters/postgres-activation.js"
|
|
@@ -49,12 +61,24 @@
|
|
|
49
61
|
"types": "./dist/adapters/postgres-activation-vectors.d.ts",
|
|
50
62
|
"import": "./dist/adapters/postgres-activation-vectors.js"
|
|
51
63
|
},
|
|
64
|
+
"./sqlite": {
|
|
65
|
+
"types": "./dist/adapters/sqlite.d.ts",
|
|
66
|
+
"import": "./dist/adapters/sqlite.js"
|
|
67
|
+
},
|
|
52
68
|
"./sql/*": "./sql/*",
|
|
53
69
|
"./migrations/*": "./migrations/*",
|
|
54
70
|
"./server/ports": {
|
|
55
71
|
"types": "./dist/server/ports.d.ts",
|
|
56
72
|
"import": "./dist/server/ports.js"
|
|
57
73
|
},
|
|
74
|
+
"./server/consent": {
|
|
75
|
+
"types": "./dist/server/consent.d.ts",
|
|
76
|
+
"import": "./dist/server/consent.js"
|
|
77
|
+
},
|
|
78
|
+
"./server/reader-store": {
|
|
79
|
+
"types": "./dist/server/reader-store.d.ts",
|
|
80
|
+
"import": "./dist/server/reader-store.js"
|
|
81
|
+
},
|
|
58
82
|
"./server/service": {
|
|
59
83
|
"types": "./dist/server/service.d.ts",
|
|
60
84
|
"import": "./dist/server/service.js"
|
|
@@ -91,6 +115,10 @@
|
|
|
91
115
|
"types": "./dist/server/uploads.d.ts",
|
|
92
116
|
"import": "./dist/server/uploads.js"
|
|
93
117
|
},
|
|
118
|
+
"./server/upload-page": {
|
|
119
|
+
"types": "./dist/server/upload-page.d.ts",
|
|
120
|
+
"import": "./dist/server/upload-page.js"
|
|
121
|
+
},
|
|
94
122
|
"./server/publication": {
|
|
95
123
|
"types": "./dist/server/publication.d.ts",
|
|
96
124
|
"import": "./dist/server/publication.js"
|
|
@@ -208,6 +236,7 @@
|
|
|
208
236
|
},
|
|
209
237
|
"peerDependencies": {
|
|
210
238
|
"@aws-sdk/client-s3": "^3.980.0",
|
|
239
|
+
"@aws-sdk/s3-request-presigner": "^3.980.0",
|
|
211
240
|
"@sentropic/mcp-platform": ">=0.4.1 <0.5.0",
|
|
212
241
|
"pg": "^8.12.0"
|
|
213
242
|
},
|
|
@@ -215,6 +244,9 @@
|
|
|
215
244
|
"@aws-sdk/client-s3": {
|
|
216
245
|
"optional": true
|
|
217
246
|
},
|
|
247
|
+
"@aws-sdk/s3-request-presigner": {
|
|
248
|
+
"optional": true
|
|
249
|
+
},
|
|
218
250
|
"@sentropic/mcp-platform": {
|
|
219
251
|
"optional": true
|
|
220
252
|
},
|
|
@@ -224,6 +256,7 @@
|
|
|
224
256
|
},
|
|
225
257
|
"devDependencies": {
|
|
226
258
|
"@aws-sdk/client-s3": "^3.980.0",
|
|
259
|
+
"@aws-sdk/s3-request-presigner": "^3.980.0",
|
|
227
260
|
"@types/node": "^22.10.10",
|
|
228
261
|
"@types/pg": "^8.15.5",
|
|
229
262
|
"pg": "^8.12.0",
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
-- Lot 1a — persistent reader consent, system area of the personal reader store
|
|
2
|
+
-- (design-merged §1.2, §3.1). Unnumbered body for the train integration lane:
|
|
3
|
+
-- the train wraps this file into the next additive migration number at land
|
|
4
|
+
-- time; wagon lanes never pre-assign migration numbers. No nullable owner
|
|
5
|
+
-- column participates in uniqueness; storage_scope_id is part of every unique
|
|
6
|
+
-- key so isolation is structural.
|
|
7
|
+
--
|
|
8
|
+
-- Consent rows authorize a data class; they never record data use: no basket
|
|
9
|
+
-- identifier, no query, no page data, no session/device/network data.
|
|
10
|
+
|
|
11
|
+
CREATE TABLE IF NOT EXISTS artifacts.reader_consents (
|
|
12
|
+
consent_id UUID PRIMARY KEY,
|
|
13
|
+
storage_scope_id TEXT NOT NULL,
|
|
14
|
+
reader_account_id TEXT NOT NULL,
|
|
15
|
+
artifact_id UUID NOT NULL REFERENCES artifacts.artifacts (id) ON DELETE CASCADE,
|
|
16
|
+
scope_id TEXT NOT NULL,
|
|
17
|
+
scope_version TEXT NOT NULL,
|
|
18
|
+
granted_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
19
|
+
granted_via TEXT NOT NULL DEFAULT 'reader_screen' CHECK (granted_via = 'reader_screen'),
|
|
20
|
+
revoked_at TIMESTAMPTZ NULL,
|
|
21
|
+
revoked_by TEXT NULL CHECK (revoked_by IN ('self', 'admin', 'cascade'))
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
-- At most one live row per (scope, reader, artifact, scope, version);
|
|
25
|
+
-- re-grant after revoke mints a new row, history stays auditable.
|
|
26
|
+
CREATE UNIQUE INDEX IF NOT EXISTS reader_consents_live_uniq ON artifacts.reader_consents
|
|
27
|
+
(storage_scope_id, reader_account_id, artifact_id, scope_id, scope_version)
|
|
28
|
+
WHERE revoked_at IS NULL;
|
|
29
|
+
CREATE INDEX IF NOT EXISTS reader_consents_by_reader ON artifacts.reader_consents
|
|
30
|
+
(storage_scope_id, reader_account_id, granted_at, consent_id);
|
|
31
|
+
|
|
32
|
+
-- Append-only audit, no content (actor, surface and version only).
|
|
33
|
+
CREATE TABLE IF NOT EXISTS artifacts.reader_consent_events (
|
|
34
|
+
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
35
|
+
consent_id UUID NOT NULL,
|
|
36
|
+
storage_scope_id TEXT NOT NULL,
|
|
37
|
+
reader_account_id TEXT NOT NULL,
|
|
38
|
+
artifact_id UUID NOT NULL,
|
|
39
|
+
scope_id TEXT NOT NULL,
|
|
40
|
+
scope_version TEXT NOT NULL,
|
|
41
|
+
action TEXT NOT NULL CHECK (action IN ('grant', 'revoke')),
|
|
42
|
+
actor TEXT NOT NULL,
|
|
43
|
+
surface TEXT NOT NULL CHECK (surface IN ('screen', 'api', 'mcp', 'cascade')),
|
|
44
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
45
|
+
);
|
|
46
|
+
CREATE INDEX IF NOT EXISTS reader_consent_events_by_artifact ON artifacts.reader_consent_events
|
|
47
|
+
(storage_scope_id, artifact_id, id);
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
-- U1 — SQLite DDL for the artifacts domain, owned by the SQLite adapter
|
|
2
|
+
-- (applied by openSqliteDatabase, never by the host migration journal).
|
|
3
|
+
--
|
|
4
|
+
-- SQLite has no schemas: the Postgres `artifacts.<table>` names map to plain
|
|
5
|
+
-- `<table>` in the single local file. Column types map TIMESTAMPTZ -> TEXT
|
|
6
|
+
-- (ISO-8601 UTC strings), JSONB -> TEXT (JSON), BOOLEAN -> INTEGER 0/1,
|
|
7
|
+
-- UUID -> TEXT, and gen_random_uuid() is supplied by the adapter. The 0004
|
|
8
|
+
-- terminal guards are enforced in adapter code (all writes are serialized
|
|
9
|
+
-- through one BEGIN IMMEDIATE writer, so check-then-write is atomic); the
|
|
10
|
+
-- publication updated_at side effect is folded into putRelease. Semantics
|
|
11
|
+
-- are identical to migrations/0001..0005.sql.
|
|
12
|
+
|
|
13
|
+
PRAGMA journal_mode = WAL;
|
|
14
|
+
PRAGMA synchronous = FULL;
|
|
15
|
+
PRAGMA foreign_keys = ON;
|
|
16
|
+
|
|
17
|
+
CREATE TABLE IF NOT EXISTS storage_scopes (
|
|
18
|
+
id TEXT PRIMARY KEY,
|
|
19
|
+
org_id TEXT NOT NULL,
|
|
20
|
+
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
CREATE TABLE IF NOT EXISTS artifacts (
|
|
24
|
+
id TEXT PRIMARY KEY,
|
|
25
|
+
storage_scope_id TEXT NOT NULL REFERENCES storage_scopes (id),
|
|
26
|
+
owner_id TEXT NOT NULL,
|
|
27
|
+
binding_name TEXT NOT NULL,
|
|
28
|
+
profile TEXT NOT NULL DEFAULT '{}',
|
|
29
|
+
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
|
|
30
|
+
lifecycle_state TEXT NOT NULL DEFAULT 'active'
|
|
31
|
+
CHECK (lifecycle_state IN ('active', 'withdrawn', 'deleted', 'purged')),
|
|
32
|
+
renewed_at TEXT,
|
|
33
|
+
is_public INTEGER NOT NULL DEFAULT 0,
|
|
34
|
+
access_mode TEXT NOT NULL DEFAULT 'restricted'
|
|
35
|
+
CHECK (access_mode IN ('restricted', 'platform', 'public')),
|
|
36
|
+
terminal_deleted_at TEXT,
|
|
37
|
+
updated_at TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
|
|
38
|
+
metadata TEXT NOT NULL DEFAULT '{}',
|
|
39
|
+
UNIQUE (storage_scope_id, owner_id, binding_name)
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
CREATE TABLE IF NOT EXISTS releases (
|
|
43
|
+
id TEXT PRIMARY KEY,
|
|
44
|
+
artifact_id TEXT NOT NULL REFERENCES artifacts (id) ON DELETE CASCADE,
|
|
45
|
+
manifest_digest TEXT NOT NULL,
|
|
46
|
+
manifest TEXT NOT NULL,
|
|
47
|
+
state TEXT NOT NULL DEFAULT 'ready' CHECK (state IN ('ready', 'retired', 'purged')),
|
|
48
|
+
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
|
|
49
|
+
author_principal_id TEXT,
|
|
50
|
+
parent_release_id TEXT,
|
|
51
|
+
reverted_from_release_id TEXT
|
|
52
|
+
);
|
|
53
|
+
CREATE INDEX IF NOT EXISTS releases_by_artifact ON releases (artifact_id);
|
|
54
|
+
|
|
55
|
+
CREATE TABLE IF NOT EXISTS artifact_current (
|
|
56
|
+
artifact_id TEXT PRIMARY KEY REFERENCES artifacts (id) ON DELETE CASCADE,
|
|
57
|
+
release_id TEXT NOT NULL REFERENCES releases (id) ON DELETE RESTRICT
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
CREATE TABLE IF NOT EXISTS blobs (
|
|
61
|
+
storage_scope_id TEXT NOT NULL,
|
|
62
|
+
digest TEXT NOT NULL,
|
|
63
|
+
size INTEGER NOT NULL CHECK (size >= 0),
|
|
64
|
+
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
|
|
65
|
+
PRIMARY KEY (storage_scope_id, digest)
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
CREATE TABLE IF NOT EXISTS uploads (
|
|
69
|
+
id TEXT PRIMARY KEY,
|
|
70
|
+
max_size INTEGER NOT NULL CHECK (max_size > 0),
|
|
71
|
+
size INTEGER NOT NULL DEFAULT 0 CHECK (size >= 0),
|
|
72
|
+
mime_type TEXT NOT NULL,
|
|
73
|
+
state TEXT NOT NULL DEFAULT 'open' CHECK (state IN ('open', 'committed', 'discarded')),
|
|
74
|
+
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
|
|
75
|
+
);
|
|
76
|
+
CREATE INDEX IF NOT EXISTS uploads_by_state ON uploads (state);
|
|
77
|
+
|
|
78
|
+
CREATE TABLE IF NOT EXISTS object_intents (
|
|
79
|
+
id TEXT PRIMARY KEY,
|
|
80
|
+
kind TEXT NOT NULL CHECK (kind IN ('commit-release', 'delete-blob', 'promote-release')),
|
|
81
|
+
state TEXT NOT NULL DEFAULT 'pending' CHECK (state IN ('pending', 'done', 'failed')),
|
|
82
|
+
payload TEXT NOT NULL DEFAULT '{}',
|
|
83
|
+
error TEXT,
|
|
84
|
+
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
|
|
85
|
+
updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
|
|
86
|
+
);
|
|
87
|
+
CREATE INDEX IF NOT EXISTS intents_pending ON object_intents (state, created_at)
|
|
88
|
+
WHERE state = 'pending';
|
|
89
|
+
|
|
90
|
+
CREATE TABLE IF NOT EXISTS idempotency_keys (
|
|
91
|
+
key TEXT PRIMARY KEY,
|
|
92
|
+
params_hash TEXT NOT NULL,
|
|
93
|
+
result TEXT NOT NULL,
|
|
94
|
+
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
CREATE TABLE IF NOT EXISTS artifact_access (
|
|
98
|
+
artifact_id TEXT NOT NULL REFERENCES artifacts (id) ON DELETE CASCADE,
|
|
99
|
+
principal_id TEXT NOT NULL,
|
|
100
|
+
permission TEXT NOT NULL CHECK (permission IN ('read', 'source')),
|
|
101
|
+
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
|
|
102
|
+
PRIMARY KEY (artifact_id, principal_id)
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
CREATE TABLE IF NOT EXISTS artifact_access_events (
|
|
106
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
107
|
+
artifact_id TEXT NOT NULL REFERENCES artifacts (id) ON DELETE CASCADE,
|
|
108
|
+
actor_id TEXT NOT NULL,
|
|
109
|
+
action TEXT NOT NULL CHECK (action IN ('grant', 'revoke')),
|
|
110
|
+
audience TEXT NOT NULL CHECK (audience IN ('user', 'platform', 'public')),
|
|
111
|
+
principal_id TEXT,
|
|
112
|
+
policy_revision TEXT NOT NULL,
|
|
113
|
+
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
CREATE INDEX IF NOT EXISTS access_events_by_artifact ON artifact_access_events (artifact_id);
|
|
117
|
+
|
|
118
|
+
CREATE TABLE IF NOT EXISTS artifact_sources (
|
|
119
|
+
artifact_id TEXT PRIMARY KEY REFERENCES artifacts (id) ON DELETE CASCADE,
|
|
120
|
+
kind TEXT NOT NULL CHECK (kind IN ('inline-original', 'base-commit', 'recipe')),
|
|
121
|
+
commit_tx TEXT,
|
|
122
|
+
steps TEXT,
|
|
123
|
+
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
CREATE TABLE IF NOT EXISTS blob_ref_holders (
|
|
127
|
+
digest TEXT NOT NULL,
|
|
128
|
+
holder TEXT NOT NULL,
|
|
129
|
+
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
|
|
130
|
+
PRIMARY KEY (digest, holder)
|
|
131
|
+
);
|
|
132
|
+
CREATE INDEX IF NOT EXISTS ref_holders_by_digest ON blob_ref_holders (digest);
|
|
133
|
+
|
|
134
|
+
CREATE TABLE IF NOT EXISTS blob_pins (
|
|
135
|
+
digest TEXT NOT NULL,
|
|
136
|
+
reason TEXT NOT NULL,
|
|
137
|
+
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
|
|
138
|
+
PRIMARY KEY (digest, reason)
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
CREATE TABLE IF NOT EXISTS operation_keys (
|
|
142
|
+
storage_scope_id TEXT NOT NULL,
|
|
143
|
+
internal_key TEXT NOT NULL,
|
|
144
|
+
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
|
|
145
|
+
PRIMARY KEY (storage_scope_id, internal_key)
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
CREATE TABLE IF NOT EXISTS operation_receipts (
|
|
149
|
+
storage_scope_id TEXT NOT NULL,
|
|
150
|
+
internal_key TEXT NOT NULL,
|
|
151
|
+
command_codec TEXT NOT NULL,
|
|
152
|
+
command_hash TEXT NOT NULL,
|
|
153
|
+
receipt TEXT NOT NULL,
|
|
154
|
+
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
|
|
155
|
+
PRIMARY KEY (storage_scope_id, internal_key)
|
|
156
|
+
);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
-- U1 — SQLite DDL for the activation host domain, owned by the SQLite
|
|
2
|
+
-- adapter. The Postgres `artifact_host.<table>` names map to plain
|
|
3
|
+
-- `<table>` (SQLite has no schemas); bigint -> INTEGER, jsonb -> TEXT,
|
|
4
|
+
-- generated columns use json_extract, and the regex CHECKs of
|
|
5
|
+
-- sql/0001_activation.sql are enforced in adapter code (SQLite has no
|
|
6
|
+
-- REGEXP without a host function). Immutability triggers are kept.
|
|
7
|
+
-- DB time is CAST((julianday('now') - 2440587.5) * 86400000 AS INTEGER) ms.
|
|
8
|
+
|
|
9
|
+
CREATE TABLE IF NOT EXISTS activation_namespaces (
|
|
10
|
+
namespace TEXT PRIMARY KEY CHECK (length(namespace) BETWEEN 1 AND 256),
|
|
11
|
+
generation INTEGER NOT NULL DEFAULT 1 CHECK (generation > 0)
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
CREATE TABLE IF NOT EXISTS activation_tickets (
|
|
15
|
+
namespace TEXT NOT NULL REFERENCES activation_namespaces (namespace),
|
|
16
|
+
generation INTEGER NOT NULL,
|
|
17
|
+
payload TEXT NOT NULL,
|
|
18
|
+
ticket_id TEXT GENERATED ALWAYS AS (json_extract(payload, '$.ticketId')) STORED NOT NULL,
|
|
19
|
+
subject_id TEXT GENERATED ALWAYS AS (json_extract(payload, '$.subjectId')) STORED NOT NULL,
|
|
20
|
+
artifact_id TEXT GENERATED ALWAYS AS (json_extract(payload, '$.artifactId')) STORED NOT NULL,
|
|
21
|
+
release_id TEXT GENERATED ALWAYS AS (json_extract(payload, '$.releaseId')) STORED NOT NULL,
|
|
22
|
+
channel TEXT GENERATED ALWAYS AS (json_extract(payload, '$.channel')) STORED NOT NULL,
|
|
23
|
+
expires_ms INTEGER GENERATED ALWAYS AS (json_extract(payload, '$.expiresAt')) STORED NOT NULL,
|
|
24
|
+
issued_ms INTEGER NOT NULL DEFAULT (CAST((julianday('now') - 2440587.5) * 86400000 AS INTEGER)),
|
|
25
|
+
-- SQLite forbids generated columns in a PRIMARY KEY; UNIQUE (which creates
|
|
26
|
+
-- the index the FK and lookups need) accepts them.
|
|
27
|
+
UNIQUE (namespace, ticket_id),
|
|
28
|
+
UNIQUE (namespace, generation, ticket_id, subject_id, artifact_id, release_id, channel, expires_ms),
|
|
29
|
+
CHECK (length(ticket_id) BETWEEN 1 AND 256 AND length(subject_id) BETWEEN 1 AND 256),
|
|
30
|
+
CHECK (length(artifact_id) BETWEEN 1 AND 256 AND length(release_id) BETWEEN 1 AND 256),
|
|
31
|
+
CHECK (channel IN ('stable', 'pinned')),
|
|
32
|
+
-- pg jsonb_typeof = 'number' covers all numbers; SQLite splits integer/real.
|
|
33
|
+
CHECK (json_type(payload, '$.expiresAt') IN ('integer', 'real')),
|
|
34
|
+
CHECK (expires_ms > issued_ms AND expires_ms <= issued_ms + 60000)
|
|
35
|
+
);
|
|
36
|
+
CREATE INDEX IF NOT EXISTS activation_tickets_expiry ON activation_tickets (namespace, expires_ms, ticket_id);
|
|
37
|
+
CREATE INDEX IF NOT EXISTS activation_tickets_generation ON activation_tickets (namespace, generation, ticket_id);
|
|
38
|
+
|
|
39
|
+
CREATE TABLE IF NOT EXISTS browser_flows (
|
|
40
|
+
namespace TEXT NOT NULL,
|
|
41
|
+
generation INTEGER NOT NULL,
|
|
42
|
+
payload TEXT NOT NULL,
|
|
43
|
+
flow_id TEXT GENERATED ALWAYS AS (json_extract(payload, '$.flowId')) STORED NOT NULL,
|
|
44
|
+
ticket_id TEXT GENERATED ALWAYS AS (json_extract(payload, '$.ticketId')) STORED NOT NULL,
|
|
45
|
+
subject_id TEXT GENERATED ALWAYS AS (json_extract(payload, '$.subjectId')) STORED NOT NULL,
|
|
46
|
+
artifact_id TEXT GENERATED ALWAYS AS (json_extract(payload, '$.artifactId')) STORED NOT NULL,
|
|
47
|
+
release_id TEXT GENERATED ALWAYS AS (json_extract(payload, '$.releaseId')) STORED NOT NULL,
|
|
48
|
+
channel TEXT GENERATED ALWAYS AS (json_extract(payload, '$.channel')) STORED NOT NULL,
|
|
49
|
+
expires_ms INTEGER GENERATED ALWAYS AS (json_extract(payload, '$.expiresAt')) STORED NOT NULL,
|
|
50
|
+
ticket_expires_ms INTEGER NOT NULL,
|
|
51
|
+
UNIQUE (namespace, flow_id),
|
|
52
|
+
UNIQUE (namespace, ticket_id),
|
|
53
|
+
FOREIGN KEY (namespace, generation, ticket_id, subject_id, artifact_id, release_id, channel, ticket_expires_ms)
|
|
54
|
+
REFERENCES activation_tickets
|
|
55
|
+
(namespace, generation, ticket_id, subject_id, artifact_id, release_id, channel, expires_ms)
|
|
56
|
+
ON DELETE CASCADE,
|
|
57
|
+
CHECK (length(flow_id) BETWEEN 1 AND 256),
|
|
58
|
+
CHECK (expires_ms <= ticket_expires_ms),
|
|
59
|
+
CHECK (json_type(payload, '$.expiresAt') IN ('integer', 'real')),
|
|
60
|
+
CHECK (length(json_extract(payload, '$.sessionId')) BETWEEN 1 AND 256 AND json_extract(payload, '$.sessionId') IS NOT NULL),
|
|
61
|
+
CHECK (length(json_extract(payload, '$.policyRevision')) BETWEEN 1 AND 256 AND json_extract(payload, '$.policyRevision') IS NOT NULL)
|
|
62
|
+
);
|
|
63
|
+
CREATE INDEX IF NOT EXISTS browser_flows_expiry ON browser_flows (namespace, expires_ms, flow_id);
|
|
64
|
+
CREATE INDEX IF NOT EXISTS browser_flows_generation ON browser_flows (namespace, generation, flow_id);
|
|
65
|
+
|
|
66
|
+
CREATE TRIGGER IF NOT EXISTS activation_tickets_immutable BEFORE UPDATE ON activation_tickets
|
|
67
|
+
BEGIN
|
|
68
|
+
SELECT RAISE(ABORT, 'activation records are immutable');
|
|
69
|
+
END;
|
|
70
|
+
CREATE TRIGGER IF NOT EXISTS browser_flows_immutable BEFORE UPDATE ON browser_flows
|
|
71
|
+
BEGIN
|
|
72
|
+
SELECT RAISE(ABORT, 'activation records are immutable');
|
|
73
|
+
END;
|