sandcms 0.6.2 → 0.7.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.
- package/README.md +14 -10
- package/dist/admin/Account.svelte +286 -83
- package/dist/admin/Admin.svelte +14 -1
- package/dist/admin/ApiKeys.svelte +146 -79
- package/dist/admin/AssetAttachment.svelte +10 -12
- package/dist/admin/AssetAttachment.svelte.d.ts +0 -1
- package/dist/admin/BlueprintFields.svelte +20 -5
- package/dist/admin/BlueprintFields.svelte.d.ts +2 -1
- package/dist/admin/Collection.svelte +111 -54
- package/dist/admin/Dashboard.svelte +3 -37
- package/dist/admin/DateField.svelte +75 -0
- package/dist/admin/DateField.svelte.d.ts +11 -0
- package/dist/admin/Editor.svelte +70 -65
- package/dist/admin/Fields.svelte +24 -23
- package/dist/admin/Fields.svelte.d.ts +0 -1
- package/dist/admin/FocusPicker.svelte +1 -2
- package/dist/admin/Gallery.svelte +2 -7
- package/dist/admin/Gallery.svelte.d.ts +0 -1
- package/dist/admin/GlobalSearch.svelte +54 -26
- package/dist/admin/HoverHint.svelte +37 -0
- package/dist/admin/HoverHint.svelte.d.ts +8 -0
- package/dist/admin/Inbox.svelte +6 -11
- package/dist/admin/LinkField.svelte +128 -66
- package/dist/admin/LinkField.svelte.d.ts +0 -1
- package/dist/admin/Login.svelte +0 -1
- package/dist/admin/MediaLibrary.svelte +70 -56
- package/dist/admin/MediaPicker.svelte +62 -55
- package/dist/admin/MediaPicker.svelte.d.ts +0 -1
- package/dist/admin/NotificationSettings.svelte +35 -27
- package/dist/admin/RichText.svelte +2 -2
- package/dist/admin/RowMenu.svelte +28 -0
- package/dist/admin/RowMenu.svelte.d.ts +10 -0
- package/dist/admin/SearchList.svelte +51 -14
- package/dist/admin/Shell.svelte +64 -29
- package/dist/admin/ThemePicker.svelte +72 -0
- package/dist/admin/ThemePicker.svelte.d.ts +18 -0
- package/dist/admin/UploadButton.svelte +2 -1
- package/dist/admin/UploadProgress.svelte +24 -0
- package/dist/admin/UploadProgress.svelte.d.ts +7 -0
- package/dist/admin/Users.svelte +106 -50
- package/dist/admin/client.d.ts +5 -670
- package/dist/admin/client.js +20 -1
- package/dist/admin/components/ui/alert/alert.svelte.d.ts +3 -13
- package/dist/admin/components/ui/attachment/attachment-media.svelte.d.ts +3 -13
- package/dist/admin/components/ui/attachment/attachment.svelte.d.ts +6 -26
- package/dist/admin/components/ui/badge/badge.svelte.d.ts +7 -25
- package/dist/admin/components/ui/button/button.svelte.d.ts +15 -53
- package/dist/admin/components/ui/calendar/calendar-caption.svelte +76 -0
- package/dist/admin/components/ui/calendar/calendar-caption.svelte.d.ts +19 -0
- package/dist/admin/components/ui/calendar/calendar-cell.svelte +19 -0
- package/dist/admin/components/ui/calendar/calendar-cell.svelte.d.ts +4 -0
- package/dist/admin/components/ui/calendar/calendar-day.svelte +33 -0
- package/dist/admin/components/ui/calendar/calendar-day.svelte.d.ts +4 -0
- package/dist/admin/components/ui/calendar/calendar-grid-body.svelte +12 -0
- package/dist/admin/components/ui/calendar/calendar-grid-body.svelte.d.ts +4 -0
- package/dist/admin/components/ui/calendar/calendar-grid-head.svelte +12 -0
- package/dist/admin/components/ui/calendar/calendar-grid-head.svelte.d.ts +4 -0
- package/dist/admin/components/ui/calendar/calendar-grid-row.svelte +12 -0
- package/dist/admin/components/ui/calendar/calendar-grid-row.svelte.d.ts +4 -0
- package/dist/admin/components/ui/calendar/calendar-grid.svelte +16 -0
- package/dist/admin/components/ui/calendar/calendar-grid.svelte.d.ts +4 -0
- package/dist/admin/components/ui/calendar/calendar-head-cell.svelte +19 -0
- package/dist/admin/components/ui/calendar/calendar-head-cell.svelte.d.ts +4 -0
- package/dist/admin/components/ui/calendar/calendar-header.svelte +19 -0
- package/dist/admin/components/ui/calendar/calendar-header.svelte.d.ts +4 -0
- package/dist/admin/components/ui/calendar/calendar-heading.svelte +16 -0
- package/dist/admin/components/ui/calendar/calendar-heading.svelte.d.ts +4 -0
- package/dist/admin/components/ui/calendar/calendar-month-select.svelte +48 -0
- package/dist/admin/components/ui/calendar/calendar-month-select.svelte.d.ts +4 -0
- package/dist/admin/components/ui/calendar/calendar-month.svelte +15 -0
- package/dist/admin/components/ui/calendar/calendar-month.svelte.d.ts +5 -0
- package/dist/admin/components/ui/calendar/calendar-months.svelte +19 -0
- package/dist/admin/components/ui/calendar/calendar-months.svelte.d.ts +5 -0
- package/dist/admin/components/ui/calendar/calendar-nav.svelte +19 -0
- package/dist/admin/components/ui/calendar/calendar-nav.svelte.d.ts +5 -0
- package/dist/admin/components/ui/calendar/calendar-next-button.svelte +37 -0
- package/dist/admin/components/ui/calendar/calendar-next-button.svelte.d.ts +8 -0
- package/dist/admin/components/ui/calendar/calendar-prev-button.svelte +37 -0
- package/dist/admin/components/ui/calendar/calendar-prev-button.svelte.d.ts +8 -0
- package/dist/admin/components/ui/calendar/calendar-year-select.svelte +47 -0
- package/dist/admin/components/ui/calendar/calendar-year-select.svelte.d.ts +4 -0
- package/dist/admin/components/ui/calendar/calendar.svelte +115 -0
- package/dist/admin/components/ui/calendar/calendar.svelte.d.ts +21 -0
- package/dist/admin/components/ui/calendar/index.d.ts +19 -0
- package/dist/admin/components/ui/calendar/index.js +21 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-checkbox-group.svelte +16 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-checkbox-group.svelte.d.ts +4 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-checkbox-item.svelte +46 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-checkbox-item.svelte.d.ts +9 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-content.svelte +31 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-content.svelte.d.ts +10 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-group-heading.svelte +22 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-group-heading.svelte.d.ts +8 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-group.svelte +7 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-group.svelte.d.ts +4 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-item.svelte +27 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-item.svelte.d.ts +8 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-label.svelte +24 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-label.svelte.d.ts +8 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-portal.svelte +7 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-portal.svelte.d.ts +3 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-radio-group.svelte +16 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-radio-group.svelte.d.ts +4 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-radio-item.svelte +36 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-radio-item.svelte.d.ts +4 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-separator.svelte +17 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-separator.svelte.d.ts +4 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-shortcut.svelte +23 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-shortcut.svelte.d.ts +5 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-sub-content.svelte +31 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-sub-content.svelte.d.ts +10 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-sub-trigger.svelte +29 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-sub-trigger.svelte.d.ts +7 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-sub.svelte +7 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-sub.svelte.d.ts +3 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-trigger.svelte +7 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu-trigger.svelte.d.ts +4 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu.svelte +7 -0
- package/dist/admin/components/ui/dropdown-menu/dropdown-menu.svelte.d.ts +3 -0
- package/dist/admin/components/ui/dropdown-menu/index.d.ts +18 -0
- package/dist/admin/components/ui/dropdown-menu/index.js +18 -0
- package/dist/admin/components/ui/input-otp/index.d.ts +5 -0
- package/dist/admin/components/ui/input-otp/index.js +5 -0
- package/dist/admin/components/ui/input-otp/input-otp-group.svelte +23 -0
- package/dist/admin/components/ui/input-otp/input-otp-group.svelte.d.ts +5 -0
- package/dist/admin/components/ui/input-otp/input-otp-separator.svelte +27 -0
- package/dist/admin/components/ui/input-otp/input-otp-separator.svelte.d.ts +5 -0
- package/dist/admin/components/ui/input-otp/input-otp-slot.svelte +29 -0
- package/dist/admin/components/ui/input-otp/input-otp-slot.svelte.d.ts +4 -0
- package/dist/admin/components/ui/input-otp/input-otp.svelte +24 -0
- package/dist/admin/components/ui/input-otp/input-otp.svelte.d.ts +4 -0
- package/dist/admin/components/ui/popover/index.d.ts +9 -0
- package/dist/admin/components/ui/popover/index.js +11 -0
- package/dist/admin/components/ui/popover/popover-close.svelte +7 -0
- package/dist/admin/components/ui/popover/popover-close.svelte.d.ts +4 -0
- package/dist/admin/components/ui/popover/popover-content.svelte +31 -0
- package/dist/admin/components/ui/popover/popover-content.svelte.d.ts +10 -0
- package/dist/admin/components/ui/popover/popover-description.svelte +20 -0
- package/dist/admin/components/ui/popover/popover-description.svelte.d.ts +5 -0
- package/dist/admin/components/ui/popover/popover-header.svelte +20 -0
- package/dist/admin/components/ui/popover/popover-header.svelte.d.ts +5 -0
- package/dist/admin/components/ui/popover/popover-portal.svelte +7 -0
- package/dist/admin/components/ui/popover/popover-portal.svelte.d.ts +3 -0
- package/dist/admin/components/ui/popover/popover-title.svelte +20 -0
- package/dist/admin/components/ui/popover/popover-title.svelte.d.ts +5 -0
- package/dist/admin/components/ui/popover/popover-trigger.svelte +17 -0
- package/dist/admin/components/ui/popover/popover-trigger.svelte.d.ts +4 -0
- package/dist/admin/components/ui/popover/popover.svelte +7 -0
- package/dist/admin/components/ui/popover/popover.svelte.d.ts +3 -0
- package/dist/admin/components/ui/switch/switch.svelte +2 -2
- package/dist/admin/components/ui/toggle/toggle.svelte.d.ts +6 -26
- package/dist/admin/components/ui/tooltip/index.d.ts +6 -0
- package/dist/admin/components/ui/tooltip/index.js +8 -0
- package/dist/admin/components/ui/tooltip/tooltip-content.svelte +48 -0
- package/dist/admin/components/ui/tooltip/tooltip-content.svelte.d.ts +11 -0
- package/dist/admin/components/ui/tooltip/tooltip-portal.svelte +7 -0
- package/dist/admin/components/ui/tooltip/tooltip-portal.svelte.d.ts +4 -0
- package/dist/admin/components/ui/tooltip/tooltip-provider.svelte +7 -0
- package/dist/admin/components/ui/tooltip/tooltip-provider.svelte.d.ts +4 -0
- package/dist/admin/components/ui/tooltip/tooltip-trigger.svelte +7 -0
- package/dist/admin/components/ui/tooltip/tooltip-trigger.svelte.d.ts +25 -0
- package/dist/admin/components/ui/tooltip/tooltip.svelte +7 -0
- package/dist/admin/components/ui/tooltip/tooltip.svelte.d.ts +25 -0
- package/dist/admin/generated/admin.css +1298 -234
- package/dist/admin/slug.d.ts +1 -0
- package/dist/admin/slug.js +6 -0
- package/dist/admin/theme-context.d.ts +7 -0
- package/dist/admin/theme-context.js +3 -0
- package/dist/admin/theme.d.ts +7 -0
- package/dist/admin/theme.js +14 -0
- package/dist/admin/types.d.ts +2 -1
- package/dist/admin/uploads.d.ts +8 -1
- package/dist/admin/uploads.js +94 -16
- package/dist/blueprints/files.js +1 -0
- package/dist/blueprints/load.js +7 -2
- package/dist/blueprints/types.d.ts +4 -1
- package/dist/cli/doctor.d.ts +3 -1
- package/dist/cli/doctor.js +85 -30
- package/dist/cli/files.d.ts +2 -6
- package/dist/cli/files.js +11 -2
- package/dist/cli/index.js +99 -31
- package/dist/cli/scaffold.js +8 -8
- package/dist/cli/setup.js +16 -26
- package/dist/cli/upgrade.js +21 -2
- package/dist/env.d.ts +32 -0
- package/dist/env.js +53 -3
- package/dist/server/admin-load.d.ts +13 -5
- package/dist/server/admin-load.js +8 -3
- package/dist/server/api-access.d.ts +4 -0
- package/dist/server/api-access.js +15 -2
- package/dist/server/api-pagination.d.ts +3 -0
- package/dist/server/api.js +11 -3
- package/dist/server/auth.d.ts +11 -9
- package/dist/server/auth.js +23 -0
- package/dist/server/cms.d.ts +65 -18
- package/dist/server/cms.js +62 -6
- package/dist/server/db/migration-data.js +4 -0
- package/dist/server/db/migrations/0009_local_media.sql +9 -0
- package/dist/server/db/migrations/meta/0009_snapshot.json +1763 -0
- package/dist/server/db/migrations/meta/_journal.json +7 -0
- package/dist/server/db/schema.d.ts +119 -2
- package/dist/server/db/schema.js +15 -3
- package/dist/server/hooks.js +155 -81
- package/dist/server/media/contracts.d.ts +115 -0
- package/dist/server/media/contracts.js +12 -0
- package/dist/server/media/deletions.d.ts +2 -1
- package/dist/server/media/deletions.js +3 -3
- package/dist/server/media/delivery.js +7 -11
- package/dist/server/media/import-r2.d.ts +56 -0
- package/dist/server/media/import-r2.js +342 -0
- package/dist/server/media/processor-child.d.ts +2 -0
- package/dist/server/media/processor-child.js +236 -0
- package/dist/server/media/processor.d.ts +51 -0
- package/dist/server/media/processor.js +135 -0
- package/dist/server/media/render-math.d.ts +24 -0
- package/dist/server/media/render-math.js +50 -0
- package/dist/server/media/runner.d.ts +30 -1
- package/dist/server/media/runner.js +418 -165
- package/dist/server/media/service.d.ts +56 -10
- package/dist/server/media/service.js +309 -98
- package/dist/server/media/storage.d.ts +5 -0
- package/dist/server/media/storage.js +279 -0
- package/dist/server/media/svg.d.ts +5 -0
- package/dist/server/media/svg.js +142 -0
- package/dist/server/media/upload-ticket.d.ts +12 -0
- package/dist/server/media/upload-ticket.js +35 -0
- package/dist/server/media/verify.d.ts +36 -0
- package/dist/server/media/verify.js +109 -0
- package/dist/server/platform/http.d.ts +27 -0
- package/dist/server/platform/http.js +77 -0
- package/dist/server/platform/index.d.ts +52 -0
- package/dist/server/platform/index.js +98 -0
- package/dist/server/platform/snapshots.d.ts +18 -0
- package/dist/server/platform/snapshots.js +110 -0
- package/dist/server/platform/volume.d.ts +20 -0
- package/dist/server/platform/volume.js +60 -0
- package/dist/worker/svg.d.ts +1 -5
- package/dist/worker/svg.js +2 -142
- package/docs/acceptance.md +6 -4
- package/docs/api.md +42 -4
- package/docs/cloudflare.md +48 -142
- package/docs/content.md +2 -2
- package/docs/deployment.md +159 -57
- package/docs/forms.md +1 -1
- package/docs/media.md +85 -21
- package/docs/package.md +21 -18
- package/docs/plans/0.7-self-hosted.md +264 -0
- package/docs/releases.md +27 -1
- package/docs/upgrades.md +44 -6
- package/package.json +38 -37
- package/templates/Dockerfile +28 -0
- package/templates/integration.ts +18 -2
- package/templates/railpack.json +1 -1
- package/templates/sandcms/blueprints/files/image.yaml +1 -1
- package/templates/sandcms/config.yaml +0 -1
- package/dist/cli/cloudflare.d.ts +0 -8
- package/dist/cli/cloudflare.js +0 -135
- package/templates/sandcms/worker/index.ts +0 -1
- package/templates/sandcms/worker/local.ts +0 -1
- package/templates/sandcms/worker/wrangler.jsonc +0 -6
package/dist/cli/index.js
CHANGED
|
@@ -11,8 +11,9 @@ import { createUser, recoverUser } from '../server/auth.js';
|
|
|
11
11
|
import { user } from '../server/db/schema.js';
|
|
12
12
|
import { loadDefinition } from '../blueprints/load.js';
|
|
13
13
|
import { text, password, confirm } from './prompts.js';
|
|
14
|
-
import { updateWorker } from './cloudflare.js';
|
|
15
14
|
import { doctor } from './doctor.js';
|
|
15
|
+
import { importFromR2 } from '../server/media/import-r2.js';
|
|
16
|
+
import { forceRebuild, verifyMedia } from '../server/media/verify.js';
|
|
16
17
|
const { values, positionals } = parseArgs({
|
|
17
18
|
args: process.argv.slice(2),
|
|
18
19
|
allowPositionals: true,
|
|
@@ -25,10 +26,14 @@ const { values, positionals } = parseArgs({
|
|
|
25
26
|
output: { type: 'string' },
|
|
26
27
|
from: { type: 'string' },
|
|
27
28
|
package: { type: 'string' },
|
|
29
|
+
'worker-url': { type: 'string' },
|
|
28
30
|
check: { type: 'boolean' },
|
|
29
31
|
'dry-run': { type: 'boolean' },
|
|
30
32
|
'skip-install': { type: 'boolean' },
|
|
31
33
|
'password-stdin': { type: 'boolean' },
|
|
34
|
+
'worker-token-stdin': { type: 'boolean' },
|
|
35
|
+
force: { type: 'boolean' },
|
|
36
|
+
repair: { type: 'boolean' },
|
|
32
37
|
yes: { type: 'boolean' },
|
|
33
38
|
help: { type: 'boolean' }
|
|
34
39
|
}
|
|
@@ -44,7 +49,7 @@ async function suppliedPassword() {
|
|
|
44
49
|
async function main() {
|
|
45
50
|
const [command, subcommand] = positionals;
|
|
46
51
|
if (values.help) {
|
|
47
|
-
console.log('sandcms setup | validate | doctor | upgrade [--check] | migrate [--check] |
|
|
52
|
+
console.log('sandcms setup | validate | doctor | upgrade [--check] | migrate [--check] | media rebuild [--force] | media verify [--repair] | media import-r2 [--worker-url URL] [--worker-token-stdin] | backup --output PATH | restore --from PATH | user bootstrap/add/reset-password/reset-2fa\nUse --database PATH to select the target database. Secrets are never accepted as arguments.');
|
|
48
53
|
return;
|
|
49
54
|
}
|
|
50
55
|
if (!command) {
|
|
@@ -75,8 +80,6 @@ async function main() {
|
|
|
75
80
|
});
|
|
76
81
|
if (command === 'upgrade')
|
|
77
82
|
return upgrade(root, values.check, database);
|
|
78
|
-
if (command === 'worker' && subcommand === 'update')
|
|
79
|
-
return updateWorker(root);
|
|
80
83
|
if (command === 'backup') {
|
|
81
84
|
if (!values.output)
|
|
82
85
|
throw new Error('Use --output PATH');
|
|
@@ -93,33 +96,8 @@ async function main() {
|
|
|
93
96
|
}
|
|
94
97
|
if (command === 'doctor')
|
|
95
98
|
return doctor(root, database);
|
|
96
|
-
if (command === 'media'
|
|
97
|
-
|
|
98
|
-
database,
|
|
99
|
-
root: join(root, 'sandcms'),
|
|
100
|
-
origin: process.env.SANDCMS_ORIGIN ?? 'http://localhost:5410',
|
|
101
|
-
secret: process.env.SANDCMS_SECRET ?? '',
|
|
102
|
-
workerToken: process.env.SANDCMS_WORKER_TOKEN,
|
|
103
|
-
workerUrl: process.env.SANDCMS_WORKER_URL
|
|
104
|
-
});
|
|
105
|
-
try {
|
|
106
|
-
cms.media.rebuild();
|
|
107
|
-
while (cms.media.list().some((a) => a.status === 'processing')) {
|
|
108
|
-
await cms.media.drain();
|
|
109
|
-
await Bun.sleep(1000);
|
|
110
|
-
console.log(cms.media
|
|
111
|
-
.list()
|
|
112
|
-
.map((a) => `${a.filename}: ${a.status}`)
|
|
113
|
-
.join('\n'));
|
|
114
|
-
}
|
|
115
|
-
if (cms.media.list().some((a) => a.status === 'failed'))
|
|
116
|
-
throw new Error('Some images failed; retry with media rebuild');
|
|
117
|
-
}
|
|
118
|
-
finally {
|
|
119
|
-
cms.close();
|
|
120
|
-
}
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
99
|
+
if (command === 'media')
|
|
100
|
+
return mediaCommand(subcommand);
|
|
123
101
|
const store = openStore(database);
|
|
124
102
|
try {
|
|
125
103
|
if (command === 'migrate') {
|
|
@@ -176,6 +154,96 @@ async function main() {
|
|
|
176
154
|
store.close();
|
|
177
155
|
}
|
|
178
156
|
}
|
|
157
|
+
// CLI media commands never call media.start(): no background tasks, schedulers or snapshots.
|
|
158
|
+
function openCMS() {
|
|
159
|
+
const mediaDir = process.env.SANDCMS_MEDIA_DIR;
|
|
160
|
+
return createCMS({
|
|
161
|
+
database,
|
|
162
|
+
root: join(root, 'sandcms'),
|
|
163
|
+
origin: process.env.SANDCMS_ORIGIN ?? 'http://localhost:5410',
|
|
164
|
+
secret: process.env.SANDCMS_SECRET ?? '',
|
|
165
|
+
...(mediaDir ? { mediaDir: resolve(root, mediaDir) } : {})
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
async function mediaCommand(subcommand) {
|
|
169
|
+
if (subcommand === 'import-r2') {
|
|
170
|
+
const token = values['worker-token-stdin']
|
|
171
|
+
? (await Bun.stdin.text()).trim()
|
|
172
|
+
: (process.env.SANDCMS_WORKER_TOKEN ?? '');
|
|
173
|
+
const cms = openCMS();
|
|
174
|
+
try {
|
|
175
|
+
const summary = await importFromR2(cms, {
|
|
176
|
+
workerUrl: values['worker-url'] ??
|
|
177
|
+
process.env.SANDCMS_WORKER_URL ??
|
|
178
|
+
cms.definition.config.media.workerUrl ??
|
|
179
|
+
'',
|
|
180
|
+
workerToken: token
|
|
181
|
+
});
|
|
182
|
+
for (const s of summary.skipped)
|
|
183
|
+
console.log(`Skipped ${s.id}: ${s.reason}`);
|
|
184
|
+
for (const f of summary.failures)
|
|
185
|
+
console.error(`Failed ${f.id}${f.key ? ` ${f.key}` : ''}: ${f.error}`);
|
|
186
|
+
console.log(`Assets: ${summary.assets}. Originals: ${summary.originals.imported} imported, ${summary.originals.present} already present. ` +
|
|
187
|
+
`Variants: ${summary.variants.imported} imported, ${summary.variants.present} already present. ` +
|
|
188
|
+
`Dimensions filled: ${summary.dimensions}. Verified ${summary.verified.originals} originals and ${summary.verified.variants} variants.`);
|
|
189
|
+
if (!summary.ok)
|
|
190
|
+
throw new Error(`${summary.failures.length} files failed. Fix the cause and run media import-r2 again; finished files are kept.`);
|
|
191
|
+
console.log('Import complete. Check the site, then remove the Worker settings.');
|
|
192
|
+
}
|
|
193
|
+
finally {
|
|
194
|
+
cms.close();
|
|
195
|
+
}
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (subcommand === 'verify') {
|
|
199
|
+
const cms = openCMS();
|
|
200
|
+
try {
|
|
201
|
+
const report = verifyMedia(cms, { repair: values.repair });
|
|
202
|
+
for (const id of report.missingOriginals)
|
|
203
|
+
console.error(`Original missing: ${id}`);
|
|
204
|
+
for (const v of report.missingVariants)
|
|
205
|
+
console.error(`Variant missing: ${v.key}`);
|
|
206
|
+
for (const v of report.unrepairable)
|
|
207
|
+
console.error(`No job to re-render ${v.key}; run media rebuild --force or upload again`);
|
|
208
|
+
console.log(`Checked ${report.checked} assets: ${report.missingOriginals.length} missing originals, ${report.missingVariants.length} missing variants.` +
|
|
209
|
+
(values.repair
|
|
210
|
+
? ` Re-rendering ${report.requeued.length} assets; marked ${report.failed.length} failed. The website renders them, or run media rebuild.`
|
|
211
|
+
: ''));
|
|
212
|
+
if (!values.repair && (report.missingOriginals.length || report.missingVariants.length))
|
|
213
|
+
throw new Error('Media files are missing; run media verify --repair');
|
|
214
|
+
}
|
|
215
|
+
finally {
|
|
216
|
+
cms.close();
|
|
217
|
+
}
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (subcommand !== 'rebuild')
|
|
221
|
+
throw new Error('Unknown command. Run sandcms --help');
|
|
222
|
+
const cms = openCMS();
|
|
223
|
+
try {
|
|
224
|
+
if (values.force)
|
|
225
|
+
console.log(`Re-rendering ${forceRebuild(cms)} assets with the local processor.`);
|
|
226
|
+
cms.media.rebuild();
|
|
227
|
+
const counts = () => {
|
|
228
|
+
const assets = cms.media.list();
|
|
229
|
+
return {
|
|
230
|
+
processing: assets.filter((a) => a.status === 'processing').length,
|
|
231
|
+
failed: assets.filter((a) => a.status === 'failed').length
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
while (counts().processing) {
|
|
235
|
+
await cms.media.drain();
|
|
236
|
+
await Bun.sleep(1000);
|
|
237
|
+
const { processing, failed } = counts();
|
|
238
|
+
console.log(`Processing: ${processing}. Failed: ${failed}.`);
|
|
239
|
+
}
|
|
240
|
+
if (counts().failed)
|
|
241
|
+
throw new Error('Some images failed; retry with media rebuild');
|
|
242
|
+
}
|
|
243
|
+
finally {
|
|
244
|
+
cms.close();
|
|
245
|
+
}
|
|
246
|
+
}
|
|
179
247
|
main().catch((e) => {
|
|
180
248
|
console.error(e instanceof Error ? e.message : e);
|
|
181
249
|
process.exitCode = 1;
|
package/dist/cli/scaffold.js
CHANGED
|
@@ -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.
|
|
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.
|
|
34
|
+
'@sveltejs/kit': '3.2.0',
|
|
35
35
|
'@sveltejs/vite-plugin-svelte': '7.3.1',
|
|
36
|
-
svelte: '5.57.
|
|
37
|
-
vite: '8.3.
|
|
36
|
+
svelte: '5.57.3',
|
|
37
|
+
vite: '8.3.8',
|
|
38
38
|
typescript: '6.0.3',
|
|
39
|
-
'@sveltejs/adapter-bun': '1.0.
|
|
40
|
-
'svelte-check': '4.7.
|
|
41
|
-
'@types/bun': '1.4.
|
|
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
|
|
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,
|
|
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
|
-
'
|
|
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
|
-
'
|
|
33
|
-
'
|
|
34
|
-
'
|
|
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: '
|
|
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) => !
|
|
75
|
-
.map((key) => `# ${key}=
|
|
64
|
+
.filter((key) => !mentioned(key))
|
|
65
|
+
.map((key) => `# ${key}=x-real-ip`);
|
|
76
66
|
if (proxyExamples.length)
|
|
77
|
-
additions.push('#
|
|
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@
|
|
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
|
-
|
|
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
|
}
|
package/dist/cli/upgrade.js
CHANGED
|
@@ -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';
|
|
@@ -15,8 +15,27 @@ export async function upgrade(root, check = false, database) {
|
|
|
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
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
|
-
'
|
|
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. Overlapping (zero-downtime) and stop-then-start deploys both work. The generated Dockerfile includes a HEALTHCHECK on /_sandcms/health; railpack.json remains supported.',
|
|
22
|
+
'Deploy with SANDCMS_WORKER_URL and SANDCMS_WORKER_TOKEN still set, run sandcms media import-r2 once, check the site, then remove the Worker variables. The Worker and its R2 bucket can be deleted after a restore from backup has been verified to contain the originals.'
|
|
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. See the proposed diff below.');
|
|
37
|
+
if (existsSync(join(root, 'sandcms/worker')))
|
|
38
|
+
notes.push('sandcms/worker/ is no longer used by SandCMS. Keep it until sandcms media import-r2 has been verified, then remove it together with the Cloudflare Worker.');
|
|
20
39
|
if (database)
|
|
21
40
|
notes.push('Pending DB migrations: ' +
|
|
22
41
|
(inspectMigrations(database)
|
package/dist/env.d.ts
CHANGED
|
@@ -28,6 +28,38 @@ export declare function sandcmsEnvVars({ building }?: SandcmsEnvOptions): {
|
|
|
28
28
|
description: string;
|
|
29
29
|
schema: (value: string | undefined) => string;
|
|
30
30
|
};
|
|
31
|
+
SANDCMS_MEDIA_DIR: {
|
|
32
|
+
description: string;
|
|
33
|
+
schema: (value: string | undefined) => string | undefined;
|
|
34
|
+
};
|
|
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: {
|
|
56
|
+
description: string;
|
|
57
|
+
schema: (value: string | undefined) => string | undefined;
|
|
58
|
+
};
|
|
59
|
+
SANDCMS_ALLOW_UNMOUNTED_DATA: {
|
|
60
|
+
description: string;
|
|
61
|
+
schema: (value: string | undefined) => boolean;
|
|
62
|
+
};
|
|
31
63
|
SANDCMS_WORKER_TOKEN: {
|
|
32
64
|
description: string;
|
|
33
65
|
schema: (value: string | undefined) => string | undefined;
|
package/dist/env.js
CHANGED
|
@@ -56,16 +56,66 @@ export function sandcmsEnvVars({ building = false } = {}) {
|
|
|
56
56
|
return value;
|
|
57
57
|
})
|
|
58
58
|
},
|
|
59
|
+
SANDCMS_MEDIA_DIR: {
|
|
60
|
+
description: 'Media directory on the site volume. Defaults to <database directory>/media.',
|
|
61
|
+
schema: optional
|
|
62
|
+
},
|
|
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'
|
|
108
|
+
},
|
|
59
109
|
SANDCMS_WORKER_TOKEN: {
|
|
60
|
-
description: '
|
|
110
|
+
description: 'Deprecated: legacy Cloudflare media Worker token, used only by sandcms media import-r2.',
|
|
61
111
|
schema: optional
|
|
62
112
|
},
|
|
63
113
|
SANDCMS_WORKER_URL: {
|
|
64
|
-
description: '
|
|
114
|
+
description: 'Deprecated: legacy Cloudflare media Worker URL, used only by sandcms media import-r2.',
|
|
65
115
|
schema: (value) => (optional(value) ? url(value) : undefined)
|
|
66
116
|
},
|
|
67
117
|
SANDCMS_TRUSTED_PROXY_HEADER: {
|
|
68
|
-
description: 'Client IP header set by a trusted reverse proxy; see docs/deployment.md.',
|
|
118
|
+
description: 'Client IP header set by a trusted reverse proxy (e.g. x-real-ip); see docs/deployment.md.',
|
|
69
119
|
schema: (value) => {
|
|
70
120
|
const header = value?.trim();
|
|
71
121
|
if (!header)
|
|
@@ -39,6 +39,7 @@ export declare function dashboardData(cms: CMS, mediaCount: number): {
|
|
|
39
39
|
};
|
|
40
40
|
};
|
|
41
41
|
export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
|
|
42
|
+
theme: "system" | "light" | "dark";
|
|
42
43
|
screen: string;
|
|
43
44
|
user: {
|
|
44
45
|
id: string;
|
|
@@ -70,21 +71,23 @@ export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
|
|
|
70
71
|
export?: string[];
|
|
71
72
|
}[];
|
|
72
73
|
emailEnabled: boolean;
|
|
73
|
-
workerUrl: string;
|
|
74
74
|
mediaVersion: string;
|
|
75
75
|
fileBlueprints: import("../index.ts").FileBlueprint[];
|
|
76
76
|
defaultFileBlueprint: string;
|
|
77
77
|
} | {
|
|
78
|
+
theme: "system" | "light" | "dark";
|
|
78
79
|
screen: string;
|
|
79
80
|
user: null;
|
|
80
81
|
emailEnabled: boolean;
|
|
81
82
|
next?: undefined;
|
|
82
83
|
} | {
|
|
84
|
+
theme: "system" | "light" | "dark";
|
|
83
85
|
screen: string;
|
|
84
86
|
user: null;
|
|
85
87
|
emailEnabled: boolean;
|
|
86
88
|
next: string;
|
|
87
89
|
} | {
|
|
90
|
+
theme: "system" | "light" | "dark";
|
|
88
91
|
blueprint: import("../index.ts").Blueprint;
|
|
89
92
|
entry: {
|
|
90
93
|
id: string;
|
|
@@ -130,6 +133,9 @@ export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
|
|
|
130
133
|
error: string | null;
|
|
131
134
|
createdAt: number;
|
|
132
135
|
searchText: string | null;
|
|
136
|
+
width: number | null;
|
|
137
|
+
height: number | null;
|
|
138
|
+
uploadAttempt: string | null;
|
|
133
139
|
}[];
|
|
134
140
|
relations: Relations;
|
|
135
141
|
screen: string;
|
|
@@ -163,12 +169,12 @@ export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
|
|
|
163
169
|
export?: string[];
|
|
164
170
|
}[];
|
|
165
171
|
emailEnabled: boolean;
|
|
166
|
-
workerUrl: string;
|
|
167
172
|
mediaVersion: string;
|
|
168
173
|
fileBlueprints: import("../index.ts").FileBlueprint[];
|
|
169
174
|
defaultFileBlueprint: string;
|
|
170
175
|
next?: undefined;
|
|
171
176
|
} | {
|
|
177
|
+
theme: "system" | "light" | "dark";
|
|
172
178
|
assets: {
|
|
173
179
|
expectedVersion: string;
|
|
174
180
|
blueprint: string;
|
|
@@ -184,6 +190,9 @@ export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
|
|
|
184
190
|
error: string | null;
|
|
185
191
|
createdAt: number;
|
|
186
192
|
searchText: string | null;
|
|
193
|
+
width: number | null;
|
|
194
|
+
height: number | null;
|
|
195
|
+
uploadAttempt: string | null;
|
|
187
196
|
}[];
|
|
188
197
|
relations: Relations;
|
|
189
198
|
photographerCollection: string | undefined;
|
|
@@ -220,12 +229,12 @@ export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
|
|
|
220
229
|
export?: string[];
|
|
221
230
|
}[];
|
|
222
231
|
emailEnabled: boolean;
|
|
223
|
-
workerUrl: string;
|
|
224
232
|
mediaVersion: string;
|
|
225
233
|
fileBlueprints: import("../index.ts").FileBlueprint[];
|
|
226
234
|
defaultFileBlueprint: string;
|
|
227
235
|
next?: undefined;
|
|
228
236
|
} | {
|
|
237
|
+
theme: "system" | "light" | "dark";
|
|
229
238
|
blueprint: import("../index.ts").Blueprint;
|
|
230
239
|
submissions: {
|
|
231
240
|
id: string;
|
|
@@ -278,12 +287,12 @@ export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
|
|
|
278
287
|
export?: string[];
|
|
279
288
|
}[];
|
|
280
289
|
emailEnabled: boolean;
|
|
281
|
-
workerUrl: string;
|
|
282
290
|
mediaVersion: string;
|
|
283
291
|
fileBlueprints: import("../index.ts").FileBlueprint[];
|
|
284
292
|
defaultFileBlueprint: string;
|
|
285
293
|
next?: undefined;
|
|
286
294
|
} | {
|
|
295
|
+
theme: "system" | "light" | "dark";
|
|
287
296
|
invitations: {
|
|
288
297
|
id: string;
|
|
289
298
|
email: string;
|
|
@@ -330,7 +339,6 @@ export declare function adminLoad(cms: CMS, event: RequestEvent): Promise<{
|
|
|
330
339
|
export?: string[];
|
|
331
340
|
}[];
|
|
332
341
|
emailEnabled: boolean;
|
|
333
|
-
workerUrl: string;
|
|
334
342
|
mediaVersion: string;
|
|
335
343
|
fileBlueprints: import("../index.ts").FileBlueprint[];
|
|
336
344
|
defaultFileBlueprint: string;
|
|
@@ -4,12 +4,13 @@ import { and, asc, count, desc, eq, inArray, sql } from 'drizzle-orm';
|
|
|
4
4
|
import { requireUser } from './auth.js';
|
|
5
5
|
import { documents, references, submissions, user } from './db/schema.js';
|
|
6
6
|
import { blueprintIcon } from './blueprint-icons.js';
|
|
7
|
+
import { parseTheme, themeCookie } from '../admin/theme.js';
|
|
7
8
|
const entryBlueprintIds = (cms) => cms.definition.blueprints.filter((b) => b.kind !== 'form').map((b) => b.id);
|
|
8
9
|
const formBlueprintIds = (cms) => cms.definition.blueprints.filter((b) => b.kind === 'form').map((b) => b.id);
|
|
9
|
-
// Matches String(draft.title ??
|
|
10
|
+
// Matches String(draft.title ?? 'Untitled') without parsing every draft in JS.
|
|
10
11
|
function titleLabel(row) {
|
|
11
12
|
if (row.titleType === null || row.titleType === 'null')
|
|
12
|
-
return
|
|
13
|
+
return 'Untitled';
|
|
13
14
|
if (row.titleType === 'true' || row.titleType === 'false')
|
|
14
15
|
return row.titleType;
|
|
15
16
|
if (row.titleType === 'object' || row.titleType === 'array')
|
|
@@ -98,6 +99,11 @@ export function dashboardData(cms, mediaCount) {
|
|
|
98
99
|
};
|
|
99
100
|
}
|
|
100
101
|
export async function adminLoad(cms, event) {
|
|
102
|
+
// Rendered on the admin root during SSR so the chosen theme paints without a flash.
|
|
103
|
+
const theme = parseTheme(event.cookies.get(themeCookie));
|
|
104
|
+
return { ...(await screenLoad(cms, event)), theme };
|
|
105
|
+
}
|
|
106
|
+
async function screenLoad(cms, event) {
|
|
101
107
|
const session = await cms.auth.api.getSession({ headers: event.request.headers }), path = event.params.path ?? '';
|
|
102
108
|
// Preserve notification links through sign-in, accepting only local form paths.
|
|
103
109
|
const requestedNext = event.url.searchParams.get('next') ?? '';
|
|
@@ -129,7 +135,6 @@ export async function adminLoad(cms, event) {
|
|
|
129
135
|
navigationIcon: blueprintIcon(blueprint)
|
|
130
136
|
})),
|
|
131
137
|
emailEnabled: cms.email.enabled,
|
|
132
|
-
workerUrl: cms.media.workerUrl,
|
|
133
138
|
mediaVersion: cms.media.version,
|
|
134
139
|
fileBlueprints: fileBlueprints(cms.definition),
|
|
135
140
|
defaultFileBlueprint: getFileBlueprint(cms.definition).id
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { CMS } from './cms.js';
|
|
2
|
+
/** Chunk endpoint of a chunked upload (`media/upload/{id}`), relative to `/api/cms/`. */
|
|
3
|
+
export declare const uploadChunkRoute: (path: string) => boolean;
|
|
2
4
|
export declare function apiKeyRoute(path: string, method: string): boolean;
|
|
3
5
|
export declare function apiPrincipal(cms: CMS, request: Request, path: string): Promise<{
|
|
4
6
|
user: {
|
|
@@ -29,3 +31,5 @@ export declare function apiPrincipal(cms: CMS, request: Request, path: string):
|
|
|
29
31
|
};
|
|
30
32
|
keyId: null;
|
|
31
33
|
}>;
|
|
34
|
+
/** User ID of the caller: the API key owner, or the signed-in admin/editor (with the origin check for writes). */
|
|
35
|
+
export declare function principalUserId(cms: CMS, request: Request, path: string): Promise<string>;
|
|
@@ -14,8 +14,13 @@ const writes = new Set([
|
|
|
14
14
|
'media/retry',
|
|
15
15
|
'media/delete'
|
|
16
16
|
]);
|
|
17
|
+
const chunkRoute = /^media\/upload\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
18
|
+
/** Chunk endpoint of a chunked upload (`media/upload/{id}`), relative to `/api/cms/`. */
|
|
19
|
+
export const uploadChunkRoute = (path) => chunkRoute.test(path);
|
|
17
20
|
export function apiKeyRoute(path, method) {
|
|
18
|
-
return (method === 'GET' && reads.has(path)) ||
|
|
21
|
+
return ((method === 'GET' && reads.has(path)) ||
|
|
22
|
+
(method === 'POST' && writes.has(path)) ||
|
|
23
|
+
((method === 'PUT' || method === 'GET') && uploadChunkRoute(path)));
|
|
19
24
|
}
|
|
20
25
|
export async function apiPrincipal(cms, request, path) {
|
|
21
26
|
// An explicitly supplied credential never falls back to a browser cookie.
|
|
@@ -30,7 +35,8 @@ export async function apiPrincipal(cms, request, path) {
|
|
|
30
35
|
}
|
|
31
36
|
if (!apiKeyRoute(path, request.method))
|
|
32
37
|
error(403, 'API keys can only access content and media');
|
|
33
|
-
|
|
38
|
+
// Chunk status (GET) belongs to an upload, so it needs the same write permission as PUT.
|
|
39
|
+
const action = request.method === 'GET' && !uploadChunkRoute(path) ? 'read' : 'write';
|
|
34
40
|
if (!result.key.permissions?.cms?.includes(action))
|
|
35
41
|
error(403, 'API key permission denied');
|
|
36
42
|
const owner = cms.store.db.select().from(user).where(eq(user.id, result.key.referenceId)).get();
|
|
@@ -50,3 +56,10 @@ export async function apiPrincipal(cms, request, path) {
|
|
|
50
56
|
error(403, 'Change your temporary password first');
|
|
51
57
|
return { user: session.user, keyId: null };
|
|
52
58
|
}
|
|
59
|
+
/** User ID of the caller: the API key owner, or the signed-in admin/editor (with the origin check for writes). */
|
|
60
|
+
export async function principalUserId(cms, request, path) {
|
|
61
|
+
const { user } = await apiPrincipal(cms, request, path);
|
|
62
|
+
if (!['admin', 'editor'].includes(user.role ?? ''))
|
|
63
|
+
error(403, 'You cannot access the CMS');
|
|
64
|
+
return user.id;
|
|
65
|
+
}
|