sandcms 0.6.3 → 0.8.0

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 (175) hide show
  1. package/README.md +15 -11
  2. package/dist/admin/Account.svelte +2 -0
  3. package/dist/admin/Admin.svelte +21 -6
  4. package/dist/admin/AssetAttachment.svelte +9 -6
  5. package/dist/admin/AssetAttachment.svelte.d.ts +3 -1
  6. package/dist/admin/BlueprintFields.svelte +0 -3
  7. package/dist/admin/BlueprintFields.svelte.d.ts +0 -1
  8. package/dist/admin/Editor.svelte +5 -10
  9. package/dist/admin/Fields.svelte +2 -8
  10. package/dist/admin/Fields.svelte.d.ts +0 -1
  11. package/dist/admin/Gallery.svelte +221 -80
  12. package/dist/admin/Gallery.svelte.d.ts +0 -1
  13. package/dist/admin/Inbox.svelte +3 -2
  14. package/dist/admin/LinkField.svelte +0 -3
  15. package/dist/admin/LinkField.svelte.d.ts +0 -1
  16. package/dist/admin/MediaLibrary.svelte +10 -7
  17. package/dist/admin/MediaPicker.svelte +43 -35
  18. package/dist/admin/MediaPicker.svelte.d.ts +0 -1
  19. package/dist/admin/Navigation.svelte +13 -2
  20. package/dist/admin/Pages.svelte +195 -0
  21. package/dist/admin/Pages.svelte.d.ts +7 -0
  22. package/dist/admin/Shell.svelte +27 -5
  23. package/dist/admin/SortableList.svelte +82 -61
  24. package/dist/admin/SortableList.svelte.d.ts +3 -1
  25. package/dist/admin/ThemePicker.svelte +72 -0
  26. package/dist/admin/ThemePicker.svelte.d.ts +18 -0
  27. package/dist/admin/UploadButton.svelte +2 -1
  28. package/dist/admin/UploadProgress.svelte +24 -0
  29. package/dist/admin/UploadProgress.svelte.d.ts +7 -0
  30. package/dist/admin/Users.svelte +8 -3
  31. package/dist/admin/client.d.ts +3 -670
  32. package/dist/admin/client.js +2 -1
  33. package/dist/admin/components/ui/alert/alert.svelte.d.ts +3 -13
  34. package/dist/admin/components/ui/attachment/attachment-media.svelte.d.ts +3 -13
  35. package/dist/admin/components/ui/attachment/attachment.svelte.d.ts +6 -26
  36. package/dist/admin/components/ui/badge/badge.svelte.d.ts +7 -25
  37. package/dist/admin/components/ui/button/button.svelte.d.ts +15 -53
  38. package/dist/admin/components/ui/toggle/toggle.svelte.d.ts +6 -26
  39. package/dist/admin/generated/admin.css +823 -115
  40. package/dist/admin/navigation.d.ts +9 -0
  41. package/dist/admin/navigation.js +20 -1
  42. package/dist/admin/theme-context.d.ts +7 -0
  43. package/dist/admin/theme-context.js +3 -0
  44. package/dist/admin/theme.d.ts +7 -0
  45. package/dist/admin/theme.js +14 -0
  46. package/dist/admin/types.d.ts +3 -1
  47. package/dist/admin/uploads.d.ts +8 -1
  48. package/dist/admin/uploads.js +94 -16
  49. package/dist/blueprints/files.js +1 -0
  50. package/dist/blueprints/labels.d.ts +6 -0
  51. package/dist/blueprints/labels.js +14 -0
  52. package/dist/blueprints/load.js +16 -2
  53. package/dist/blueprints/types.d.ts +4 -1
  54. package/dist/cli/admin.d.ts +39 -0
  55. package/dist/cli/admin.js +95 -0
  56. package/dist/cli/backup.js +4 -4
  57. package/dist/cli/doctor.d.ts +10 -1
  58. package/dist/cli/doctor.js +98 -33
  59. package/dist/cli/email-test.d.ts +3 -0
  60. package/dist/cli/email-test.js +20 -0
  61. package/dist/cli/files.d.ts +2 -6
  62. package/dist/cli/files.js +12 -2
  63. package/dist/cli/index.js +401 -95
  64. package/dist/cli/rebaseline.d.ts +10 -0
  65. package/dist/cli/rebaseline.js +117 -0
  66. package/dist/cli/scaffold.js +8 -8
  67. package/dist/cli/setup.js +16 -26
  68. package/dist/cli/upgrade.js +34 -7
  69. package/dist/env.d.ts +26 -2
  70. package/dist/env.js +48 -6
  71. package/dist/notification-fields.js +2 -1
  72. package/dist/server/admin-load.d.ts +85 -5
  73. package/dist/server/admin-load.js +26 -1
  74. package/dist/server/api-access.d.ts +4 -0
  75. package/dist/server/api-access.js +15 -2
  76. package/dist/server/api-keys.d.ts +96 -0
  77. package/dist/server/api-keys.js +115 -0
  78. package/dist/server/api-pagination.d.ts +3 -0
  79. package/dist/server/api.js +21 -63
  80. package/dist/server/auth.d.ts +10 -9
  81. package/dist/server/cms.d.ts +63 -21
  82. package/dist/server/cms.js +64 -7
  83. package/dist/server/db/auto-migrate.d.ts +0 -4
  84. package/dist/server/db/auto-migrate.js +12 -3
  85. package/dist/server/db/legacy.d.ts +13 -0
  86. package/dist/server/db/legacy.js +60 -0
  87. package/dist/server/db/migration-data.js +2 -34
  88. package/dist/server/db/migrations/{0000_foundation.sql → 0000_baseline.sql} +120 -4
  89. package/dist/server/db/migrations/meta/0000_snapshot.json +578 -3
  90. package/dist/server/db/migrations/meta/_journal.json +2 -58
  91. package/dist/server/db/schema.d.ts +119 -2
  92. package/dist/server/db/schema.js +23 -9
  93. package/dist/server/db/store.d.ts +25 -2
  94. package/dist/server/db/store.js +90 -26
  95. package/dist/server/forms.js +2 -1
  96. package/dist/server/hooks.js +155 -81
  97. package/dist/server/media/contracts.d.ts +115 -0
  98. package/dist/server/media/contracts.js +12 -0
  99. package/dist/server/media/deletions.d.ts +2 -1
  100. package/dist/server/media/deletions.js +3 -3
  101. package/dist/server/media/delivery.js +7 -11
  102. package/dist/server/media/processor-child.d.ts +2 -0
  103. package/dist/server/media/processor-child.js +236 -0
  104. package/dist/server/media/processor.d.ts +51 -0
  105. package/dist/server/media/processor.js +135 -0
  106. package/dist/server/media/render-math.d.ts +24 -0
  107. package/dist/server/media/render-math.js +50 -0
  108. package/dist/server/media/runner.d.ts +30 -1
  109. package/dist/server/media/runner.js +418 -165
  110. package/dist/server/media/service.d.ts +53 -11
  111. package/dist/server/media/service.js +307 -98
  112. package/dist/server/media/storage.d.ts +5 -0
  113. package/dist/server/media/storage.js +279 -0
  114. package/dist/server/media/upload-ticket.d.ts +12 -0
  115. package/dist/server/media/upload-ticket.js +35 -0
  116. package/dist/server/media/verify.d.ts +64 -0
  117. package/dist/server/media/verify.js +201 -0
  118. package/dist/server/platform/http.d.ts +27 -0
  119. package/dist/server/platform/http.js +77 -0
  120. package/dist/server/platform/index.d.ts +52 -0
  121. package/dist/server/platform/index.js +98 -0
  122. package/dist/server/platform/snapshots.d.ts +18 -0
  123. package/dist/server/platform/snapshots.js +110 -0
  124. package/dist/server/platform/volume.d.ts +20 -0
  125. package/dist/server/platform/volume.js +60 -0
  126. package/docs/acceptance.md +7 -5
  127. package/docs/api.md +56 -4
  128. package/docs/cloudflare.md +26 -152
  129. package/docs/content.md +20 -5
  130. package/docs/deployment.md +222 -57
  131. package/docs/email.md +6 -0
  132. package/docs/forms.md +2 -2
  133. package/docs/media.md +94 -21
  134. package/docs/package.md +21 -18
  135. package/docs/plans/0.7-self-hosted.md +264 -0
  136. package/docs/releases.md +37 -1
  137. package/docs/upgrades.md +72 -9
  138. package/package.json +37 -44
  139. package/templates/Dockerfile +32 -0
  140. package/templates/integration.ts +26 -5
  141. package/templates/openship.json +9 -0
  142. package/templates/railpack.json +1 -1
  143. package/templates/sandcms/blueprints/files/image.yaml +1 -1
  144. package/templates/sandcms/config.yaml +1 -1
  145. package/dist/cli/cloudflare.d.ts +0 -8
  146. package/dist/cli/cloudflare.js +0 -135
  147. package/dist/server/db/migrations/0001_independent_password_resets.sql +0 -3
  148. package/dist/server/db/migrations/0002_email_failure_reason.sql +0 -1
  149. package/dist/server/db/migrations/0003_direct_r2_uploads.sql +0 -10
  150. package/dist/server/db/migrations/0004_agent_api_keys.sql +0 -38
  151. package/dist/server/db/migrations/0005_api_retention_and_pagination.sql +0 -3
  152. package/dist/server/db/migrations/0006_durable_media_deletion.sql +0 -7
  153. package/dist/server/db/migrations/0007_content_and_job_indexes.sql +0 -2
  154. package/dist/server/db/migrations/0008_search_text_cache.sql +0 -45
  155. package/dist/server/db/migrations/meta/0001_snapshot.json +0 -1197
  156. package/dist/server/db/migrations/meta/0002_snapshot.json +0 -1204
  157. package/dist/server/db/migrations/meta/0003_snapshot.json +0 -1281
  158. package/dist/server/db/migrations/meta/0004_snapshot.json +0 -1546
  159. package/dist/server/db/migrations/meta/0005_snapshot.json +0 -1572
  160. package/dist/server/db/migrations/meta/0006_snapshot.json +0 -1627
  161. package/dist/server/db/migrations/meta/0007_snapshot.json +0 -1643
  162. package/dist/server/db/migrations/meta/0008_snapshot.json +0 -1711
  163. package/dist/worker/index.d.ts +0 -10
  164. package/dist/worker/index.js +0 -460
  165. package/dist/worker/local.d.ts +0 -5
  166. package/dist/worker/local.js +0 -57
  167. package/dist/worker/source.d.ts +0 -2
  168. package/dist/worker/source.js +0 -31
  169. package/dist/worker/uploads.d.ts +0 -22
  170. package/dist/worker/uploads.js +0 -48
  171. package/templates/sandcms/worker/index.ts +0 -1
  172. package/templates/sandcms/worker/local.ts +0 -1
  173. package/templates/sandcms/worker/wrangler.jsonc +0 -6
  174. /package/dist/{worker → server/media}/svg.d.ts +0 -0
  175. /package/dist/{worker → server/media}/svg.js +0 -0
@@ -0,0 +1,117 @@
1
+ import { Database } from 'bun:sqlite';
2
+ import { chmodSync, existsSync, renameSync, unlinkSync } from 'node:fs';
3
+ import { applyMigrations, databasePath, schemaHistory, volumeGuard } from '../server/db/store.js';
4
+ import { legacyHistory } from '../server/db/legacy.js';
5
+ // Derived rows: the media insert trigger recreates them while media is copied.
6
+ const DERIVED = new Set(['media_document_links']);
7
+ const quote = (name) => `"${name.replaceAll('"', '""')}"`;
8
+ /**
9
+ * Convert a SandCMS 0.7.x database (the retired 0000–0009 migration history) into a fresh database built
10
+ * from the 0.8.0 baseline, copying every row. Media files are untouched. The website must be stopped; a
11
+ * verified safety copy of the old database is kept next to it.
12
+ */
13
+ export function rebaseline(database, confirmed = false) {
14
+ const target = databasePath(database);
15
+ if (!confirmed)
16
+ throw new Error(`Rebaseline requires explicit confirmation for ${target}`);
17
+ if (!existsSync(target))
18
+ throw new Error('Database does not exist');
19
+ const guard = volumeGuard(target, true);
20
+ const safety = `${target}.before-rebaseline-${Date.now()}.sqlite`, staged = `${target}.rebaseline-${crypto.randomUUID()}`;
21
+ try {
22
+ const legacy = new Database(target);
23
+ try {
24
+ legacy.exec('PRAGMA busy_timeout=0; PRAGMA wal_checkpoint(TRUNCATE);');
25
+ const state = legacyHistory(legacy);
26
+ if (state !== 'complete')
27
+ throw new Error(state === 'outdated'
28
+ ? 'Database was created by SandCMS 0.6 or older. Upgrade it with SandCMS 0.7.x first, then run sandcms rebaseline.'
29
+ : 'Database does not have the SandCMS 0.7 migration history; nothing to rebaseline.');
30
+ assertHealthy(legacy, 'Database');
31
+ legacy.query('VACUUM INTO ?').run(safety);
32
+ chmodSync(safety, 0o600);
33
+ }
34
+ finally {
35
+ legacy.close();
36
+ }
37
+ const copied = copyInto(staged, safety);
38
+ for (const suffix of ['-wal', '-shm'])
39
+ if (existsSync(target + suffix))
40
+ unlinkSync(target + suffix);
41
+ renameSync(staged, target);
42
+ return { target, safety, copied };
43
+ }
44
+ catch (cause) {
45
+ if (existsSync(staged))
46
+ unlinkSync(staged);
47
+ throw cause;
48
+ }
49
+ finally {
50
+ guard?.close();
51
+ }
52
+ }
53
+ function assertHealthy(db, label) {
54
+ const integrity = db.query('PRAGMA integrity_check').get();
55
+ if (integrity.integrity_check !== 'ok')
56
+ throw new Error(`${label} failed integrity check`);
57
+ if (db.query('PRAGMA foreign_key_check').all().length)
58
+ throw new Error(`${label} contains invalid references`);
59
+ }
60
+ function tables(db, schema) {
61
+ return db
62
+ .query(`SELECT name FROM ${schema}.sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%' AND name != 'schema_migrations' ORDER BY name`)
63
+ .all().map((t) => t.name);
64
+ }
65
+ function columns(db, schema, table) {
66
+ return db.query(`PRAGMA ${schema}.table_info(${quote(table)})`).all().map((c) => c.name);
67
+ }
68
+ function count(db, sql) {
69
+ return db.query(`SELECT count(*) AS n FROM (${sql})`).get().n;
70
+ }
71
+ /** Build the baseline in `staged`, copy every legacy row, verify, and return row counts per table. */
72
+ function copyInto(staged, source) {
73
+ const db = new Database(staged, { create: true });
74
+ try {
75
+ chmodSync(staged, 0o600);
76
+ applyMigrations({ sqlite: db });
77
+ db.exec('PRAGMA foreign_keys=OFF');
78
+ db.query('ATTACH DATABASE ? AS legacy').run(source);
79
+ const copied = {};
80
+ db.transaction(() => {
81
+ const current = tables(db, 'main');
82
+ for (const table of tables(db, 'legacy'))
83
+ if (!current.includes(table) && count(db, `SELECT 1 FROM legacy.${quote(table)}`))
84
+ throw new Error(`Table ${table} has rows but no place in the new schema`);
85
+ for (const table of current) {
86
+ if (!tables(db, 'legacy').includes(table))
87
+ continue;
88
+ const target = columns(db, 'main', table), source = columns(db, 'legacy', table);
89
+ const lost = source.filter((c) => !target.includes(c));
90
+ if (lost.length)
91
+ throw new Error(`Columns ${table}.${lost.join(', ')} have no place`);
92
+ const list = source.map(quote).join(', '), name = quote(table);
93
+ db.exec(`INSERT ${DERIVED.has(table) ? 'OR IGNORE ' : ''}INTO main.${name} (${list}) SELECT ${list} FROM legacy.${name}`);
94
+ const legacyRows = `SELECT ${list} FROM legacy.${name}`, newRows = `SELECT ${list} FROM main.${name}`;
95
+ if (count(db, `${legacyRows} EXCEPT ${newRows}`))
96
+ throw new Error(`Rows of ${table} were not copied exactly`);
97
+ if (!DERIVED.has(table) && count(db, `${newRows} EXCEPT ${legacyRows}`))
98
+ throw new Error(`Rows of ${table} differ after copying`);
99
+ copied[table] = count(db, `SELECT 1 FROM main.${name}`);
100
+ if (!DERIVED.has(table) && copied[table] !== count(db, legacyRows))
101
+ throw new Error(`Row count of ${table} differs after copying`);
102
+ }
103
+ if (db.query('PRAGMA main.foreign_key_check').all().length)
104
+ throw new Error('Copied rows contain invalid references');
105
+ })();
106
+ db.exec('DETACH DATABASE legacy');
107
+ db.exec('PRAGMA foreign_keys=ON');
108
+ assertHealthy(db, 'Rebaselined database');
109
+ const history = schemaHistory(db);
110
+ if (history.pending.length || history.ahead.length)
111
+ throw new Error('Rebaselined database is not at the current schema');
112
+ return copied;
113
+ }
114
+ finally {
115
+ db.close();
116
+ }
117
+ }
@@ -22,7 +22,7 @@ export function scaffold(root, name, packageSource) {
22
22
  private: true,
23
23
  type: 'module',
24
24
  imports: { '#lib': './src/lib/index.ts', '#lib/*': './src/lib/*' },
25
- packageManager: 'bun@1.4.0',
25
+ packageManager: 'bun@1.4.4',
26
26
  scripts: {
27
27
  dev: 'bun --bun vite dev --host 0.0.0.0 --port 5410 --strictPort',
28
28
  build: 'bun x --no-install sandcms validate && bun --bun vite build',
@@ -31,17 +31,17 @@ export function scaffold(root, name, packageSource) {
31
31
  },
32
32
  dependencies: { [PACKAGE_NAME]: packageSource ?? PACKAGE_VERSION },
33
33
  devDependencies: {
34
- '@sveltejs/kit': '3.0.0',
34
+ '@sveltejs/kit': '3.2.0',
35
35
  '@sveltejs/vite-plugin-svelte': '7.3.1',
36
- svelte: '5.57.1',
37
- vite: '8.3.1',
36
+ svelte: '5.57.3',
37
+ vite: '8.3.8',
38
38
  typescript: '6.0.3',
39
- '@sveltejs/adapter-bun': '1.0.0',
40
- 'svelte-check': '4.7.6',
41
- '@types/bun': '1.4.2'
39
+ '@sveltejs/adapter-bun': '1.0.1',
40
+ 'svelte-check': '4.7.8',
41
+ '@types/bun': '1.4.4'
42
42
  }
43
43
  }, null, 2) + '\n');
44
- write(join(root, 'vite.config.ts'), "import adapter from '@sveltejs/adapter-bun';\nimport { vitePreprocess } from '@sveltejs/vite-plugin-svelte';\nimport { sveltekit } from '@sveltejs/kit/vite';\nimport { defineConfig } from 'vite';\n// Keep Better Auth on native async storage when the Bun adapter bundles the server.\nexport default defineConfig({plugins:[sveltekit({adapter:adapter(),paths:{origin:process.env.SANDCMS_ORIGIN},preprocess:vitePreprocess()})],ssr:{external:['bun:sqlite'],noExternal:['@better-auth/core']}});\n");
44
+ write(join(root, 'vite.config.ts'), "import adapter from '@sveltejs/adapter-bun';\nimport { vitePreprocess } from '@sveltejs/vite-plugin-svelte';\nimport { sveltekit } from '@sveltejs/kit/vite';\nimport { defineConfig } from 'vite';\n// The origin comes from each request's Host header, so a domain change needs no rebuild.\n// Keep native modules external and Better Auth on native async storage in the server build.\nexport default defineConfig({plugins:[sveltekit({adapter:adapter(),preprocess:vitePreprocess()})],ssr:{external:['bun:sqlite','sharp'],noExternal:['@better-auth/core']}});\n");
45
45
  write(join(root, 'tsconfig.json'), JSON.stringify({
46
46
  extends: '$app/tsconfig',
47
47
  include: ['src', 'test', '*'],
package/dist/cli/setup.js CHANGED
@@ -3,8 +3,7 @@ import { join, resolve } from 'node:path';
3
3
  import * as p from '@clack/prompts';
4
4
  import { parse as parseEnv } from 'dotenv';
5
5
  import { planFiles, applyPlan, migrationReport, routeConflicts, write, PACKAGE_NAME, PACKAGE_VERSION } from './files.js';
6
- import { answer, confirm, text, run } from './prompts.js';
7
- import { configureWorker } from './cloudflare.js';
6
+ import { answer, text, run } from './prompts.js';
8
7
  import { scaffold, assertFreshDirectory } from './scaffold.js';
9
8
  import { openStore, pendingMigrations } from '../server/db/store.js';
10
9
  import { createUser } from '../server/auth.js';
@@ -27,11 +26,12 @@ export async function setup(options) {
27
26
  const notes = [
28
27
  'SvelteKit 3 is required. Migrate developer-owned Vite configuration, package imports, and tsconfig before applying generated integrations; see docs/upgrades.md#sveltekit-3.',
29
28
  'Public website routes remain developer-owned.',
30
- 'Run sandcms user bootstrap against the production database after deployment.',
29
+ 'Deploy the generated Dockerfile as one container with one persistent volume at /data. Set SANDCMS_BOOTSTRAP_EMAIL for the first start to create the admin, or run sandcms user bootstrap against the production database. See docs/deployment.md.',
31
30
  'Existing adapters are preserved. Configure @sveltejs/adapter-bun as shown in docs/deployment.md.',
32
- 'Setup adds commented proxy settings to .env.local. For Dokploy + Cloudflare, secure origin ingress, then set SANDCMS_TRUSTED_PROXY_HEADER=cf-connecting-ip and ADDRESS_HEADER=cf-connecting-ip in Dokploy runtime variables; see docs/deployment.md#client-ip-behind-dokploy-and-cloudflare.',
33
- 'Existing Vite configuration is preserved. Include @better-auth/core in ssr.noExternal to retain native async request storage in Bun production builds. See docs/deployment.md#server-build-configuration.',
34
- 'If .dockerignore is customized, merge the template exclusions before building: environment files, credentials, data/, and local Worker state must stay outside the image.'
31
+ 'Existing Vite configuration is preserved. Do not set paths.origin: the site derives its origin from the request and redirects other hostnames to SANDCMS_ORIGIN. Keep bun:sqlite and sharp in ssr.external and @better-auth/core in ssr.noExternal. See docs/deployment.md#server-build-configuration.',
32
+ 'An existing server hook must run cmsHandle first in sequence(): it enforces request size limits and handles health checks, redirects and media before other hooks.',
33
+ 'Set BODY_SIZE_LIMIT=10M wherever the site runs; setup adds it to .env.local and the Dockerfile sets it in the image. Setup adds commented proxy settings to .env.local; set SANDCMS_TRUSTED_PROXY_HEADER and ADDRESS_HEADER to the client IP header your reverse proxy sets.',
34
+ 'If .dockerignore is customized, merge the template exclusions before building: environment files, credentials and data/ must stay outside the image.'
35
35
  ];
36
36
  const report = migrationReport(plan, notes);
37
37
  console.log(report);
@@ -44,25 +44,14 @@ export async function setup(options) {
44
44
  const ignore = join(root, '.gitignore');
45
45
  const existingIgnore = existsSync(ignore) ? readFileSync(ignore, 'utf8') : '';
46
46
  appendFileSync(ignore, '\n' +
47
- [
48
- 'node_modules/',
49
- '.svelte-kit/',
50
- 'build/',
51
- '.env',
52
- '.env.*',
53
- '!.env.example',
54
- 'data/',
55
- '.wrangler/',
56
- '.dev.vars',
57
- '.dev.vars.*'
58
- ]
47
+ ['node_modules/', '.svelte-kit/', 'build/', '.env', '.env.*', '!.env.example', 'data/']
59
48
  .filter((s) => !existingIgnore.split('\n').includes(s))
60
49
  .join('\n') +
61
50
  '\n');
62
51
  const env = join(root, '.env.local'), previous = existsSync(env) ? readFileSync(env, 'utf8') : '';
63
52
  const previousSettings = parseEnv(previous);
64
53
  const settings = {
65
- BODY_SIZE_LIMIT: '1M',
54
+ BODY_SIZE_LIMIT: '10M',
66
55
  SANDCMS_DATABASE: options.database ?? './data/sandcms.sqlite',
67
56
  SANDCMS_ORIGIN: 'http://localhost:5410',
68
57
  SANDCMS_SECRET: crypto.randomUUID() + crypto.randomUUID()
@@ -70,11 +59,14 @@ export async function setup(options) {
70
59
  const additions = Object.entries(settings)
71
60
  .filter(([key]) => !previousSettings[key])
72
61
  .map(([key, v]) => `${key}=${v}`);
62
+ const mentioned = (key) => new RegExp(`^\\s*#?\\s*${key}\\s*=`, 'm').test(previous);
73
63
  const proxyExamples = ['SANDCMS_TRUSTED_PROXY_HEADER', 'ADDRESS_HEADER']
74
- .filter((key) => !new RegExp(`^\\s*#?\\s*${key}\\s*=`, 'm').test(previous))
75
- .map((key) => `# ${key}=cf-connecting-ip`);
64
+ .filter((key) => !mentioned(key))
65
+ .map((key) => `# ${key}=x-real-ip`);
76
66
  if (proxyExamples.length)
77
- additions.push('# Dokploy + Cloudflare: enable both settings in Dokploy runtime variables only after', '# restricting website ingress to Cloudflare and keeping the container port private.', '# See docs/deployment.md#client-ip-behind-dokploy-and-cloudflare.', ...proxyExamples);
67
+ additions.push('# Behind a reverse proxy, set both to the client IP header the proxy sets and overwrites,', '# in the host runtime variables. See docs/deployment.md.', ...proxyExamples);
68
+ if (!mentioned('SANDCMS_INDEXING'))
69
+ additions.push('# Preview sites: keep search engines out until launch.', '# SANDCMS_INDEXING=false');
78
70
  appendFileSync(env, '\n' + additions.join('\n') + '\n', { mode: 0o600 });
79
71
  chmodSync(env, 0o600);
80
72
  if (!options.skipInstall) {
@@ -93,7 +85,7 @@ export async function setup(options) {
93
85
  }))
94
86
  }));
95
87
  if (addons.length)
96
- await run(['bun', 'x', 'sv@0.17.1', 'add', ...addons], root);
88
+ await run(['bun', 'x', 'sv@1.4.0', 'add', ...addons], root);
97
89
  }
98
90
  const dbPath = options.database ?? previousSettings.SANDCMS_DATABASE ?? settings.SANDCMS_DATABASE;
99
91
  const target = resolve(root, dbPath);
@@ -117,7 +109,5 @@ export async function setup(options) {
117
109
  finally {
118
110
  store.close();
119
111
  }
120
- if (!options.yes && (await confirm('Configure and deploy Cloudflare media now?')))
121
- await configureWorker(root, name);
122
- console.log('Setup complete. Review sandcms/setup-report.md. Run bun run dev. In production: sandcms migrate, then sandcms user bootstrap against the mounted database.');
112
+ console.log('Setup complete. Review sandcms/setup-report.md. Run bun run dev. In production, set SANDCMS_AUTO_MIGRATE=true and, for the first start, SANDCMS_BOOTSTRAP_EMAIL; see docs/deployment.md.');
123
113
  }
@@ -1,7 +1,7 @@
1
1
  import { join } from 'node:path';
2
2
  import { readFileSync, existsSync } from 'node:fs';
3
3
  import { createTwoFilesPatch } from 'diff';
4
- import { planFiles, applyPlan, migrationReport, write, readManifest, routeConflicts } from './files.js';
4
+ import { PACKAGE_NAME, planFiles, applyPlan, migrationReport, write, readManifest, routeConflicts } from './files.js';
5
5
  import { confirm } from './prompts.js';
6
6
  import { loadDefinition } from '../blueprints/load.js';
7
7
  import { inspectMigrations } from '../server/db/store.js';
@@ -14,14 +14,41 @@ export async function upgrade(root, check = false, database) {
14
14
  `Installed integration: ${manifest.version}. Blueprints are valid.`,
15
15
  'The website now validates SandCMS environment variables on start through src/env.ts. Ensure SANDCMS_ORIGIN and a 32-character SANDCMS_SECRET are set in every environment. See docs/upgrades.md#validated-environment-variables.',
16
16
  'Include @better-auth/core in ssr.noExternal in your Vite configuration, then rebuild and restart the website to fix concurrent image preview failures. Developer-owned configuration is preserved. See docs/deployment.md#server-build-configuration.',
17
- 'From 0.5.0, database changes use incremental migrations. Back up with the installed package before updating, then run sandcms migrate. Changed pre-0.5.0 baselines still require a fresh database. See docs/upgrades.md.',
18
- 'Worker compatibility range: protocol 6 (Worker also accepts protocols 3, 4 and 5 for existing website processes). Deploy with sandcms worker update before upgrading website processes; expect temporary media downtime. Configure Worker R2 signing credentials, bucket CORS and staging lifecycle rules for direct uploads; run the incremental database migration; metadata inspection and encoding use remote transformations; verify both in staging. Purge old /media/* caches and keep R2 public access disabled. See docs/media.md.'
17
+ '0.8.0 replaces the 0.7 migration history with a new baseline. A 0.7.x database is converted once with sandcms rebaseline while the site is stopped; older databases are first upgraded with 0.7.x. See docs/upgrades.md#080-upgrade-checklist.',
18
+ '0.7.0 stores media on the site volume instead of Cloudflare. Before deploying: check that no uploads are pending, take a backup, and make sure the volume has free space of at least 3 × the current media. See docs/upgrades.md.',
19
+ 'Confirm cmsHandle runs first in sequence() in src/hooks.server.ts: it enforces request size limits and handles health checks, host redirects, uploads and media before other hooks.',
20
+ 'Add sharp to ssr.external next to bun:sqlite in your Vite configuration. Remove paths.origin: the site now derives its origin from the request and redirects other hostnames to SANDCMS_ORIGIN.',
21
+ 'Set BODY_SIZE_LIMIT=10M. Deploys overlap: the new container migrates on its first health check and takes traffic once healthy. OpenShip, Dokploy and Coolify each need a few settings; see docs/deployment.md#platform-settings. railpack.json remains supported.',
22
+ '0.8.0 removes the Cloudflare Worker support deprecated in 0.7.0: sandcms media import-r2, the sandcms/worker exports, the createCMS workerUrl and workerToken options and the SANDCMS_WORKER_URL and SANDCMS_WORKER_TOKEN variables. Finish the R2 import with 0.7.x before upgrading. media.workerUrl in config.yaml is ignored and can be removed.'
19
23
  ];
24
+ const vite = ['vite.config.ts', 'vite.config.js']
25
+ .map((file) => join(root, file))
26
+ .filter(existsSync)
27
+ .map((file) => readFileSync(file, 'utf8'))
28
+ .join('\n');
29
+ if (/paths\s*:\s*\{[^}]*\borigin\b/.test(vite))
30
+ notes.push('Your Vite configuration sets paths.origin. Remove it so a domain change needs no rebuild.');
31
+ if (vite && !/['"]sharp['"]/.test(vite))
32
+ notes.push('Your Vite configuration does not list sharp in ssr.external yet.');
33
+ if (!plan.some((p) => p.path === 'Dockerfile'))
34
+ notes.push(`A Dockerfile with a HEALTHCHECK on /_sandcms/health is available at node_modules/${PACKAGE_NAME}/templates/Dockerfile. It was not added because this site builds with Railpack, and hosts that detect a Dockerfile switch builders. To switch, copy it to the project root; later upgrades then keep it current.`);
35
+ if (plan.some((p) => /^src\/lib\/server\/sandcms\/index\.[jt]s$/.test(p.path) && p.status === 'conflict'))
36
+ notes.push('Your src/lib/server/sandcms/index.ts is customized. Pass server: true to createCMS and call media.start() before storing the instance (close and rethrow on failure), so the data-volume lock is taken before the database opens. Pass SANDCMS_CANONICAL_REDIRECT as canonicalRedirect, and add the sveltekit:shutdown listener that stops background work, closes the CMS and exits. See the proposed diff below.');
37
+ if (['src/lib/server/sandcms/index.ts', 'src/lib/server/sandcms/index.js'].some((file) => existsSync(join(root, file)) &&
38
+ /SANDCMS_WORKER_|workerUrl|workerToken/.test(readFileSync(join(root, file), 'utf8'))))
39
+ notes.push('Your src/lib/server/sandcms/index file still passes workerUrl or workerToken, or reads SANDCMS_WORKER_* variables. Remove those lines: 0.8.0 no longer declares the variables, so the build fails while they are read.');
40
+ if (existsSync(join(root, 'sandcms/worker')))
41
+ notes.push('sandcms/worker/ is no longer used by SandCMS and the sandcms/worker exports it imports are gone. Remove it, together with the Cloudflare Worker, once the R2 import has been verified with 0.7.x.');
20
42
  if (database)
21
- notes.push('Pending DB migrations: ' +
22
- (inspectMigrations(database)
23
- .map((m) => m.name)
24
- .join(', ') || 'none'));
43
+ try {
44
+ notes.push('Pending DB migrations: ' +
45
+ (inspectMigrations(database)
46
+ .map((m) => m.name)
47
+ .join(', ') || 'none'));
48
+ }
49
+ catch (cause) {
50
+ notes.push(`Database: ${cause instanceof Error ? cause.message : String(cause)}`);
51
+ }
25
52
  const conflicts = plan.filter((p) => p.status === 'conflict'), accepted = new Set();
26
53
  const diffs = conflicts.map((item) => createTwoFilesPatch(item.path, item.path + ' (proposed)', readFileSync(join(root, item.path), 'utf8'), item.content));
27
54
  let cancelled;
package/dist/env.d.ts CHANGED
@@ -28,14 +28,38 @@ export declare function sandcmsEnvVars({ building }?: SandcmsEnvOptions): {
28
28
  description: string;
29
29
  schema: (value: string | undefined) => string;
30
30
  };
31
- SANDCMS_WORKER_TOKEN: {
31
+ SANDCMS_MEDIA_DIR: {
32
32
  description: string;
33
33
  schema: (value: string | undefined) => string | undefined;
34
34
  };
35
- SANDCMS_WORKER_URL: {
35
+ SANDCMS_MEDIA_THREADS: {
36
+ description: string;
37
+ schema: (value: string | undefined) => number | undefined;
38
+ };
39
+ SANDCMS_REQUEST_LIMIT: {
40
+ description: string;
41
+ schema: (value: string | undefined) => number | undefined;
42
+ };
43
+ SANDCMS_INDEXING: {
44
+ description: string;
45
+ schema: (value: string | undefined) => boolean;
46
+ };
47
+ SANDCMS_CANONICAL_REDIRECT: {
48
+ description: string;
49
+ schema: (value: string | undefined) => boolean;
50
+ };
51
+ SANDCMS_SITE_RENAME: {
52
+ description: string;
53
+ schema: (value: string | undefined) => boolean;
54
+ };
55
+ SANDCMS_BOOTSTRAP_EMAIL: {
36
56
  description: string;
37
57
  schema: (value: string | undefined) => string | undefined;
38
58
  };
59
+ SANDCMS_ALLOW_UNMOUNTED_DATA: {
60
+ description: string;
61
+ schema: (value: string | undefined) => boolean;
62
+ };
39
63
  SANDCMS_TRUSTED_PROXY_HEADER: {
40
64
  description: string;
41
65
  schema: (value: string | undefined) => string | undefined;
package/dist/env.js CHANGED
@@ -56,16 +56,58 @@ export function sandcmsEnvVars({ building = false } = {}) {
56
56
  return value;
57
57
  })
58
58
  },
59
- SANDCMS_WORKER_TOKEN: {
60
- description: 'Media Worker token.',
59
+ SANDCMS_MEDIA_DIR: {
60
+ description: 'Media directory on the site volume. Defaults to <database directory>/media.',
61
61
  schema: optional
62
62
  },
63
- SANDCMS_WORKER_URL: {
64
- description: 'Overrides config media.workerUrl for this environment.',
65
- schema: (value) => (optional(value) ? url(value) : undefined)
63
+ SANDCMS_MEDIA_THREADS: {
64
+ description: 'CPU threads for image processing (default 1). More finishes batches sooner on an idle server; Docker still shares CPU fairly between sites under load.',
65
+ schema: (value) => {
66
+ if (!optional(value))
67
+ return undefined;
68
+ if (!/^[1-9]\d*$/.test(value))
69
+ throw new Error('Must be a positive whole number');
70
+ return Number(value);
71
+ }
72
+ },
73
+ SANDCMS_REQUEST_LIMIT: {
74
+ description: 'Largest request body in bytes outside chunked uploads (default 1 MB).',
75
+ schema: (value) => {
76
+ if (!optional(value))
77
+ return undefined;
78
+ if (!/^\d+$/.test(value.trim()) || !Number(value))
79
+ throw new Error('Must be a positive integer');
80
+ return Number(value);
81
+ }
82
+ },
83
+ SANDCMS_INDEXING: {
84
+ description: 'Set false on preview sites: sends X-Robots-Tag noindex and a disallow-all robots.txt.',
85
+ schema: (value) => boolean(value) !== 'false'
86
+ },
87
+ SANDCMS_CANONICAL_REDIRECT: {
88
+ description: 'Redirect other hostnames to SANDCMS_ORIGIN (default true). Behind a proxy that rewrites Host, set HOST_HEADER=x-forwarded-host instead of disabling this.',
89
+ schema: (value) => boolean(value) !== 'false'
90
+ },
91
+ SANDCMS_SITE_RENAME: {
92
+ description: 'Start once with true after renaming the project in config.yaml, so the data volume site-id follows the new name.',
93
+ schema: (value) => boolean(value) === 'true'
94
+ },
95
+ SANDCMS_BOOTSTRAP_EMAIL: {
96
+ description: 'On start with no users, create this admin and log a one-time password.',
97
+ schema: (value) => {
98
+ if (!optional(value))
99
+ return undefined;
100
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value.trim()))
101
+ throw new Error('Must be an email address');
102
+ return value.trim();
103
+ }
104
+ },
105
+ SANDCMS_ALLOW_UNMOUNTED_DATA: {
106
+ description: 'Allow a production database outside a mounted volume (the directory must persist).',
107
+ schema: (value) => boolean(value) === 'true'
66
108
  },
67
109
  SANDCMS_TRUSTED_PROXY_HEADER: {
68
- description: 'Client IP header set by a trusted reverse proxy; see docs/deployment.md.',
110
+ description: 'Client IP header set by a trusted reverse proxy (e.g. x-real-ip); see docs/deployment.md.',
69
111
  schema: (value) => {
70
112
  const header = value?.trim();
71
113
  if (!header)
@@ -1,7 +1,8 @@
1
+ import { fieldLabel } from './blueprints/labels.js';
1
2
  /** Groups are expanded so selecting one field never includes unrelated nested answers. */
2
3
  export function notificationFields(fields, prefix = '', label = '') {
3
4
  return Object.entries(fields).flatMap(([key, field]) => {
4
- const value = prefix + key, title = label + (field.label ?? key);
5
+ const value = prefix + key, title = label + fieldLabel(key, field);
5
6
  if (field.type === 'group')
6
7
  return notificationFields(field.fields ?? {}, value + '.', title + ' / ');
7
8
  // Repeated groups and rich content can contain additional unselected data.
@@ -11,6 +11,21 @@ type Usages = Record<string, {
11
11
  }[]>;
12
12
  /** Label options for every non-form blueprint, newest first. Empty blueprints map to []. */
13
13
  export declare function relationLabels(cms: CMS): Relations;
14
+ /** The newest document of every page blueprint, without creating missing singletons. */
15
+ export declare function pageEntries(cms: CMS): {
16
+ id: string;
17
+ blueprint: string;
18
+ singleton: string | null;
19
+ draft: import("../index.ts").Payload;
20
+ published: import("../index.ts").Payload | null;
21
+ draftSlug: string | null;
22
+ publishedSlug: string | null;
23
+ version: number;
24
+ publishedAt: number | null;
25
+ updatedAt: number;
26
+ createdAt: number;
27
+ searchText: string | null;
28
+ }[];
14
29
  /** Content references grouped by media id; every requested asset id gets an array. */
15
30
  export declare function mediaUsages(cms: CMS, assetIds: string[]): Usages;
16
31
  /** Dashboard entries (8 most recent) and counts, computed in SQL. */
@@ -39,6 +54,7 @@ export declare function dashboardData(cms: CMS, mediaCount: number): {
39
54
  };
40
55
  };
41
56
  export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
57
+ theme: "system" | "light" | "dark";
42
58
  screen: string;
43
59
  user: {
44
60
  id: string;
@@ -53,6 +69,7 @@ export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
53
69
  twoFactorEnabled: boolean | null | undefined;
54
70
  };
55
71
  site: string;
72
+ logo: string | false | undefined;
56
73
  blueprints: {
57
74
  navigationIcon: import("@lucide/svelte").LucideIconData;
58
75
  id: string;
@@ -70,21 +87,23 @@ export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
70
87
  export?: string[];
71
88
  }[];
72
89
  emailEnabled: boolean;
73
- workerUrl: string;
74
90
  mediaVersion: string;
75
91
  fileBlueprints: import("../index.ts").FileBlueprint[];
76
92
  defaultFileBlueprint: string;
77
93
  } | {
94
+ theme: "system" | "light" | "dark";
78
95
  screen: string;
79
96
  user: null;
80
97
  emailEnabled: boolean;
81
98
  next?: undefined;
82
99
  } | {
100
+ theme: "system" | "light" | "dark";
83
101
  screen: string;
84
102
  user: null;
85
103
  emailEnabled: boolean;
86
104
  next: string;
87
105
  } | {
106
+ theme: "system" | "light" | "dark";
88
107
  blueprint: import("../index.ts").Blueprint;
89
108
  entry: {
90
109
  id: string;
@@ -130,6 +149,9 @@ export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
130
149
  error: string | null;
131
150
  createdAt: number;
132
151
  searchText: string | null;
152
+ width: number | null;
153
+ height: number | null;
154
+ uploadAttempt: string | null;
133
155
  }[];
134
156
  relations: Relations;
135
157
  screen: string;
@@ -146,6 +168,59 @@ export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
146
168
  twoFactorEnabled: boolean | null | undefined;
147
169
  };
148
170
  site: string;
171
+ logo: string | false | undefined;
172
+ blueprints: {
173
+ navigationIcon: import("@lucide/svelte").LucideIconData;
174
+ id: string;
175
+ label: string;
176
+ kind: "page" | "site" | "collection" | "form";
177
+ icon?: string;
178
+ navigation?: {
179
+ group: string | false;
180
+ };
181
+ description?: string;
182
+ preview?: string;
183
+ fields: Record<string, import("../index.ts").Field>;
184
+ tabs?: Record<string, import("../index.ts").BlueprintTab>;
185
+ columns?: string[];
186
+ export?: string[];
187
+ }[];
188
+ emailEnabled: boolean;
189
+ mediaVersion: string;
190
+ fileBlueprints: import("../index.ts").FileBlueprint[];
191
+ defaultFileBlueprint: string;
192
+ next?: undefined;
193
+ } | {
194
+ theme: "system" | "light" | "dark";
195
+ entries: {
196
+ id: string;
197
+ blueprint: string;
198
+ singleton: string | null;
199
+ draft: import("../index.ts").Payload;
200
+ published: import("../index.ts").Payload | null;
201
+ draftSlug: string | null;
202
+ publishedSlug: string | null;
203
+ version: number;
204
+ publishedAt: number | null;
205
+ updatedAt: number;
206
+ createdAt: number;
207
+ searchText: string | null;
208
+ }[];
209
+ screen: string;
210
+ user: {
211
+ id: string;
212
+ createdAt: Date;
213
+ updatedAt: Date;
214
+ email: string;
215
+ emailVerified: boolean;
216
+ name: string;
217
+ image?: string | null | undefined | undefined;
218
+ role: string;
219
+ mustChangePassword: boolean;
220
+ twoFactorEnabled: boolean | null | undefined;
221
+ };
222
+ site: string;
223
+ logo: string | false | undefined;
149
224
  blueprints: {
150
225
  navigationIcon: import("@lucide/svelte").LucideIconData;
151
226
  id: string;
@@ -163,12 +238,12 @@ export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
163
238
  export?: string[];
164
239
  }[];
165
240
  emailEnabled: boolean;
166
- workerUrl: string;
167
241
  mediaVersion: string;
168
242
  fileBlueprints: import("../index.ts").FileBlueprint[];
169
243
  defaultFileBlueprint: string;
170
244
  next?: undefined;
171
245
  } | {
246
+ theme: "system" | "light" | "dark";
172
247
  assets: {
173
248
  expectedVersion: string;
174
249
  blueprint: string;
@@ -184,6 +259,9 @@ export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
184
259
  error: string | null;
185
260
  createdAt: number;
186
261
  searchText: string | null;
262
+ width: number | null;
263
+ height: number | null;
264
+ uploadAttempt: string | null;
187
265
  }[];
188
266
  relations: Relations;
189
267
  photographerCollection: string | undefined;
@@ -203,6 +281,7 @@ export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
203
281
  twoFactorEnabled: boolean | null | undefined;
204
282
  };
205
283
  site: string;
284
+ logo: string | false | undefined;
206
285
  blueprints: {
207
286
  navigationIcon: import("@lucide/svelte").LucideIconData;
208
287
  id: string;
@@ -220,12 +299,12 @@ export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
220
299
  export?: string[];
221
300
  }[];
222
301
  emailEnabled: boolean;
223
- workerUrl: string;
224
302
  mediaVersion: string;
225
303
  fileBlueprints: import("../index.ts").FileBlueprint[];
226
304
  defaultFileBlueprint: string;
227
305
  next?: undefined;
228
306
  } | {
307
+ theme: "system" | "light" | "dark";
229
308
  blueprint: import("../index.ts").Blueprint;
230
309
  submissions: {
231
310
  id: string;
@@ -261,6 +340,7 @@ export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
261
340
  twoFactorEnabled: boolean | null | undefined;
262
341
  };
263
342
  site: string;
343
+ logo: string | false | undefined;
264
344
  blueprints: {
265
345
  navigationIcon: import("@lucide/svelte").LucideIconData;
266
346
  id: string;
@@ -278,12 +358,12 @@ export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
278
358
  export?: string[];
279
359
  }[];
280
360
  emailEnabled: boolean;
281
- workerUrl: string;
282
361
  mediaVersion: string;
283
362
  fileBlueprints: import("../index.ts").FileBlueprint[];
284
363
  defaultFileBlueprint: string;
285
364
  next?: undefined;
286
365
  } | {
366
+ theme: "system" | "light" | "dark";
287
367
  invitations: {
288
368
  id: string;
289
369
  email: string;
@@ -313,6 +393,7 @@ export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
313
393
  twoFactorEnabled: boolean | null | undefined;
314
394
  };
315
395
  site: string;
396
+ logo: string | false | undefined;
316
397
  blueprints: {
317
398
  navigationIcon: import("@lucide/svelte").LucideIconData;
318
399
  id: string;
@@ -330,7 +411,6 @@ export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
330
411
  export?: string[];
331
412
  }[];
332
413
  emailEnabled: boolean;
333
- workerUrl: string;
334
414
  mediaVersion: string;
335
415
  fileBlueprints: import("../index.ts").FileBlueprint[];
336
416
  defaultFileBlueprint: string;