sandcms 0.6.0 → 0.6.2

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 (51) hide show
  1. package/README.md +1 -1
  2. package/dist/cli/cloudflare.js +6 -6
  3. package/dist/cli/doctor.js +2 -2
  4. package/dist/cli/files.js +11 -6
  5. package/dist/cli/index.js +1 -1
  6. package/dist/cli/upgrade.js +2 -1
  7. package/dist/env.d.ts +80 -0
  8. package/dist/env.js +103 -0
  9. package/dist/server/admin-load.d.ts +46 -76
  10. package/dist/server/admin-load.js +98 -24
  11. package/dist/server/api-pagination.d.ts +2 -0
  12. package/dist/server/api-pagination.js +51 -7
  13. package/dist/server/cms.d.ts +19 -2
  14. package/dist/server/cms.js +13 -1
  15. package/dist/server/content.d.ts +15 -2
  16. package/dist/server/content.js +72 -30
  17. package/dist/server/db/auto-migrate.d.ts +12 -0
  18. package/dist/server/db/auto-migrate.js +23 -0
  19. package/dist/server/db/migration-data.js +8 -0
  20. package/dist/server/db/migrations/0007_content_and_job_indexes.sql +2 -0
  21. package/dist/server/db/migrations/0008_search_text_cache.sql +45 -0
  22. package/dist/server/db/migrations/meta/0007_snapshot.json +1643 -0
  23. package/dist/server/db/migrations/meta/0008_snapshot.json +1711 -0
  24. package/dist/server/db/migrations/meta/_journal.json +14 -0
  25. package/dist/server/db/schema.d.ts +83 -0
  26. package/dist/server/db/schema.js +23 -5
  27. package/dist/server/db/store.js +24 -9
  28. package/dist/server/email/index.d.ts +5 -1
  29. package/dist/server/email/index.js +12 -11
  30. package/dist/server/index.d.ts +1 -0
  31. package/dist/server/index.js +1 -0
  32. package/dist/server/media/runner.js +217 -191
  33. package/dist/server/media/service.d.ts +6 -0
  34. package/dist/server/media/service.js +36 -3
  35. package/dist/server/search.d.ts +2 -0
  36. package/dist/server/search.js +7 -0
  37. package/dist/worker/index.d.ts +1 -1
  38. package/dist/worker/index.js +134 -81
  39. package/dist/worker/local.js +5 -5
  40. package/dist/worker/uploads.d.ts +5 -5
  41. package/dist/worker/uploads.js +11 -9
  42. package/docs/cloudflare.md +7 -7
  43. package/docs/deployment.md +18 -0
  44. package/docs/email.md +5 -5
  45. package/docs/media.md +2 -2
  46. package/docs/package.md +4 -4
  47. package/docs/releases.md +18 -0
  48. package/docs/upgrades.md +66 -0
  49. package/package.json +5 -1
  50. package/templates/env.ts +8 -0
  51. package/templates/integration.ts +6 -5
package/docs/upgrades.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # Updates and generated files
2
2
 
3
+ ## 0.6.2 upgrade checklist
4
+
5
+ Version 0.6.2 includes retained database migrations `0007` and `0008`. Follow this order when upgrading from 0.6.1:
6
+
7
+ 1. Check `SANDCMS_ORIGIN`, `SANDCMS_SECRET` and the boolean SandCMS variables in every environment, as described in [validated environment variables](#validated-environment-variables).
8
+ 2. Stop website and job processes and take a verified backup with the installed package.
9
+ 3. Install `sandcms@0.6.2`, review `sandcms upgrade --check`, then apply integration updates with `sandcms upgrade`. Merge `sandcmsEnvVars` into an existing `src/env.ts`.
10
+ 4. Deploy the protocol-6 Worker with `sandcms worker update`; see [batched media processing](#batched-media-processing).
11
+ 5. Review `sandcms migrate --check`, then run `sandcms migrate`, or let a website with `SANDCMS_AUTO_MIGRATE=true` apply them on start.
12
+ 6. Rebuild and restart the website. Verify sign-in, admin search, uploads and media processing on staging.
13
+
14
+ Upgrading from 0.6.0 still requires the [0.6.1 upgrade checklist](#061-upgrade-checklist) first.
15
+
16
+ ## Faster admin queries
17
+
18
+ Apply the retained `0007_content_and_job_indexes.sql` and `0008_search_text_cache.sql` migrations before restarting the updated website. `0007` adds indexes for media jobs and document references. `0008` adds nullable `searchText` columns to documents and media, a `media_document_links` table backfilled from existing media metadata, and triggers that keep both current. Existing accounts, content, media and project-owned YAML are unchanged, and no configuration change is required. The search cache fills lazily and is cleared on every start.
19
+
20
+ ## Batched media processing
21
+
22
+ The media Worker protocol is now **6**. It adds a batch variant endpoint and still accepts protocol 3, 4 and 5 website processes, so deploy the Worker with `sandcms worker update` before the website. Updated website processes reject older Workers, and `sandcms doctor` reports the mismatch. No SQL migration is required. Existing jobs, active variant sets and project-owned YAML are preserved. Pending jobs resume in batches after the restart.
23
+
24
+ ## Validated environment variables
25
+
26
+ The website now validates its environment on start and refuses to run with a missing or malformed SandCMS variable; see [environment validation](deployment.md#environment-validation). No SQL migration is required.
27
+
28
+ - `sandcms upgrade` creates `src/env.ts` and updates an unmodified `src/lib/server/sandcms/index.ts` to read from `$app/env/private`.
29
+ - If the project already has `src/env.ts` or `src/env.js`, it is preserved and the report shows the merge: import `sandcmsEnvVars` from `sandcms/env` and spread `...sandcmsEnvVars({ building })` into the existing `defineEnvVars` call. The updated integration does not build until this is merged.
30
+ - Customized integrations may keep reading `process.env`, or switch to `import * as env from '$app/env/private'` and pass the validated values (`autoMigrate: env.SANDCMS_AUTO_MIGRATE` is already a boolean).
31
+ - Check every environment before deploying: `SANDCMS_ORIGIN` and a 32-character `SANDCMS_SECRET` are now required at start, and `SANDCMS_AUTO_MIGRATE`, `SANDCMS_SMTP_SECURE` and `SANDCMS_SMTP_ALLOW_INSECURE_LOCAL` accept only `true` or `false`. Previously, other values silently meant `false`.
32
+
33
+ ## 0.6.1 upgrade checklist
34
+
35
+ Version 0.6.1 adds no SQL migration. Follow this order when upgrading from 0.6.0:
36
+
37
+ 1. Copy each Worker secret to its new `SANDCMS_` name for every environment, as described in [renamed Worker secrets](#renamed-worker-secrets), and rename `CMS_TOKEN` in `sandcms/worker/.dev.vars`.
38
+ 2. Install `sandcms@0.6.1`, review `sandcms upgrade --check`, then apply integration updates with `sandcms upgrade`.
39
+ 3. Deploy the Worker with `sandcms worker update`, then rebuild and restart the website. Verify uploads, then delete the old Worker secrets.
40
+ 4. Optionally set `SANDCMS_AUTO_MIGRATE=true` to apply future migrations on start; see [automatic migration on start](#automatic-migration-on-start).
41
+
42
+ Upgrading from 0.5.x still requires the [0.6.0 upgrade checklist](#060-upgrade-checklist) first.
43
+
44
+ ## Automatic migration on start
45
+
46
+ The website can apply pending migrations itself when `SANDCMS_AUTO_MIGRATE=true` is set. It first takes a verified snapshot of an existing database beside it, then runs the same per-migration transactional runner as `sandcms migrate`. Unmodified generated integrations receive the setting through `sandcms upgrade`; merge `autoMigrate: env.SANDCMS_AUTO_MIGRATE` into customized `src/lib/server/sandcms/index.ts` files that read `$app/env/private` (the value is already a boolean), or `autoMigrate: process.env.SANDCMS_AUTO_MIGRATE === 'true'` into files that still read `process.env`. No SQL migration or configuration change is required, and leaving the variable unset keeps the explicit workflow below. See [automatic migration](deployment.md#automatic-migration-on-start).
47
+
3
48
  ## 0.6.0 upgrade checklist
4
49
 
5
50
  Version 0.6.0 requires SvelteKit 3 and includes retained database migrations `0001` through `0006`. Follow this order when upgrading from 0.5.x:
@@ -12,6 +57,27 @@ Version 0.6.0 requires SvelteKit 3 and includes retained database migrations `00
12
57
 
13
58
  Blueprint features and focal-point cropping are opt-in for existing project-owned YAML. Review the feature instructions below before changing it. Rollback requires the matching old package and its verified backup; no down migrations or automatic database reset are provided.
14
59
 
60
+ ## Renamed Worker secrets
61
+
62
+ The media Worker no longer reads `CMS_TOKEN` or the `R2_*` direct-upload secrets. Before deploying the new Worker, copy each existing value to its new name for every environment:
63
+
64
+ | Old Worker secret | New Worker secret |
65
+ | ---------------------- | ------------------------------ |
66
+ | `CMS_TOKEN` | `SANDCMS_WORKER_TOKEN` |
67
+ | `R2_ACCOUNT_ID` | `SANDCMS_CF_ACCOUNT_ID` |
68
+ | `R2_BUCKET_NAME` | `SANDCMS_R2_BUCKET_NAME` |
69
+ | `R2_ACCESS_KEY_ID` | `SANDCMS_R2_ACCESS_KEY_ID` |
70
+ | `R2_SECRET_ACCESS_KEY` | `SANDCMS_R2_SECRET_ACCESS_KEY` |
71
+ | `R2_ENDPOINT` | `SANDCMS_R2_ENDPOINT` |
72
+
73
+ ```sh
74
+ bun x wrangler secret put SANDCMS_WORKER_TOKEN --config sandcms/worker/wrangler.jsonc
75
+ # Repeat for SANDCMS_CF_ACCOUNT_ID and each SANDCMS_R2_* secret, then deploy:
76
+ bun x --no-install sandcms worker update
77
+ ```
78
+
79
+ `SANDCMS_WORKER_TOKEN` must equal the website's existing `SANDCMS_WORKER_TOKEN`. Cloudflare does not reveal stored secret values; if you no longer have them, generate a new token and set it on both the website and the Worker, and reuse or recreate the bucket-scoped R2 API token. Until the new names are set, the updated Worker rejects CMS requests and direct uploads fail closed. After verifying uploads, remove the old secrets with `wrangler secret delete`. For local development, rename `CMS_TOKEN` to `SANDCMS_WORKER_TOKEN` in `sandcms/worker/.dev.vars`. No database migration or website environment change is required.
80
+
15
81
  ## Durable media deletion
16
82
 
17
83
  Deploy the updated media Worker first using `sandcms worker update`; it speaks protocol 5, still accepts protocol 3 and 4 website processes, and adds permanent deletion markers to prevent late writes from recreating removed assets. Preserve the private `deleted/` prefix indefinitely and retain the one-day `incoming/` lifecycle rule. Apply `0006_durable_media_deletion.sql` using the retained migration workflow below before restarting the updated website. It adds a deletion queue and preserves existing assets, pending jobs, accounts, content, and YAML. Deletion now revokes references and active variants immediately and may finish storage cleanup asynchronously.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sandcms",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "scripts": {
5
5
  "dev": "bun run styles && bun --bun vite dev",
6
6
  "build": "bun run validate && bun run styles && bun --bun vite build && bun run package",
@@ -52,6 +52,10 @@
52
52
  "svelte": "./dist/admin/index.js"
53
53
  },
54
54
  "./admin/styles.css": "./dist/admin/generated/admin.css",
55
+ "./env": {
56
+ "types": "./dist/env.d.ts",
57
+ "default": "./dist/env.js"
58
+ },
55
59
  "./worker": "./dist/worker/index.js",
56
60
  "./worker/local": {
57
61
  "default": "./dist/worker/local.js"
@@ -0,0 +1,8 @@
1
+ import { building } from '$app/env';
2
+ import { defineEnvVars } from '@sveltejs/kit/env';
3
+ import { sandcmsEnvVars } from 'sandcms/env';
4
+ // The app refuses to start when a required SandCMS variable is missing or invalid.
5
+ // Declare your own variables alongside: https://svelte.dev/docs/kit/environment-variables
6
+ export const variables = defineEnvVars({
7
+ ...sandcmsEnvVars({ building })
8
+ });
@@ -1,18 +1,19 @@
1
1
  import { createCMS, emailOptionsFromEnv, type CMS } from 'sandcms/server';
2
- const env = process.env;
2
+ import * as env from '$app/env/private';
3
3
  let instance: CMS;
4
4
  export function getCMS() {
5
5
  if (!instance) {
6
6
  instance = createCMS({
7
7
  // Enable CMS-owned SEO routes after mapping your public pages:
8
8
  // seo: { routes: { home: '/', projects: '/projects/{slug}' } },
9
- database: env.SANDCMS_DATABASE ?? './data/sandcms.sqlite',
10
- origin: env.SANDCMS_ORIGIN ?? 'http://localhost:5410',
11
- secret: env.SANDCMS_SECRET ?? '',
9
+ database: env.SANDCMS_DATABASE,
10
+ origin: env.SANDCMS_ORIGIN,
11
+ secret: env.SANDCMS_SECRET,
12
12
  email: emailOptionsFromEnv(env),
13
13
  workerToken: env.SANDCMS_WORKER_TOKEN,
14
14
  workerUrl: env.SANDCMS_WORKER_URL,
15
- trustedProxyHeader: env.SANDCMS_TRUSTED_PROXY_HEADER
15
+ trustedProxyHeader: env.SANDCMS_TRUSTED_PROXY_HEADER,
16
+ autoMigrate: env.SANDCMS_AUTO_MIGRATE
16
17
  });
17
18
  instance.media.start();
18
19
  }