@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.
Files changed (95) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/adapters/github-forge.d.ts +4 -0
  3. package/dist/adapters/github-forge.js +88 -0
  4. package/dist/adapters/github-git-port.d.ts +5 -0
  5. package/dist/adapters/github-git-port.js +102 -0
  6. package/dist/adapters/github-http.d.ts +5 -0
  7. package/dist/adapters/github-http.js +57 -0
  8. package/dist/adapters/github-receive-pack.d.ts +4 -0
  9. package/dist/adapters/github-receive-pack.js +49 -0
  10. package/dist/adapters/postgres-git-bindings.d.ts +7 -0
  11. package/dist/adapters/postgres-git-bindings.js +110 -0
  12. package/dist/adapters/postgres-live.d.ts +4 -0
  13. package/dist/adapters/postgres-live.js +97 -0
  14. package/dist/adapters/postgres.d.ts +1 -0
  15. package/dist/adapters/postgres.js +1 -0
  16. package/dist/content/handler.d.ts +7 -0
  17. package/dist/content/handler.js +28 -5
  18. package/dist/content/headers.d.ts +13 -0
  19. package/dist/content/headers.js +40 -2
  20. package/dist/git-tool-definitions.d.ts +606 -0
  21. package/dist/git-tool-definitions.js +14 -0
  22. package/dist/http.d.ts +6 -0
  23. package/dist/http.js +20 -2
  24. package/dist/index.d.ts +13 -0
  25. package/dist/index.js +12 -0
  26. package/dist/mcp-core.d.ts +3 -3
  27. package/dist/mcp-core.js +15 -2
  28. package/dist/profile/contracts.d.ts +1 -1
  29. package/dist/profile/contracts.js +4 -0
  30. package/dist/profile/index.js +8 -1
  31. package/dist/profile/schemas.js +19 -0
  32. package/dist/profile/validation.js +5 -1
  33. package/dist/server/build-contract.d.ts +64 -0
  34. package/dist/server/build-contract.js +58 -0
  35. package/dist/server/build-dependencies.d.ts +3 -0
  36. package/dist/server/build-dependencies.js +122 -0
  37. package/dist/server/consent-grant.d.ts +91 -0
  38. package/dist/server/consent-grant.js +89 -0
  39. package/dist/server/consent-screen.d.ts +21 -0
  40. package/dist/server/consent-screen.js +52 -0
  41. package/dist/server/failures.d.ts +3 -2
  42. package/dist/server/failures.js +30 -0
  43. package/dist/server/git-bindings.d.ts +8 -0
  44. package/dist/server/git-bindings.js +113 -0
  45. package/dist/server/git-contracts.d.ts +98 -0
  46. package/dist/server/git-contracts.js +1 -0
  47. package/dist/server/git-port-policy.d.ts +9 -0
  48. package/dist/server/git-port-policy.js +76 -0
  49. package/dist/server/git-port-read.d.ts +3 -0
  50. package/dist/server/git-port-read.js +95 -0
  51. package/dist/server/git-port-session.d.ts +38 -0
  52. package/dist/server/git-port-session.js +59 -0
  53. package/dist/server/git-port-tree.d.ts +8 -0
  54. package/dist/server/git-port-tree.js +92 -0
  55. package/dist/server/git-port-write.d.ts +6 -0
  56. package/dist/server/git-port-write.js +102 -0
  57. package/dist/server/git-port.d.ts +147 -0
  58. package/dist/server/git-port.js +8 -0
  59. package/dist/server/git-projection.d.ts +16 -0
  60. package/dist/server/git-projection.js +20 -0
  61. package/dist/server/git-registry.d.ts +37 -0
  62. package/dist/server/git-registry.js +39 -0
  63. package/dist/server/live-body.d.ts +3 -0
  64. package/dist/server/live-body.js +28 -0
  65. package/dist/server/live-commit-outcome.d.ts +6 -0
  66. package/dist/server/live-commit-outcome.js +10 -0
  67. package/dist/server/live-commit.d.ts +11 -0
  68. package/dist/server/live-commit.js +133 -0
  69. package/dist/server/live-contracts.d.ts +62 -0
  70. package/dist/server/live-contracts.js +8 -0
  71. package/dist/server/live-crypto.d.ts +14 -0
  72. package/dist/server/live-crypto.js +50 -0
  73. package/dist/server/live-drafts.d.ts +61 -0
  74. package/dist/server/live-drafts.js +119 -0
  75. package/dist/server/live-errors.d.ts +23 -0
  76. package/dist/server/live-errors.js +9 -0
  77. package/dist/server/live-mutations.d.ts +18 -0
  78. package/dist/server/live-mutations.js +83 -0
  79. package/dist/server/live-read.d.ts +15 -0
  80. package/dist/server/live-read.js +95 -0
  81. package/dist/server/live-service.d.ts +3 -0
  82. package/dist/server/live-service.js +181 -0
  83. package/dist/server/live-store.d.ts +111 -0
  84. package/dist/server/live-store.js +80 -0
  85. package/dist/server/live-tree.d.ts +22 -0
  86. package/dist/server/live-tree.js +148 -0
  87. package/dist/server/live-worker.d.ts +10 -0
  88. package/dist/server/live-worker.js +55 -0
  89. package/dist/server/mime.d.ts +9 -0
  90. package/dist/server/mime.js +47 -0
  91. package/dist/server/upload-page.d.ts +7 -0
  92. package/dist/server/upload-page.js +16 -1
  93. package/migrations/0010_git_bindings.sql +82 -0
  94. package/migrations/0011_live_drafts.sql +42 -0
  95. package/package.json +13 -1
@@ -18,6 +18,21 @@ import { combineSharingPolicy, resolveSharingPolicy } from '../server/ports.js';
18
18
  import { CONTENT_GRANT_TTL_SECONDS } from './grants.js';
19
19
  import { contentHeaders, grantCookie, parseGrantCookie } from './headers.js';
20
20
  import { isServiceWorkerPath, parseContentHost, resolveContentPath } from './routing.js';
21
+ /**
22
+ * History fallback (application mode only): an extensionless HTML navigation
23
+ * serves the release entry instead of 404. Missing assets (extension
24
+ * present), reader protocol paths and non-HTML data fetches stay 404.
25
+ */
26
+ function isHistoryFallback(filePath, accept) {
27
+ if (filePath === '_reader' || filePath.startsWith('_reader/'))
28
+ return false;
29
+ const last = filePath.split('/').pop() ?? '';
30
+ if (last.includes('.'))
31
+ return false;
32
+ if (accept === undefined)
33
+ return true;
34
+ return accept.split(',').some((part) => part.split(';')[0]?.trim() === 'text/html');
35
+ }
21
36
  function jsonResponse(status, body, extra = {}) {
22
37
  return { status, body, headers: {
23
38
  ...contentHeaders({ mimeType: 'application/json', size: Buffer.byteLength(JSON.stringify(body)) }),
@@ -83,16 +98,24 @@ export function createContentHandler(deps) {
83
98
  const bytes = await deps.blobs.getBlob(key);
84
99
  return bytes === undefined ? undefined : bytes.slice(start, end + 1);
85
100
  }
86
- async function serveFile(artifactId, manifest, filePath, rangeHeader) {
101
+ async function serveFile(artifactId, manifest, filePath, rangeHeader, accept) {
87
102
  const acl = await deps.acls.getArtifactAcl(artifactId);
88
103
  if (acl === undefined)
89
104
  return fail(404);
90
105
  if (acl.storageScopeId === undefined)
91
106
  return fail(500);
107
+ const mode = deps.contentMode ?? 'safe';
92
108
  const parsed = JSON.parse(manifest);
93
- const file = (parsed.files ?? []).find((entry) => entry.path === filePath);
109
+ let file = (parsed.files ?? []).find((entry) => entry.path === filePath);
110
+ let servedPath = filePath;
111
+ if ((file === undefined || typeof file.digest !== 'string') &&
112
+ mode === 'application' && isHistoryFallback(filePath, accept)) {
113
+ file = (parsed.files ?? []).find((entry) => entry.path === 'index.html');
114
+ servedPath = 'index.html';
115
+ }
94
116
  if (file === undefined || typeof file.digest !== 'string')
95
117
  return fail(404);
118
+ const scriptHashes = mode === 'application' ? deps.getScriptHashes?.(servedPath) : undefined;
96
119
  const hex = file.digest.startsWith('sha256:') ? file.digest.slice(7) : file.digest;
97
120
  const key = `artifacts/${acl.storageScopeId}/blobs/sha256/${hex}`;
98
121
  const mimeType = typeof file.mimeType === 'string' ? file.mimeType : 'application/octet-stream';
@@ -117,7 +140,7 @@ export function createContentHandler(deps) {
117
140
  return {
118
141
  status: 206,
119
142
  headers: { ...contentHeaders({ mimeType, size: bytes.length,
120
- assetCacheSeconds: deps.assetCacheSeconds }),
143
+ assetCacheSeconds: deps.assetCacheSeconds, mode, scriptHashes }),
121
144
  'content-range': `bytes ${range.start}-${range.end}/${size}`,
122
145
  'accept-ranges': 'bytes' },
123
146
  bytes,
@@ -134,7 +157,7 @@ export function createContentHandler(deps) {
134
157
  return {
135
158
  status: 200,
136
159
  headers: { ...contentHeaders({ mimeType, size: bytes.length,
137
- assetCacheSeconds: deps.assetCacheSeconds }),
160
+ assetCacheSeconds: deps.assetCacheSeconds, mode, scriptHashes }),
138
161
  'accept-ranges': 'bytes' },
139
162
  bytes,
140
163
  };
@@ -211,7 +234,7 @@ export function createContentHandler(deps) {
211
234
  const filePath = resolveContentPath(request.path);
212
235
  if (filePath === undefined || isServiceWorkerPath(filePath))
213
236
  return fail(404);
214
- return serveFile(artifactId, release.manifest, filePath, request.range);
237
+ return serveFile(artifactId, release.manifest, filePath, request.range, request.accept);
215
238
  }
216
239
  return {
217
240
  async handle(request) {
@@ -11,11 +11,24 @@
11
11
  * prefix: Secure, Path=/, no Domain attribute).
12
12
  */
13
13
  export declare const GRANT_COOKIE_NAME = "__Host-artifacts_grant";
14
+ /** Host-configured content mode (owner decision 05/11): safe is the historic strict regime and the default. */
15
+ export type ContentMode = 'safe' | 'application';
16
+ /**
17
+ * Application-mode HTML policy (binding J1.0, measured on the real immo UI
18
+ * build): same-origin module workers, runtime-injected styles, blob media.
19
+ * No `unsafe-eval`, no `wasm-unsafe-eval`, no `blob:` worker. Kept as one
20
+ * constant so the conductor can relay adjustments.
21
+ */
22
+ export declare const APPLICATION_HTML_CSP: string;
14
23
  export interface ContentHeaderInput {
15
24
  mimeType: string;
16
25
  size: number;
17
26
  /** Explicit host opt-in for non-HTML asset caching (seconds). */
18
27
  assetCacheSeconds?: number;
28
+ /** Host-configured mode: `safe` (default, historic strict) or `application` (J1.0 policy). */
29
+ mode?: ContentMode;
30
+ /** Per-release inline script hashes, application mode only. */
31
+ scriptHashes?: readonly string[];
19
32
  }
20
33
  /** Security/cache headers for one served file (declared MIME wins). */
21
34
  export declare function contentHeaders(input: ContentHeaderInput): Record<string, string>;
@@ -11,7 +11,7 @@
11
11
  * prefix: Secure, Path=/, no Domain attribute).
12
12
  */
13
13
  export const GRANT_COOKIE_NAME = '__Host-artifacts_grant';
14
- const HTML_CSP = [
14
+ const SAFE_HTML_CSP = [
15
15
  "default-src 'self'",
16
16
  "script-src 'self' 'unsafe-inline'",
17
17
  "style-src 'self' 'unsafe-inline'",
@@ -23,6 +23,39 @@ const HTML_CSP = [
23
23
  "form-action 'none'",
24
24
  "frame-ancestors 'none'",
25
25
  ].join('; ');
26
+ /**
27
+ * Application-mode HTML policy (binding J1.0, measured on the real immo UI
28
+ * build): same-origin module workers, runtime-injected styles, blob media.
29
+ * No `unsafe-eval`, no `wasm-unsafe-eval`, no `blob:` worker. Kept as one
30
+ * constant so the conductor can relay adjustments.
31
+ */
32
+ export const APPLICATION_HTML_CSP = [
33
+ "default-src 'self'",
34
+ "script-src 'self'",
35
+ "style-src 'self' 'unsafe-inline'",
36
+ "img-src 'self' data: blob:",
37
+ "font-src 'self'",
38
+ "media-src 'self' blob:",
39
+ "connect-src 'self'",
40
+ "worker-src 'self'",
41
+ "child-src 'self'",
42
+ "frame-src 'none'",
43
+ "frame-ancestors 'none'",
44
+ "object-src 'none'",
45
+ "base-uri 'none'",
46
+ "form-action 'none'",
47
+ ].join('; ');
48
+ const SCRIPT_HASH_RE = /^'sha256-[A-Za-z0-9+/=]+'$/;
49
+ /** Application policy with per-release inline script hashes appended to `script-src` only. */
50
+ function applicationCsp(scriptHashes) {
51
+ if (scriptHashes === undefined || scriptHashes.length === 0)
52
+ return APPLICATION_HTML_CSP;
53
+ for (const hash of scriptHashes) {
54
+ if (!SCRIPT_HASH_RE.test(hash))
55
+ throw new Error(`invalid inline script hash: ${hash}`);
56
+ }
57
+ return APPLICATION_HTML_CSP.replace("script-src 'self'", `script-src 'self' ${scriptHashes.join(' ')}`);
58
+ }
26
59
  /**
27
60
  * Active-content types that can script or navigate when navigated to
28
61
  * directly get a sandboxed CSP in addition to `nosniff`: SVG (validated at
@@ -38,6 +71,11 @@ export function contentHeaders(input) {
38
71
  const isHtml = mimeType === 'text/html';
39
72
  const withCharset = mimeType.startsWith('text/') ? `${mimeType}; charset=utf-8` : mimeType;
40
73
  const cacheable = !isHtml && input.assetCacheSeconds !== undefined && input.assetCacheSeconds > 0;
74
+ const mode = input.mode ?? 'safe';
75
+ // Workers enforce the script response's policy, not the document's CSP.
76
+ // Cover every application asset so alternate JavaScript MIME types cannot bypass it.
77
+ const csp = mode === 'application' ? applicationCsp(isHtml ? input.scriptHashes : undefined)
78
+ : isHtml ? SAFE_HTML_CSP : undefined;
41
79
  return {
42
80
  'content-type': withCharset,
43
81
  'content-length': String(input.size),
@@ -46,7 +84,7 @@ export function contentHeaders(input) {
46
84
  'cache-control': cacheable ? `private, max-age=${input.assetCacheSeconds}` : 'no-store',
47
85
  'x-frame-options': 'DENY',
48
86
  'referrer-policy': 'no-referrer',
49
- ...(isHtml ? { 'content-security-policy': HTML_CSP } : {}),
87
+ ...(csp === undefined ? {} : { 'content-security-policy': csp }),
50
88
  ...(SANDBOXED_MIME_TYPES.has(mimeType) ? { 'content-security-policy': SANDBOX_CSP } : {}),
51
89
  };
52
90
  }