@sentropic/artifacts 0.2.28 → 0.2.30

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.30
4
+
5
+ - Fix the Postgres uploads adapter: staged files now carry the `pageSessionId` of their upload
6
+ session (`artifacts.uploads.page_session_id`, migration 0009). Before, `getStagedFile`,
7
+ `listStagedFiles` and `listExpiredStaged` dropped it, so `artifacts_list_assets {pageSessionId}`
8
+ and the upload page « Review files » list returned no file on Postgres hosts. No migration.
9
+
10
+ ## 0.2.29
11
+
12
+ - Fix the browser upload script syntax and authorize the inline scripts and style with a fresh
13
+ CSP nonce on each render. Existing HTML-only hosts can keep calling `renderUploadPage`.
14
+ Hosts that send a CSP header can use the matching `html` and `csp` from
15
+ `renderUploadPageDocument`. Browsers enforce `frame-ancestors` only in that header.
16
+
3
17
  ## 0.2.28
4
18
 
5
19
  - Add DB blob placement: migration `0014_db_blob_placement.sql` (`placement`, `blob_bytes`,
@@ -16,6 +16,13 @@ async function tx(pool, work) {
16
16
  client.release();
17
17
  }
18
18
  }
19
+ /**
20
+ * A staged file's page is the page of its upload session: `uploads.page_session_id`
21
+ * (0009) is the persisted source, and `staged_files.upload_id` cascades from it.
22
+ */
23
+ const STAGED_SELECT = `SELECT s.upload_id, s.artifact_id, s.path, s.mime_type, s.digest, s.size,
24
+ s.created_at, u.page_session_id
25
+ FROM artifacts.staged_files s JOIN artifacts.uploads u ON u.id = s.upload_id`;
19
26
  const toSession = (row) => ({
20
27
  uploadId: row.id,
21
28
  artifactId: row.artifact_id ?? '',
@@ -36,6 +43,7 @@ const toStaged = (row) => ({
36
43
  digest: row.digest,
37
44
  size: row.size,
38
45
  createdAt: row.created_at.toISOString(),
46
+ ...(row.page_session_id === null ? {} : { pageSessionId: row.page_session_id }),
39
47
  });
40
48
  function using(pool, db, inTx) {
41
49
  return {
@@ -78,11 +86,11 @@ function using(pool, db, inTx) {
78
86
  record.digest, record.size, record.createdAt]);
79
87
  },
80
88
  async getStagedFile(uploadId) {
81
- const { rows } = await db.query('SELECT * FROM artifacts.staged_files WHERE upload_id = $1', [uploadId]);
89
+ const { rows } = await db.query(`${STAGED_SELECT} WHERE s.upload_id = $1`, [uploadId]);
82
90
  return rows[0] === undefined ? undefined : toStaged(rows[0]);
83
91
  },
84
92
  async listStagedFiles(artifactId) {
85
- const { rows } = await db.query('SELECT * FROM artifacts.staged_files WHERE artifact_id = $1 ORDER BY path', [artifactId]);
93
+ const { rows } = await db.query(`${STAGED_SELECT} WHERE s.artifact_id = $1 ORDER BY s.path`, [artifactId]);
86
94
  return rows.map(toStaged);
87
95
  },
88
96
  async sumOpenMaxSize(storageScopeId) {
@@ -111,7 +119,7 @@ function using(pool, db, inTx) {
111
119
  },
112
120
  async listExpiredStaged(at, ttlMs) {
113
121
  const cutoff = new Date(at.getTime() - ttlMs).toISOString();
114
- const { rows } = await db.query('SELECT * FROM artifacts.staged_files WHERE created_at <= $1 ORDER BY created_at', [cutoff]);
122
+ const { rows } = await db.query(`${STAGED_SELECT} WHERE s.created_at <= $1 ORDER BY s.created_at`, [cutoff]);
115
123
  return rows.map(toStaged);
116
124
  },
117
125
  async deleteStagedFile(uploadId) {
@@ -10,7 +10,7 @@ export { createRadarKeyDerivation } from './server/command-identity.js';
10
10
  export type { ArtifactKeyDerivationBinding } from './server/command-identity.js';
11
11
  export declare const ARTIFACTS_PROVIDER_ID = "sentropic.artifacts";
12
12
  export declare const ARTIFACTS_APP_ID = "sentropic-artifacts";
13
- export declare const ARTIFACTS_PROVIDER_VERSION = "0.2.28";
13
+ export declare const ARTIFACTS_PROVIDER_VERSION = "0.2.30";
14
14
  export declare const ARTIFACTS_TOOL_NAMES: readonly ["artifacts_get_template", "artifacts_get_api_guide", "artifacts_ensure", "artifacts_publish", "artifacts_create_upload", "artifacts_commit_upload", "artifacts_list", "artifacts_get", "artifacts_get_source", "artifacts_fork", "artifacts_set_access", "artifacts_promote", "artifacts_renew", "artifacts_delete", "artifacts_restore", "artifacts_list_versions", "artifacts_revert", "artifacts_lookup_people", "artifacts_list_access", "artifacts_publish_bundle", "artifacts_revoke_reader_consent", "artifacts_create_upload_page", "artifacts_list_assets", "artifacts_publish_bundle_v2", "artifacts_list_app_sources", "artifacts_fetch_app_source", "artifacts_git_attach", "artifacts_git_commit", "artifacts_git_publish", "artifacts_git_live", "artifacts_live_write", "artifacts_live_read", "artifacts_live_reset", "artifacts_live_status", "artifacts_live_control", "artifacts_live_invite", "artifacts_live_accept_invitation", "artifacts_live_revoke_invitation", "artifacts_live_invitations"];
15
15
  export type ArtifactsToolName = (typeof ARTIFACTS_TOOL_NAMES)[number];
16
16
  export interface ArtifactsToolDefinition {
package/dist/mcp-core.js CHANGED
@@ -7,7 +7,7 @@ export * from './profile/index.js';
7
7
  export { createRadarKeyDerivation } from './server/command-identity.js';
8
8
  export const ARTIFACTS_PROVIDER_ID = 'sentropic.artifacts';
9
9
  export const ARTIFACTS_APP_ID = 'sentropic-artifacts';
10
- export const ARTIFACTS_PROVIDER_VERSION = '0.2.28';
10
+ export const ARTIFACTS_PROVIDER_VERSION = '0.2.30';
11
11
  export const ARTIFACTS_TOOL_NAMES = ARTIFACT_CAPABILITY_NAMES;
12
12
  // ---------------------------------------------------------------------------
13
13
  // Byte-stable tool definitions (MCP tool-definition stability rule).
@@ -66,6 +66,14 @@ export declare const BROWSER_EXTENSION_FALLBACK_MIME: Readonly<Record<string, st
66
66
  export declare function renderUploadPage(options: {
67
67
  s3Origins: readonly string[];
68
68
  }): string;
69
+ /** Render the document and its matching CSP for hosts that send a CSP header. */
70
+ export declare function renderUploadPageDocument(options: {
71
+ s3Origins: readonly string[];
72
+ }): {
73
+ html: string;
74
+ csp: string;
75
+ nonce: string;
76
+ };
69
77
  export interface UploadPageProfileCaps {
70
78
  readonly maxFiles: number;
71
79
  readonly maxFileBytes: number;
@@ -125,10 +125,14 @@ export function parseUploadPageCookie(header) {
125
125
  }
126
126
  /** Page CSP (§A.4): no external assets; S3 origins are host-supplied. */
127
127
  export function uploadPageCsp(s3Origins) {
128
+ return buildUploadPageCsp(s3Origins);
129
+ }
130
+ function buildUploadPageCsp(s3Origins, nonce) {
128
131
  if (s3Origins.length === 0 || s3Origins.some((origin) => !/^https:\/\/[A-Za-z0-9.-]+(?::\d+)?$/.test(origin))) {
129
132
  throw new Error('invalid page S3 origins: the page refuses to render without them');
130
133
  }
131
- return ['default-src \'none\'', 'script-src \'self\'', 'style-src \'self\'',
134
+ const inlineSource = nonce === undefined ? '' : ` 'nonce-${nonce}'`;
135
+ return ["default-src 'none'", `script-src 'self'${inlineSource}`, `style-src 'self'${inlineSource}`,
132
136
  'img-src \'self\' blob:', 'font-src \'self\'', `connect-src 'self' ${s3Origins.join(' ')}`,
133
137
  'base-uri \'none\'', 'form-action \'none\'', 'frame-ancestors \'none\''].join('; ');
134
138
  }
@@ -154,17 +158,24 @@ export const BROWSER_EXTENSION_FALLBACK_MIME = Object.freeze({
154
158
  * PUTs in flight; commit each file before opening further sessions.
155
159
  */
156
160
  export function renderUploadPage(options) {
157
- const csp = uploadPageCsp(options.s3Origins);
158
- const config = JSON.stringify({ s3Origins: [...options.s3Origins] });
159
- return `<!doctype html>
161
+ return renderUploadPageDocument(options).html;
162
+ }
163
+ /** Render the document and its matching CSP for hosts that send a CSP header. */
164
+ export function renderUploadPageDocument(options) {
165
+ const nonce = randomBytes(16).toString('base64');
166
+ const csp = buildUploadPageCsp(options.s3Origins, nonce);
167
+ // Browsers only enforce frame-ancestors in an HTTP header.
168
+ const metaCsp = csp.replace("; frame-ancestors 'none'", '');
169
+ const config = JSON.stringify({ s3Origins: [...options.s3Origins] }).replace(/</g, '\\u003c');
170
+ const html = `<!doctype html>
160
171
  <html lang="en">
161
172
  <head>
162
173
  <meta charset="utf-8">
163
174
  <meta name="viewport" content="width=device-width, initial-scale=1">
164
- <meta http-equiv="Content-Security-Policy" content="${csp.replace(/"/g, '&quot;')}">
175
+ <meta http-equiv="Content-Security-Policy" content="${metaCsp.replace(/"/g, '&quot;')}">
165
176
  <meta name="color-scheme" content="light dark">
166
177
  <title>Upload files</title>
167
- <style>body{font-family:system-ui,sans-serif;max-width:42rem;margin:2rem auto;padding:0 1rem}
178
+ <style nonce="${nonce}">body{font-family:system-ui,sans-serif;max-width:42rem;margin:2rem auto;padding:0 1rem}
168
179
  #drop{border:2px dashed #888;border-radius:.5rem;padding:2rem;text-align:center;margin:1rem 0}
169
180
  #drop.over{border-color:#06c;background:#06c1}
170
181
  li{margin:.25rem 0;font-size:.9rem}pre{white-space:pre-wrap;word-break:break-all;background:#8882;padding:1rem}</style>
@@ -179,8 +190,8 @@ When every file shows <b>staged</b>, go back to the chat and say <b>done</b>.</p
179
190
  <button id="copy" type="button">Copy asset list (chat fallback)</button>
180
191
  <pre id="assetJson" hidden></pre>
181
192
  <p id="error" role="alert"></p>
182
- <script>window.__ARTIFACTS_UPLOAD__ = ${config};</script>
183
- <script>
193
+ <script nonce="${nonce}">window.__ARTIFACTS_UPLOAD__ = ${config};</script>
194
+ <script nonce="${nonce}">
184
195
  'use strict';
185
196
  const sessionId = location.pathname.split('/').filter(Boolean).pop();
186
197
  let token = (location.hash.match(/#t=([^&]+)/) || [])[1] || '';
@@ -200,7 +211,7 @@ const EXT_TYPES = ${JSON.stringify(BROWSER_EXTENSION_FALLBACK_MIME)};
200
211
  const chunked = (bytes, f) => {
201
212
  const view = new Uint8Array(bytes);
202
213
  let out = '';
203
- for (let i = 0; i < view.length; i += 0x8000) out += f(view.subarray(i, i + 0x8000)));
214
+ for (let i = 0; i < view.length; i += 0x8000) out += f(view.subarray(i, i + 0x8000));
204
215
  return out;
205
216
  };
206
217
  const hex = (bytes) => chunked(bytes, (part) => [...part].map((b) => b.toString(16).padStart(2, '0')).join(''));
@@ -283,6 +294,7 @@ api('exchange', { token }).then(() => {
283
294
  </script>
284
295
  </body>
285
296
  </html>`;
297
+ return { html, csp, nonce };
286
298
  }
287
299
  export function createUploadPageService(deps, options) {
288
300
  const now = options?.now ?? (() => new Date());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentropic/artifacts",
3
- "version": "0.2.28",
3
+ "version": "0.2.30",
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",
@@ -289,6 +289,6 @@
289
289
  "@types/pg": "^8.15.5",
290
290
  "pg": "^8.12.0",
291
291
  "typescript": "5.4.5",
292
- "vitest": "4.1.0"
292
+ "vitest": "4.1.12"
293
293
  }
294
294
  }