@dreamlake/dreamlake-cli 0.104.3 → 0.104.4

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.
@@ -13,6 +13,7 @@ export interface ArtifactPushArgs extends DreamlakeOpts {
13
13
  entry?: string;
14
14
  site?: boolean;
15
15
  spa?: boolean;
16
+ siteConfig?: string;
16
17
  title?: string;
17
18
  kind?: string;
18
19
  artifactId?: string;
@@ -1,3 +1,4 @@
1
+ import { readSiteConfig } from './siteConfig.js';
1
2
  import { collectionList } from "../collection-list.js";
2
3
  import { registerShareCommands } from "../share.js";
3
4
  // `dreamlake artifact push|list|delete|restore`.
@@ -94,6 +95,8 @@ export async function runDreamlakeArtifactPush(args, deps = {}) {
94
95
  directory = stat.isDirectory();
95
96
  if (args.site && !directory)
96
97
  throw new Error('--site requires a built static directory');
98
+ if (args.siteConfig && !args.site)
99
+ throw new Error('--site-config requires --site');
97
100
  if (args.spa && !args.site)
98
101
  throw new Error('--spa requires --site');
99
102
  if (!directory && !stat.isFile())
@@ -106,7 +109,7 @@ export async function runDreamlakeArtifactPush(args, deps = {}) {
106
109
  fail("incremental artifacts are limited to 512 MiB");
107
110
  return 1;
108
111
  }
109
- site = args.site ? collectSite(args.file, args.entry, args.spa) : undefined;
112
+ site = args.site ? collectSite(args.file, args.entry, args.spa, readSiteConfig(args.siteConfig)) : undefined;
110
113
  content = site ? site.content : directory ? packPages(args.file, args.entry) : readFileSync(args.file);
111
114
  }
112
115
  catch (error) {
@@ -150,7 +153,9 @@ export async function runDreamlakeArtifactPush(args, deps = {}) {
150
153
  return 1;
151
154
  if (site) {
152
155
  const capability = await jsonRequest('GET', `${ctx.remote}/artifacts/site-capabilities`, token);
153
- if (capability.status !== 200 || capability.body?.schema !== 'dreamlake-artifact-files/1') {
156
+ const caps = capability.body;
157
+ const needsPublicData = site.manifest.schema === 'dreamlake-artifact-files/2';
158
+ if (capability.status !== 200 || caps?.schema !== 'dreamlake-artifact-files/1' || (needsPublicData && (!caps.supportedSchemas?.includes('dreamlake-artifact-files/2') || caps.features?.publicDataOrigins !== true))) {
154
159
  fail('Static artifact hosting is unavailable on this server; no files were uploaded.');
155
160
  return 1;
156
161
  }
@@ -224,6 +229,12 @@ export async function runDreamlakeArtifactPush(args, deps = {}) {
224
229
  let storedContent = content;
225
230
  if (site) {
226
231
  const result = await uploadSite(site, backend);
232
+ if (site.manifest.schema === 'dreamlake-artifact-files/2') {
233
+ const grant = await jsonRequest('POST', `${ctx.remote}/namespaces/${encodeURIComponent(namespace)}/artifacts/${encodeURIComponent(artifactId)}/site-public-data-grants`, token, { manifest: site.hash });
234
+ const binding = grant.body;
235
+ if (grant.status !== 200 || binding?.manifest !== site.hash || JSON.stringify(binding.origins) !== JSON.stringify(site.manifest.network?.publicDataOrigins))
236
+ throw new Error('Public data authorization failed; no artifact version was published. Owner or Project ADMIN access is required.');
237
+ }
227
238
  process.stdout.write(` site: ${site.manifest.files.length} files, ${result.uploadedFiles} new files, ${result.uploadedBytes} bytes uploaded\n`);
228
239
  }
229
240
  else if (incremental) {
@@ -403,6 +414,7 @@ export function registerArtifactCommand(program) {
403
414
  .argument("<file>", "file or self-contained HTML page directory to push")
404
415
  .option("--entry <path>", "entry page for a directory (default: index.html)")
405
416
  .option("--site", "upload a static build with files loaded on demand (requires site hosting)")
417
+ .option("--site-config <file>", "site network configuration (default: ./artifact.config.json when present)")
406
418
  .option("--spa", "serve the site entry for extensionless client routes (requires --site)")
407
419
  .option("--title <title>", "human title (default: file stem)")
408
420
  .option("--kind <kind>", "html, react, markdown, svg, code, mermaid (default: auto)")
@@ -1,7 +1,7 @@
1
1
  import { type DreamdbBackend, type UploadFile } from '../compat/s3-backend.js';
2
2
  import { type SiteManifest } from './siteFormat.js';
3
3
  /** Snapshot the manifest before any network writes; retain file metadata, not media buffers. */
4
- export declare function collectSite(directory: string, entry?: string, spa?: boolean): {
4
+ export declare function collectSite(directory: string, entry?: string, spa?: boolean, publicDataOrigins?: string[]): {
5
5
  manifest: SiteManifest;
6
6
  objects: Map<string, UploadFile>;
7
7
  json: Buffer<ArrayBuffer>;
@@ -2,7 +2,7 @@ import { closeSync, constants, fstatSync, lstatSync, openSync, readdirSync, read
2
2
  import path from 'node:path';
3
3
  import { createHash } from 'node:crypto';
4
4
  import { S3_SINGLE_PUT_MAX_BYTES } from '../compat/s3-backend.js';
5
- import { encodeSiteDescriptor, SITE_MAX_FILES, SITE_MANIFEST_MAX_BYTES, siteFileKey, siteManifestKey, validSitePath, validateSiteManifest } from './siteFormat.js';
5
+ import { encodeSiteDescriptor, SITE_MAX_FILES, SITE_MANIFEST_MAX_BYTES, siteFileKey, siteManifestKey, validSitePath, validateSiteManifest, validatePublicDataOrigins } from './siteFormat.js';
6
6
  const sha = (bytes) => createHash('sha256').update(bytes).digest('hex');
7
7
  /** Hash with bounded memory; a signed upload rejects source changes before publication. */
8
8
  function inspectFile(file, html) {
@@ -35,10 +35,15 @@ function inspectFile(file, html) {
35
35
  }
36
36
  }
37
37
  /** Snapshot the manifest before any network writes; retain file metadata, not media buffers. */
38
- export function collectSite(directory, entry = 'index.html', spa = false) {
38
+ export function collectSite(directory, entry = 'index.html', spa = false, publicDataOrigins = []) {
39
39
  if (!lstatSync(directory).isDirectory())
40
40
  throw new Error('Site must be a directory, not a symlink');
41
41
  const manifest = { schema: 'dreamlake-artifact-files/1', entry, spa, files: [] };
42
+ const origins = validatePublicDataOrigins(publicDataOrigins);
43
+ if (origins.length) {
44
+ manifest.schema = 'dreamlake-artifact-files/2';
45
+ manifest.network = { publicDataOrigins: origins };
46
+ }
42
47
  const objects = new Map();
43
48
  let bytes = 0;
44
49
  let visited = 0;
@@ -79,7 +84,7 @@ export function collectSite(directory, entry = 'index.html', spa = false) {
79
84
  if (json.length > SITE_MANIFEST_MAX_BYTES)
80
85
  throw new Error('Artifact manifest exceeds 2 MiB');
81
86
  const hash = sha(json);
82
- return { manifest, objects, json, hash, content: Buffer.from(encodeSiteDescriptor(hash)), bytes };
87
+ return { manifest, objects, json, hash, content: Buffer.from(encodeSiteDescriptor(hash, manifest.schema)), bytes };
83
88
  }
84
89
  /** Conditional immutable writes; publish the manifest only after every file exists. */
85
90
  export async function uploadSite(site, backend) {
@@ -0,0 +1 @@
1
+ export declare function readSiteConfig(file?: string): string[];
@@ -0,0 +1,15 @@
1
+ import { existsSync, lstatSync, readFileSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { validatePublicDataOrigins } from './siteFormat.js';
4
+ export function readSiteConfig(file) {
5
+ const target = file ?? path.resolve('artifact.config.json');
6
+ if (!file && !existsSync(target))
7
+ return [];
8
+ const stat = lstatSync(target);
9
+ if (!stat.isFile() || stat.size > 16 * 1024)
10
+ throw new Error('Site configuration must be a regular file of at most 16 KiB');
11
+ const config = JSON.parse(readFileSync(target, 'utf8'));
12
+ if (config?.schema !== 'dreamlake-artifact-config/1' || Object.keys(config).some(key => !['schema', 'network'].includes(key)) || !config.network || Object.keys(config.network).some(key => key !== 'publicDataOrigins'))
13
+ throw new Error('Invalid artifact site configuration');
14
+ return validatePublicDataOrigins(config.network.publicDataOrigins);
15
+ }
@@ -1,4 +1,5 @@
1
1
  export declare const SITE_PREFIX = "<!--DREAMLAKE-ARTIFACT-FILES/1-->\n<script type=\"application/json\" id=\"dreamlake-artifact-files\">";
2
+ export declare const SITE_V2_PREFIX: string;
2
3
  export declare const SITE_SUFFIX = "</script>\n<p>This artifact requires a viewer with static-site support.</p>";
3
4
  export declare const SITE_MAX_FILES = 4096;
4
5
  export declare const SITE_MANIFEST_MAX_BYTES: number;
@@ -8,7 +9,10 @@ export interface SiteFile {
8
9
  size: number;
9
10
  }
10
11
  export interface SiteManifest {
11
- schema: 'dreamlake-artifact-files/1';
12
+ schema: 'dreamlake-artifact-files/1' | 'dreamlake-artifact-files/2';
13
+ network?: {
14
+ publicDataOrigins: string[];
15
+ };
12
16
  entry: string;
13
17
  spa: boolean;
14
18
  files: SiteFile[];
@@ -19,7 +23,8 @@ export interface SiteDescriptor {
19
23
  export declare const isHash: (s: unknown) => s is string;
20
24
  export declare function validSitePath(s: unknown): s is string;
21
25
  export declare function validateSiteManifest(value: unknown): SiteManifest;
22
- export declare function encodeSiteDescriptor(manifest: string): string;
26
+ export declare function encodeSiteDescriptor(manifest: string, schema?: SiteManifest['schema']): string;
23
27
  export declare function decodeSiteDescriptor(content: string): SiteDescriptor | null;
24
28
  export declare const siteManifestKey: (hash: string) => string;
25
29
  export declare const siteFileKey: (hash: string) => string;
30
+ export declare function validatePublicDataOrigins(value: unknown): string[];
@@ -1,6 +1,7 @@
1
1
  // Wire contract shared with dreamlake-server/src/services/artifactSiteFormat.ts
2
2
  // and dreamlake-ai/frame/siteFormat.ts. Never change v1 in place.
3
3
  export const SITE_PREFIX = '<!--DREAMLAKE-ARTIFACT-FILES/1-->\n<script type="application/json" id="dreamlake-artifact-files">';
4
+ export const SITE_V2_PREFIX = SITE_PREFIX.replace('FILES/1', 'FILES/2');
4
5
  export const SITE_SUFFIX = '</script>\n<p>This artifact requires a viewer with static-site support.</p>';
5
6
  export const SITE_MAX_FILES = 4096;
6
7
  export const SITE_MANIFEST_MAX_BYTES = 2 * 1024 * 1024;
@@ -13,10 +14,17 @@ export function validSitePath(s) {
13
14
  }
14
15
  export function validateSiteManifest(value) {
15
16
  const m = value;
16
- if (!m || m.schema !== 'dreamlake-artifact-files/1' || !validSitePath(m.entry) ||
17
+ if (!m || !['dreamlake-artifact-files/1', 'dreamlake-artifact-files/2'].includes(m.schema) || !validSitePath(m.entry) ||
17
18
  !/\.html?$/i.test(m.entry) || typeof m.spa !== 'boolean' || !Array.isArray(m.files) ||
18
19
  !m.files.length || m.files.length > SITE_MAX_FILES)
19
20
  throw new Error('Invalid artifact site manifest');
21
+ if (m.schema === 'dreamlake-artifact-files/2') {
22
+ const origins = validatePublicDataOrigins(m.network?.publicDataOrigins);
23
+ if (!origins.length || JSON.stringify(origins) !== JSON.stringify(m.network?.publicDataOrigins))
24
+ throw new Error('Non-canonical public data origins');
25
+ }
26
+ else if (m.network !== undefined)
27
+ throw new Error('Network declarations require artifact site v2');
20
28
  const paths = new Set();
21
29
  let total = 0;
22
30
  for (const f of m.files) {
@@ -34,20 +42,34 @@ export function validateSiteManifest(value) {
34
42
  throw new Error('Artifact entry page is missing');
35
43
  return m;
36
44
  }
37
- export function encodeSiteDescriptor(manifest) {
45
+ export function encodeSiteDescriptor(manifest, schema = 'dreamlake-artifact-files/1') {
38
46
  if (!isHash(manifest))
39
47
  throw new Error('Invalid artifact manifest hash');
40
- return SITE_PREFIX + JSON.stringify({ manifest }) + SITE_SUFFIX;
48
+ return (schema === 'dreamlake-artifact-files/2' ? SITE_V2_PREFIX : SITE_PREFIX) + JSON.stringify({ manifest }) + SITE_SUFFIX;
41
49
  }
42
50
  export function decodeSiteDescriptor(content) {
43
51
  if (!content.startsWith('<!--DREAMLAKE-ARTIFACT-FILES/'))
44
52
  return null;
45
- if (!content.startsWith(SITE_PREFIX) || !content.endsWith(SITE_SUFFIX) || content.length > 4096)
53
+ const prefix = content.startsWith(SITE_V2_PREFIX) ? SITE_V2_PREFIX : SITE_PREFIX;
54
+ if (!content.startsWith(prefix) || !content.endsWith(SITE_SUFFIX) || content.length > 4096)
46
55
  throw new Error('Unsupported artifact site format');
47
- const value = JSON.parse(content.slice(SITE_PREFIX.length, -SITE_SUFFIX.length));
56
+ const value = JSON.parse(content.slice(prefix.length, -SITE_SUFFIX.length));
48
57
  if (!isHash(value?.manifest))
49
58
  throw new Error('Invalid artifact manifest hash');
50
59
  return { manifest: value.manifest };
51
60
  }
52
61
  export const siteManifestKey = (hash) => `artifact-files/v1/manifests/${hash}.json`;
53
62
  export const siteFileKey = (hash) => `artifact-files/v1/objects/${hash}`;
63
+ export function validatePublicDataOrigins(value) {
64
+ if (!Array.isArray(value) || value.length > 16)
65
+ throw new Error('publicDataOrigins must contain at most 16 HTTPS origins');
66
+ const origins = value.map(origin => {
67
+ if (typeof origin !== 'string' || origin.length > 2048)
68
+ throw new Error('Invalid public data origin');
69
+ const url = new URL(origin);
70
+ if (url.protocol !== 'https:' || url.port || !/^(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/.test(url.hostname) || url.username || url.password || url.search || url.hash || url.pathname !== '/' || origin.includes('*') || url.hostname === 'localhost' || url.hostname.endsWith('.localhost') || url.hostname.includes(':') || /^\d+\.\d+\.\d+\.\d+$/.test(url.hostname))
71
+ throw new Error('Public data origins require exact HTTPS hostnames without paths or credentials');
72
+ return url.origin;
73
+ });
74
+ return [...new Set(origins)].sort();
75
+ }
@@ -1 +1 @@
1
- export declare const VERSION = "0.104.3";
1
+ export declare const VERSION = "0.104.4";
@@ -6,4 +6,4 @@
6
6
  // value means a binary that re-installs the same version forever.
7
7
  //
8
8
  // Editing this by hand does nothing for a release; bump package.json.
9
- export const VERSION = "0.104.3";
9
+ export const VERSION = "0.104.4";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreamlake/dreamlake-cli",
3
- "version": "0.104.3",
3
+ "version": "0.104.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/dreamlake-ai/dreamlake-cli.git"
@@ -36,13 +36,13 @@
36
36
  "node": ">=18"
37
37
  },
38
38
  "optionalDependencies": {
39
- "@dreamlake/dreamlake-cli-darwin-arm64": "0.104.3",
40
- "@dreamlake/dreamlake-cli-darwin-x64": "0.104.3",
41
- "@dreamlake/dreamlake-cli-linux-x64": "0.104.3",
42
- "@dreamlake/dreamlake-cli-linux-arm64": "0.104.3",
43
- "@dreamlake/dreamlake-cli-linux-x64-musl": "0.104.3",
44
- "@dreamlake/dreamlake-cli-linux-arm64-musl": "0.104.3",
45
- "@dreamlake/dreamlake-cli-win32-x64": "0.104.3",
46
- "@dreamlake/dreamlake-cli-win32-arm64": "0.104.3"
39
+ "@dreamlake/dreamlake-cli-darwin-arm64": "0.104.4",
40
+ "@dreamlake/dreamlake-cli-darwin-x64": "0.104.4",
41
+ "@dreamlake/dreamlake-cli-linux-x64": "0.104.4",
42
+ "@dreamlake/dreamlake-cli-linux-arm64": "0.104.4",
43
+ "@dreamlake/dreamlake-cli-linux-x64-musl": "0.104.4",
44
+ "@dreamlake/dreamlake-cli-linux-arm64-musl": "0.104.4",
45
+ "@dreamlake/dreamlake-cli-win32-x64": "0.104.4",
46
+ "@dreamlake/dreamlake-cli-win32-arm64": "0.104.4"
47
47
  }
48
48
  }