sandcms 0.5.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.
- package/LICENSE +57 -0
- package/README.md +84 -0
- package/dist/Image.svelte +53 -0
- package/dist/Image.svelte.d.ts +10 -0
- package/dist/Seo.svelte +29 -0
- package/dist/Seo.svelte.d.ts +10 -0
- package/dist/admin/Access.svelte +129 -0
- package/dist/admin/Access.svelte.d.ts +7 -0
- package/dist/admin/Account.svelte +190 -0
- package/dist/admin/Account.svelte.d.ts +7 -0
- package/dist/admin/Admin.svelte +42 -0
- package/dist/admin/Admin.svelte.d.ts +8 -0
- package/dist/admin/AssetAttachment.svelte +77 -0
- package/dist/admin/AssetAttachment.svelte.d.ts +15 -0
- package/dist/admin/Collection.svelte +52 -0
- package/dist/admin/Collection.svelte.d.ts +7 -0
- package/dist/admin/Dashboard.svelte +105 -0
- package/dist/admin/Dashboard.svelte.d.ts +7 -0
- package/dist/admin/Editor.svelte +192 -0
- package/dist/admin/Editor.svelte.d.ts +7 -0
- package/dist/admin/Fields.svelte +221 -0
- package/dist/admin/Fields.svelte.d.ts +17 -0
- package/dist/admin/Gallery.svelte +130 -0
- package/dist/admin/Gallery.svelte.d.ts +16 -0
- package/dist/admin/Inbox.svelte +154 -0
- package/dist/admin/Inbox.svelte.d.ts +8 -0
- package/dist/admin/Login.svelte +104 -0
- package/dist/admin/Login.svelte.d.ts +7 -0
- package/dist/admin/MediaLibrary.svelte +231 -0
- package/dist/admin/MediaLibrary.svelte.d.ts +7 -0
- package/dist/admin/MediaPicker.svelte +273 -0
- package/dist/admin/MediaPicker.svelte.d.ts +16 -0
- package/dist/admin/Notice.svelte +13 -0
- package/dist/admin/Notice.svelte.d.ts +8 -0
- package/dist/admin/NotificationSettings.svelte +153 -0
- package/dist/admin/NotificationSettings.svelte.d.ts +7 -0
- package/dist/admin/RichText.svelte +103 -0
- package/dist/admin/RichText.svelte.d.ts +9 -0
- package/dist/admin/RichTextLink.svelte +71 -0
- package/dist/admin/RichTextLink.svelte.d.ts +7 -0
- package/dist/admin/SelectField.svelte +39 -0
- package/dist/admin/SelectField.svelte.d.ts +15 -0
- package/dist/admin/Shell.svelte +106 -0
- package/dist/admin/Shell.svelte.d.ts +9 -0
- package/dist/admin/SortableList.svelte +104 -0
- package/dist/admin/SortableList.svelte.d.ts +30 -0
- package/dist/admin/UnsavedChanges.svelte +54 -0
- package/dist/admin/UnsavedChanges.svelte.d.ts +6 -0
- package/dist/admin/UploadButton.svelte +42 -0
- package/dist/admin/UploadButton.svelte.d.ts +10 -0
- package/dist/admin/UploadQueue.svelte +40 -0
- package/dist/admin/UploadQueue.svelte.d.ts +7 -0
- package/dist/admin/Users.svelte +185 -0
- package/dist/admin/Users.svelte.d.ts +7 -0
- package/dist/admin/client.d.ts +720 -0
- package/dist/admin/client.js +29 -0
- package/dist/admin/components/ui/alert/alert-action.svelte +20 -0
- package/dist/admin/components/ui/alert/alert-action.svelte.d.ts +5 -0
- package/dist/admin/components/ui/alert/alert-description.svelte +23 -0
- package/dist/admin/components/ui/alert/alert-description.svelte.d.ts +5 -0
- package/dist/admin/components/ui/alert/alert-title.svelte +23 -0
- package/dist/admin/components/ui/alert/alert-title.svelte.d.ts +5 -0
- package/dist/admin/components/ui/alert/alert.svelte +44 -0
- package/dist/admin/components/ui/alert/alert.svelte.d.ts +26 -0
- package/dist/admin/components/ui/alert/index.d.ts +6 -0
- package/dist/admin/components/ui/alert/index.js +8 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-action.svelte +27 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-action.svelte.d.ts +9 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-cancel.svelte +27 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-cancel.svelte.d.ts +9 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-content.svelte +32 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-content.svelte.d.ts +11 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-description.svelte +20 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-description.svelte.d.ts +4 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-footer.svelte +23 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-footer.svelte.d.ts +5 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-header.svelte +23 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-header.svelte.d.ts +5 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-media.svelte +23 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-media.svelte.d.ts +5 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-overlay.svelte +20 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-overlay.svelte.d.ts +4 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-portal.svelte +7 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-portal.svelte.d.ts +3 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-title.svelte +20 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-title.svelte.d.ts +4 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-trigger.svelte +7 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog-trigger.svelte.d.ts +4 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog.svelte +7 -0
- package/dist/admin/components/ui/alert-dialog/alert-dialog.svelte.d.ts +3 -0
- package/dist/admin/components/ui/alert-dialog/index.d.ts +13 -0
- package/dist/admin/components/ui/alert-dialog/index.js +15 -0
- package/dist/admin/components/ui/attachment/attachment-action.svelte +21 -0
- package/dist/admin/components/ui/attachment/attachment-action.svelte.d.ts +4 -0
- package/dist/admin/components/ui/attachment/attachment-actions.svelte +23 -0
- package/dist/admin/components/ui/attachment/attachment-actions.svelte.d.ts +5 -0
- package/dist/admin/components/ui/attachment/attachment-content.svelte +23 -0
- package/dist/admin/components/ui/attachment/attachment-content.svelte.d.ts +5 -0
- package/dist/admin/components/ui/attachment/attachment-description.svelte +24 -0
- package/dist/admin/components/ui/attachment/attachment-description.svelte.d.ts +5 -0
- package/dist/admin/components/ui/attachment/attachment-group.svelte +23 -0
- package/dist/admin/components/ui/attachment/attachment-group.svelte.d.ts +5 -0
- package/dist/admin/components/ui/attachment/attachment-media.svelte +44 -0
- package/dist/admin/components/ui/attachment/attachment-media.svelte.d.ts +26 -0
- package/dist/admin/components/ui/attachment/attachment-title.svelte +23 -0
- package/dist/admin/components/ui/attachment/attachment-title.svelte.d.ts +5 -0
- package/dist/admin/components/ui/attachment/attachment-trigger.svelte +29 -0
- package/dist/admin/components/ui/attachment/attachment-trigger.svelte.d.ts +11 -0
- package/dist/admin/components/ui/attachment/attachment.svelte +54 -0
- package/dist/admin/components/ui/attachment/attachment.svelte.d.ts +45 -0
- package/dist/admin/components/ui/attachment/index.d.ts +10 -0
- package/dist/admin/components/ui/attachment/index.js +12 -0
- package/dist/admin/components/ui/avatar/avatar-badge.svelte +26 -0
- package/dist/admin/components/ui/avatar/avatar-badge.svelte.d.ts +5 -0
- package/dist/admin/components/ui/avatar/avatar-fallback.svelte +20 -0
- package/dist/admin/components/ui/avatar/avatar-fallback.svelte.d.ts +4 -0
- package/dist/admin/components/ui/avatar/avatar-group-count.svelte +23 -0
- package/dist/admin/components/ui/avatar/avatar-group-count.svelte.d.ts +5 -0
- package/dist/admin/components/ui/avatar/avatar-group.svelte +23 -0
- package/dist/admin/components/ui/avatar/avatar-group.svelte.d.ts +5 -0
- package/dist/admin/components/ui/avatar/avatar-image.svelte +17 -0
- package/dist/admin/components/ui/avatar/avatar-image.svelte.d.ts +4 -0
- package/dist/admin/components/ui/avatar/avatar.svelte +26 -0
- package/dist/admin/components/ui/avatar/avatar.svelte.d.ts +7 -0
- package/dist/admin/components/ui/avatar/index.d.ts +7 -0
- package/dist/admin/components/ui/avatar/index.js +9 -0
- package/dist/admin/components/ui/badge/badge.svelte +50 -0
- package/dist/admin/components/ui/badge/badge.svelte.d.ts +38 -0
- package/dist/admin/components/ui/badge/index.d.ts +2 -0
- package/dist/admin/components/ui/badge/index.js +2 -0
- package/dist/admin/components/ui/button/button.svelte +87 -0
- package/dist/admin/components/ui/button/button.svelte.d.ts +70 -0
- package/dist/admin/components/ui/button/index.d.ts +2 -0
- package/dist/admin/components/ui/button/index.js +4 -0
- package/dist/admin/components/ui/card/card-action.svelte +20 -0
- package/dist/admin/components/ui/card/card-action.svelte.d.ts +5 -0
- package/dist/admin/components/ui/card/card-content.svelte +20 -0
- package/dist/admin/components/ui/card/card-content.svelte.d.ts +5 -0
- package/dist/admin/components/ui/card/card-description.svelte +20 -0
- package/dist/admin/components/ui/card/card-description.svelte.d.ts +5 -0
- package/dist/admin/components/ui/card/card-footer.svelte +20 -0
- package/dist/admin/components/ui/card/card-footer.svelte.d.ts +5 -0
- package/dist/admin/components/ui/card/card-header.svelte +23 -0
- package/dist/admin/components/ui/card/card-header.svelte.d.ts +5 -0
- package/dist/admin/components/ui/card/card-title.svelte +20 -0
- package/dist/admin/components/ui/card/card-title.svelte.d.ts +5 -0
- package/dist/admin/components/ui/card/card.svelte +25 -0
- package/dist/admin/components/ui/card/card.svelte.d.ts +8 -0
- package/dist/admin/components/ui/card/index.d.ts +8 -0
- package/dist/admin/components/ui/card/index.js +10 -0
- package/dist/admin/components/ui/checkbox/checkbox.svelte +39 -0
- package/dist/admin/components/ui/checkbox/checkbox.svelte.d.ts +4 -0
- package/dist/admin/components/ui/checkbox/index.d.ts +2 -0
- package/dist/admin/components/ui/checkbox/index.js +4 -0
- package/dist/admin/components/ui/dialog/dialog-close.svelte +11 -0
- package/dist/admin/components/ui/dialog/dialog-close.svelte.d.ts +4 -0
- package/dist/admin/components/ui/dialog/dialog-content.svelte +48 -0
- package/dist/admin/components/ui/dialog/dialog-content.svelte.d.ts +13 -0
- package/dist/admin/components/ui/dialog/dialog-description.svelte +20 -0
- package/dist/admin/components/ui/dialog/dialog-description.svelte.d.ts +4 -0
- package/dist/admin/components/ui/dialog/dialog-footer.svelte +32 -0
- package/dist/admin/components/ui/dialog/dialog-footer.svelte.d.ts +8 -0
- package/dist/admin/components/ui/dialog/dialog-header.svelte +20 -0
- package/dist/admin/components/ui/dialog/dialog-header.svelte.d.ts +5 -0
- package/dist/admin/components/ui/dialog/dialog-overlay.svelte +20 -0
- package/dist/admin/components/ui/dialog/dialog-overlay.svelte.d.ts +4 -0
- package/dist/admin/components/ui/dialog/dialog-portal.svelte +7 -0
- package/dist/admin/components/ui/dialog/dialog-portal.svelte.d.ts +3 -0
- package/dist/admin/components/ui/dialog/dialog-title.svelte +17 -0
- package/dist/admin/components/ui/dialog/dialog-title.svelte.d.ts +4 -0
- package/dist/admin/components/ui/dialog/dialog-trigger.svelte +11 -0
- package/dist/admin/components/ui/dialog/dialog-trigger.svelte.d.ts +4 -0
- package/dist/admin/components/ui/dialog/dialog.svelte +7 -0
- package/dist/admin/components/ui/dialog/dialog.svelte.d.ts +3 -0
- package/dist/admin/components/ui/dialog/index.d.ts +11 -0
- package/dist/admin/components/ui/dialog/index.js +13 -0
- package/dist/admin/components/ui/input/index.d.ts +2 -0
- package/dist/admin/components/ui/input/index.js +4 -0
- package/dist/admin/components/ui/input/input.svelte +48 -0
- package/dist/admin/components/ui/input/input.svelte.d.ts +13 -0
- package/dist/admin/components/ui/label/index.d.ts +2 -0
- package/dist/admin/components/ui/label/index.js +4 -0
- package/dist/admin/components/ui/label/label.svelte +20 -0
- package/dist/admin/components/ui/label/label.svelte.d.ts +4 -0
- package/dist/admin/components/ui/select/index.d.ts +13 -0
- package/dist/admin/components/ui/select/index.js +15 -0
- package/dist/admin/components/ui/select/select-content.svelte +45 -0
- package/dist/admin/components/ui/select/select-content.svelte.d.ts +11 -0
- package/dist/admin/components/ui/select/select-group-heading.svelte +21 -0
- package/dist/admin/components/ui/select/select-group-heading.svelte.d.ts +10 -0
- package/dist/admin/components/ui/select/select-group.svelte +17 -0
- package/dist/admin/components/ui/select/select-group.svelte.d.ts +4 -0
- package/dist/admin/components/ui/select/select-item.svelte +42 -0
- package/dist/admin/components/ui/select/select-item.svelte.d.ts +4 -0
- package/dist/admin/components/ui/select/select-label.svelte +20 -0
- package/dist/admin/components/ui/select/select-label.svelte.d.ts +6 -0
- package/dist/admin/components/ui/select/select-portal.svelte +7 -0
- package/dist/admin/components/ui/select/select-portal.svelte.d.ts +3 -0
- package/dist/admin/components/ui/select/select-scroll-down-button.svelte +23 -0
- package/dist/admin/components/ui/select/select-scroll-down-button.svelte.d.ts +4 -0
- package/dist/admin/components/ui/select/select-scroll-up-button.svelte +23 -0
- package/dist/admin/components/ui/select/select-scroll-up-button.svelte.d.ts +4 -0
- package/dist/admin/components/ui/select/select-separator.svelte +18 -0
- package/dist/admin/components/ui/select/select-separator.svelte.d.ts +4 -0
- package/dist/admin/components/ui/select/select-trigger.svelte +29 -0
- package/dist/admin/components/ui/select/select-trigger.svelte.d.ts +8 -0
- package/dist/admin/components/ui/select/select-value.svelte +7 -0
- package/dist/admin/components/ui/select/select-value.svelte.d.ts +4 -0
- package/dist/admin/components/ui/select/select.svelte +11 -0
- package/dist/admin/components/ui/select/select.svelte.d.ts +3 -0
- package/dist/admin/components/ui/separator/index.d.ts +2 -0
- package/dist/admin/components/ui/separator/index.js +4 -0
- package/dist/admin/components/ui/separator/separator.svelte +21 -0
- package/dist/admin/components/ui/separator/separator.svelte.d.ts +4 -0
- package/dist/admin/components/ui/switch/index.d.ts +2 -0
- package/dist/admin/components/ui/switch/index.js +4 -0
- package/dist/admin/components/ui/switch/switch.svelte +34 -0
- package/dist/admin/components/ui/switch/switch.svelte.d.ts +8 -0
- package/dist/admin/components/ui/table/index.d.ts +9 -0
- package/dist/admin/components/ui/table/index.js +11 -0
- package/dist/admin/components/ui/table/table-body.svelte +20 -0
- package/dist/admin/components/ui/table/table-body.svelte.d.ts +5 -0
- package/dist/admin/components/ui/table/table-caption.svelte +20 -0
- package/dist/admin/components/ui/table/table-caption.svelte.d.ts +5 -0
- package/dist/admin/components/ui/table/table-cell.svelte +20 -0
- package/dist/admin/components/ui/table/table-cell.svelte.d.ts +5 -0
- package/dist/admin/components/ui/table/table-footer.svelte +20 -0
- package/dist/admin/components/ui/table/table-footer.svelte.d.ts +5 -0
- package/dist/admin/components/ui/table/table-head.svelte +23 -0
- package/dist/admin/components/ui/table/table-head.svelte.d.ts +5 -0
- package/dist/admin/components/ui/table/table-header.svelte +20 -0
- package/dist/admin/components/ui/table/table-header.svelte.d.ts +5 -0
- package/dist/admin/components/ui/table/table-row.svelte +23 -0
- package/dist/admin/components/ui/table/table-row.svelte.d.ts +5 -0
- package/dist/admin/components/ui/table/table.svelte +22 -0
- package/dist/admin/components/ui/table/table.svelte.d.ts +5 -0
- package/dist/admin/components/ui/textarea/index.d.ts +2 -0
- package/dist/admin/components/ui/textarea/index.js +4 -0
- package/dist/admin/components/ui/textarea/textarea.svelte +22 -0
- package/dist/admin/components/ui/textarea/textarea.svelte.d.ts +5 -0
- package/dist/admin/components/ui/toggle/index.d.ts +3 -0
- package/dist/admin/components/ui/toggle/index.js +5 -0
- package/dist/admin/components/ui/toggle/toggle.svelte +52 -0
- package/dist/admin/components/ui/toggle/toggle.svelte.d.ts +43 -0
- package/dist/admin/generated/FONT-LICENSE +93 -0
- package/dist/admin/generated/Geist-LICENSE.txt +93 -0
- package/dist/admin/generated/admin.css +3276 -0
- package/dist/admin/generated/fonts/geist-cyrillic-ext-wght-italic.woff2 +0 -0
- package/dist/admin/generated/fonts/geist-cyrillic-ext-wght-normal.woff2 +0 -0
- package/dist/admin/generated/fonts/geist-cyrillic-wght-italic.woff2 +0 -0
- package/dist/admin/generated/fonts/geist-cyrillic-wght-normal.woff2 +0 -0
- package/dist/admin/generated/fonts/geist-latin-ext-wght-italic.woff2 +0 -0
- package/dist/admin/generated/fonts/geist-latin-ext-wght-normal.woff2 +0 -0
- package/dist/admin/generated/fonts/geist-latin-wght-italic.woff2 +0 -0
- package/dist/admin/generated/fonts/geist-latin-wght-normal.woff2 +0 -0
- package/dist/admin/generated/fonts/geist-vietnamese-wght-italic.woff2 +0 -0
- package/dist/admin/generated/fonts/geist-vietnamese-wght-normal.woff2 +0 -0
- package/dist/admin/generated/geist-cyrillic-ext-wght-normal.woff2 +0 -0
- package/dist/admin/generated/geist-cyrillic-wght-normal.woff2 +0 -0
- package/dist/admin/generated/geist-latin-ext-wght-normal.woff2 +0 -0
- package/dist/admin/generated/geist-latin-wght-normal.woff2 +0 -0
- package/dist/admin/generated/geist-vietnamese-wght-normal.woff2 +0 -0
- package/dist/admin/generated/styles.css +2772 -0
- package/dist/admin/index.d.ts +2 -0
- package/dist/admin/index.js +1 -0
- package/dist/admin/types.d.ts +63 -0
- package/dist/admin/types.js +1 -0
- package/dist/admin/uploads.d.ts +12 -0
- package/dist/admin/uploads.js +23 -0
- package/dist/admin/utils.d.ts +11 -0
- package/dist/admin/utils.js +1 -0
- package/dist/blueprints/files.d.ts +7 -0
- package/dist/blueprints/files.js +112 -0
- package/dist/blueprints/gallery.d.ts +3 -0
- package/dist/blueprints/gallery.js +14 -0
- package/dist/blueprints/load.d.ts +6 -0
- package/dist/blueprints/load.js +186 -0
- package/dist/blueprints/merge.d.ts +2 -0
- package/dist/blueprints/merge.js +18 -0
- package/dist/blueprints/types.d.ts +58 -0
- package/dist/blueprints/types.js +1 -0
- package/dist/blueprints/validate.d.ts +8 -0
- package/dist/blueprints/validate.js +133 -0
- package/dist/cli/backup.d.ts +6 -0
- package/dist/cli/backup.js +85 -0
- package/dist/cli/cloudflare.d.ts +8 -0
- package/dist/cli/cloudflare.js +123 -0
- package/dist/cli/doctor.d.ts +1 -0
- package/dist/cli/doctor.js +56 -0
- package/dist/cli/files.d.ts +30 -0
- package/dist/cli/files.js +114 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +182 -0
- package/dist/cli/prompts.d.ts +5 -0
- package/dist/cli/prompts.js +41 -0
- package/dist/cli/scaffold.d.ts +2 -0
- package/dist/cli/scaffold.js +58 -0
- package/dist/cli/setup.d.ts +11 -0
- package/dist/cli/setup.js +116 -0
- package/dist/cli/upgrade.d.ts +1 -0
- package/dist/cli/upgrade.js +47 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/media.d.ts +26 -0
- package/dist/media.js +27 -0
- package/dist/notification-fields.d.ts +8 -0
- package/dist/notification-fields.js +26 -0
- package/dist/richtext.d.ts +14 -0
- package/dist/richtext.js +73 -0
- package/dist/server/access.d.ts +16 -0
- package/dist/server/access.js +216 -0
- package/dist/server/admin-load.d.ts +342 -0
- package/dist/server/admin-load.js +135 -0
- package/dist/server/api.d.ts +3 -0
- package/dist/server/api.js +144 -0
- package/dist/server/auth.d.ts +744 -0
- package/dist/server/auth.js +142 -0
- package/dist/server/blueprint-icons.d.ts +4 -0
- package/dist/server/blueprint-icons.js +14 -0
- package/dist/server/cms.d.ts +1054 -0
- package/dist/server/cms.js +58 -0
- package/dist/server/content.d.ts +101 -0
- package/dist/server/content.js +285 -0
- package/dist/server/db/migration-data.d.ts +4 -0
- package/dist/server/db/migration-data.js +7 -0
- package/dist/server/db/migrations/0000_foundation.sql +180 -0
- package/dist/server/db/migrations/meta/0000_snapshot.json +1188 -0
- package/dist/server/db/migrations/meta/_journal.json +13 -0
- package/dist/server/db/schema.d.ts +2212 -0
- package/dist/server/db/schema.js +171 -0
- package/dist/server/db/store.d.ts +33 -0
- package/dist/server/db/store.js +131 -0
- package/dist/server/email/index.d.ts +50 -0
- package/dist/server/email/index.js +175 -0
- package/dist/server/email/template.d.ts +8 -0
- package/dist/server/email/template.js +53 -0
- package/dist/server/forms.d.ts +40 -0
- package/dist/server/forms.js +84 -0
- package/dist/server/hooks.d.ts +3 -0
- package/dist/server/hooks.js +85 -0
- package/dist/server/http.d.ts +3 -0
- package/dist/server/http.js +3 -0
- package/dist/server/index.d.ts +8 -0
- package/dist/server/index.js +7 -0
- package/dist/server/media/delivery.d.ts +3 -0
- package/dist/server/media/delivery.js +42 -0
- package/dist/server/media/presets.d.ts +2 -0
- package/dist/server/media/presets.js +8 -0
- package/dist/server/media/runner.d.ts +2 -0
- package/dist/server/media/runner.js +128 -0
- package/dist/server/media/service.d.ts +144 -0
- package/dist/server/media/service.js +280 -0
- package/dist/server/notifications.d.ts +9 -0
- package/dist/server/notifications.js +161 -0
- package/dist/server/request.d.ts +2 -0
- package/dist/server/request.js +39 -0
- package/dist/server/seo.d.ts +12 -0
- package/dist/server/seo.js +62 -0
- package/dist/worker/index.d.ts +10 -0
- package/dist/worker/index.js +266 -0
- package/dist/worker/source.d.ts +2 -0
- package/dist/worker/source.js +31 -0
- package/dist/worker/svg.d.ts +5 -0
- package/dist/worker/svg.js +142 -0
- package/docs/acceptance.md +58 -0
- package/docs/cloudflare.md +146 -0
- package/docs/content.md +188 -0
- package/docs/deployment.md +89 -0
- package/docs/email.md +124 -0
- package/docs/forms.md +18 -0
- package/docs/media.md +105 -0
- package/docs/package.md +84 -0
- package/docs/releases.md +29 -0
- package/docs/upgrades.md +62 -0
- package/package.json +124 -0
- package/templates/dockerignore +15 -0
- package/templates/hooks.server.ts +4 -0
- package/templates/integration.ts +20 -0
- package/templates/railpack.json +7 -0
- package/templates/routes/admin/+page.server.ts +3 -0
- package/templates/routes/admin/+page.svelte +6 -0
- package/templates/routes/api/+server.ts +4 -0
- package/templates/sandcms/blueprints/collections/photographers.yaml +6 -0
- package/templates/sandcms/blueprints/collections/projects.yaml +26 -0
- package/templates/sandcms/blueprints/files/image.yaml +6 -0
- package/templates/sandcms/blueprints/forms/registration.yaml +15 -0
- package/templates/sandcms/blueprints/pages/home.yaml +9 -0
- package/templates/sandcms/blueprints/site.yaml +13 -0
- package/templates/sandcms/config.yaml +12 -0
- package/templates/sandcms/worker/index.ts +1 -0
- package/templates/sandcms/worker/wrangler.jsonc +7 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { effectiveMetadata, getFileBlueprint, publicMetadata } from '../../blueprints/files.js';
|
|
2
|
+
import { validatePayload, walkValues } from '../../blueprints/validate.js';
|
|
3
|
+
import { mergeDraft } from '../../blueprints/merge.js';
|
|
4
|
+
import { createRunner } from './runner.js';
|
|
5
|
+
import { presetVersion } from './presets.js';
|
|
6
|
+
import { and, eq, desc, isNotNull } from 'drizzle-orm';
|
|
7
|
+
import { media, jobs, uploads, references, documents } from '../db/schema.js';
|
|
8
|
+
class WorkerResponseError extends Error {
|
|
9
|
+
status;
|
|
10
|
+
constructor(status, detail) {
|
|
11
|
+
super(`Media Worker: ${detail}`);
|
|
12
|
+
this.status = status;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function createMedia(store, definition, content, token, workerUrl = definition.config.media.workerUrl) {
|
|
16
|
+
const { db } = store, settings = definition.config.media;
|
|
17
|
+
const version = presetVersion(definition);
|
|
18
|
+
const get = (id) => db.select().from(media).where(eq(media.id, id)).get();
|
|
19
|
+
// Only published snapshots grant access; draft edits never change public visibility.
|
|
20
|
+
const isPublic = (id) => !!db
|
|
21
|
+
.select({ id: references.id })
|
|
22
|
+
.from(references)
|
|
23
|
+
.innerJoin(documents, eq(documents.id, references.documentId))
|
|
24
|
+
.where(and(eq(references.targetId, id), eq(references.kind, 'media'), eq(references.snapshot, 'published'), isNotNull(documents.published)))
|
|
25
|
+
.get();
|
|
26
|
+
async function worker(path, init = {}) {
|
|
27
|
+
if (!token)
|
|
28
|
+
throw new Error('Configure SANDCMS_WORKER_TOKEN before uploading media');
|
|
29
|
+
const response = await fetch(workerUrl.replace(/\/$/, '') + '/internal/' + path, {
|
|
30
|
+
...init,
|
|
31
|
+
headers: { ...init.headers, authorization: `Bearer ${token}`, 'x-sandcms-protocol': '3' },
|
|
32
|
+
signal: init.signal ?? AbortSignal.timeout(60_000)
|
|
33
|
+
});
|
|
34
|
+
if (!response.ok && !(path.startsWith('media/') && response.status === 304))
|
|
35
|
+
throw new WorkerResponseError(response.status, (await response.text().catch(() => '')).slice(0, 300));
|
|
36
|
+
return response;
|
|
37
|
+
}
|
|
38
|
+
function enqueue(id, mime) {
|
|
39
|
+
const existing = db
|
|
40
|
+
.select()
|
|
41
|
+
.from(jobs)
|
|
42
|
+
.where(and(eq(jobs.mediaId, id), eq(jobs.version, version)))
|
|
43
|
+
.all();
|
|
44
|
+
if (existing.length) {
|
|
45
|
+
const ready = existing.every((job) => job.status === 'ready');
|
|
46
|
+
if (!ready)
|
|
47
|
+
db.update(jobs)
|
|
48
|
+
.set({ status: 'pending', attempts: 0, nextAttempt: 0, error: null })
|
|
49
|
+
.where(and(eq(jobs.mediaId, id), eq(jobs.version, version), eq(jobs.status, 'failed')))
|
|
50
|
+
.run();
|
|
51
|
+
db.update(media)
|
|
52
|
+
.set({
|
|
53
|
+
targetVersion: version,
|
|
54
|
+
status: ready ? 'ready' : 'processing',
|
|
55
|
+
error: null,
|
|
56
|
+
...(ready ? { activeVersion: version, variants: existing.map((job) => job.result) } : {})
|
|
57
|
+
})
|
|
58
|
+
.where(eq(media.id, id))
|
|
59
|
+
.run();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const specs = mime === 'image/svg+xml'
|
|
63
|
+
? [{ preset: 'svg', size: 1, format: 'svg', quality: 100 }]
|
|
64
|
+
: Object.entries(settings.presets).flatMap(([preset, p]) => p.sizes.flatMap((size) => Object.entries(p.formats).map(([format, quality]) => ({
|
|
65
|
+
preset,
|
|
66
|
+
size,
|
|
67
|
+
format,
|
|
68
|
+
quality: quality
|
|
69
|
+
}))));
|
|
70
|
+
for (const spec of specs)
|
|
71
|
+
db.insert(jobs).values({ id: crypto.randomUUID(), mediaId: id, version, spec }).run();
|
|
72
|
+
db.update(media)
|
|
73
|
+
.set({ status: 'processing', targetVersion: version, error: null })
|
|
74
|
+
.where(eq(media.id, id))
|
|
75
|
+
.run();
|
|
76
|
+
}
|
|
77
|
+
async function upload(file, blueprintId) {
|
|
78
|
+
const blueprint = getFileBlueprint(definition, blueprintId);
|
|
79
|
+
if (!blueprint.accept.includes(file.type))
|
|
80
|
+
throw new Error(`Choose a file accepted by ${blueprint.label}`);
|
|
81
|
+
if (!file.size || file.size > settings.uploadLimit)
|
|
82
|
+
throw new Error(`Choose an image under ${settings.uploadLimit / 1_000_000} MB`);
|
|
83
|
+
if (![
|
|
84
|
+
'image/jpeg',
|
|
85
|
+
'image/png',
|
|
86
|
+
'image/webp',
|
|
87
|
+
'image/avif',
|
|
88
|
+
'image/gif',
|
|
89
|
+
'image/svg+xml'
|
|
90
|
+
].includes(file.type))
|
|
91
|
+
throw new Error('Choose a raster image or SVG');
|
|
92
|
+
const id = crypto.randomUUID(), body = Buffer.from(await file.arrayBuffer());
|
|
93
|
+
db.transaction(() => {
|
|
94
|
+
db.insert(media)
|
|
95
|
+
.values({
|
|
96
|
+
id,
|
|
97
|
+
filename: file.name.slice(0, 255),
|
|
98
|
+
blueprint: blueprint.id,
|
|
99
|
+
mime: file.type,
|
|
100
|
+
bytes: file.size,
|
|
101
|
+
status: 'processing',
|
|
102
|
+
targetVersion: version,
|
|
103
|
+
createdAt: Date.now()
|
|
104
|
+
})
|
|
105
|
+
.run();
|
|
106
|
+
db.insert(uploads).values({ mediaId: id, body }).run();
|
|
107
|
+
});
|
|
108
|
+
return get(id);
|
|
109
|
+
}
|
|
110
|
+
const tick = createRunner(store, worker, enqueue);
|
|
111
|
+
function retry(id) {
|
|
112
|
+
const asset = get(id);
|
|
113
|
+
if (!asset)
|
|
114
|
+
throw new Error('Image not found');
|
|
115
|
+
const upload = db.select().from(uploads).where(eq(uploads.mediaId, id)).get();
|
|
116
|
+
if (upload) {
|
|
117
|
+
db.update(uploads)
|
|
118
|
+
.set({ attempts: 0, leaseUntil: 0, nextAttempt: 0 })
|
|
119
|
+
.where(eq(uploads.mediaId, id))
|
|
120
|
+
.run();
|
|
121
|
+
db.update(media).set({ status: 'processing', error: null }).where(eq(media.id, id)).run();
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const set = db
|
|
125
|
+
.select()
|
|
126
|
+
.from(jobs)
|
|
127
|
+
.where(and(eq(jobs.mediaId, id), eq(jobs.version, asset.targetVersion)))
|
|
128
|
+
.all();
|
|
129
|
+
if (!set.length)
|
|
130
|
+
throw new Error('Upload was interrupted. Upload this file again.');
|
|
131
|
+
if (set.every((job) => job.status === 'ready'))
|
|
132
|
+
return;
|
|
133
|
+
db.update(jobs)
|
|
134
|
+
.set({ status: 'pending', attempts: 0, nextAttempt: 0, error: null })
|
|
135
|
+
.where(and(eq(jobs.mediaId, id), eq(jobs.version, asset.targetVersion), eq(jobs.status, 'failed')))
|
|
136
|
+
.run();
|
|
137
|
+
db.update(media).set({ status: 'processing', error: null }).where(eq(media.id, id)).run();
|
|
138
|
+
}
|
|
139
|
+
function updateMetadata(id, input) {
|
|
140
|
+
const asset = get(id);
|
|
141
|
+
if (!asset)
|
|
142
|
+
throw new Error('Image not found');
|
|
143
|
+
const blueprint = getFileBlueprint(definition, asset.blueprint);
|
|
144
|
+
const values = validatePayload(blueprint.fields, input);
|
|
145
|
+
const metadata = mergeDraft(blueprint.fields, asset.metadata, values);
|
|
146
|
+
validatePayload(blueprint.fields, metadata, true);
|
|
147
|
+
walkValues(blueprint.fields, metadata, (field, value) => {
|
|
148
|
+
if (field.type === 'relation' && value) {
|
|
149
|
+
const entry = content.get(String(value));
|
|
150
|
+
if (!entry || entry.blueprint !== field.collection)
|
|
151
|
+
throw new Error(`Choose a valid ${field.label ?? field.collection}`);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
db.update(media)
|
|
155
|
+
.set({
|
|
156
|
+
metadata,
|
|
157
|
+
blueprint: blueprint.id
|
|
158
|
+
})
|
|
159
|
+
.where(eq(media.id, id))
|
|
160
|
+
.run();
|
|
161
|
+
}
|
|
162
|
+
const assetData = (id, overrides = {}, preview = false) => {
|
|
163
|
+
const asset = get(id);
|
|
164
|
+
if (!asset?.activeVersion || (!preview && !isPublic(id)))
|
|
165
|
+
return null;
|
|
166
|
+
const blueprint = getFileBlueprint(definition, asset.blueprint);
|
|
167
|
+
const resolved = effectiveMetadata(asset.metadata, overrides, blueprint.fields);
|
|
168
|
+
const metadata = publicMetadata(blueprint.fields, resolved);
|
|
169
|
+
const photographer = blueprint.fields.photographer?.type === 'relation' && metadata.photographer
|
|
170
|
+
? content.get(String(metadata.photographer))
|
|
171
|
+
: null;
|
|
172
|
+
return {
|
|
173
|
+
id: asset.id,
|
|
174
|
+
blueprint: blueprint.id,
|
|
175
|
+
metadata,
|
|
176
|
+
alt: typeof metadata.alt === 'string' ? metadata.alt : '',
|
|
177
|
+
variants: asset.variants.map((variant) => ({
|
|
178
|
+
...variant,
|
|
179
|
+
url: `${preview ? '/api/cms' : '/_sandcms'}/media/${variant.key}`
|
|
180
|
+
})),
|
|
181
|
+
photographer: photographer?.published
|
|
182
|
+
? { id: photographer.id, name: String(photographer.published.title ?? '') }
|
|
183
|
+
: null
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
const galleryData = (rows, field, preview = false) => {
|
|
187
|
+
if (!Array.isArray(rows))
|
|
188
|
+
return [];
|
|
189
|
+
return rows.flatMap((row) => {
|
|
190
|
+
if (!row || typeof row.image !== 'string')
|
|
191
|
+
return [];
|
|
192
|
+
const overrides = {};
|
|
193
|
+
for (const key of field?.overrides ?? [])
|
|
194
|
+
if (row[key] !== undefined)
|
|
195
|
+
overrides[key] = row[key];
|
|
196
|
+
const asset = assetData(row.image, overrides, preview);
|
|
197
|
+
return asset
|
|
198
|
+
? [{ image: row.image, caption: String(asset.metadata.caption ?? ''), asset }]
|
|
199
|
+
: [];
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
return {
|
|
203
|
+
get,
|
|
204
|
+
upload,
|
|
205
|
+
tick,
|
|
206
|
+
retry,
|
|
207
|
+
version,
|
|
208
|
+
workerUrl,
|
|
209
|
+
list: () => db.select().from(media).orderBy(desc(media.createdAt)).all(),
|
|
210
|
+
updateMetadata,
|
|
211
|
+
async health() {
|
|
212
|
+
return (await worker('health')).json();
|
|
213
|
+
},
|
|
214
|
+
rebuild: () => {
|
|
215
|
+
db.transaction(() => {
|
|
216
|
+
for (const asset of db.select().from(media).all()) {
|
|
217
|
+
if (asset.activeVersion !== version &&
|
|
218
|
+
!db.select().from(uploads).where(eq(uploads.mediaId, asset.id)).get())
|
|
219
|
+
enqueue(asset.id, asset.mime);
|
|
220
|
+
if (get(asset.id)?.status === 'failed')
|
|
221
|
+
retry(asset.id);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
},
|
|
225
|
+
async remove(id) {
|
|
226
|
+
// Remove content references first. If R2 is temporarily unavailable, deletion is retryable.
|
|
227
|
+
db.transaction(() => {
|
|
228
|
+
content.clearReferences(id, 'media');
|
|
229
|
+
db.delete(jobs).where(eq(jobs.mediaId, id)).run();
|
|
230
|
+
db.delete(uploads).where(eq(uploads.mediaId, id)).run();
|
|
231
|
+
db.update(media)
|
|
232
|
+
.set({
|
|
233
|
+
status: 'failed',
|
|
234
|
+
variants: [],
|
|
235
|
+
activeVersion: null,
|
|
236
|
+
error: 'Deletion pending; retry delete'
|
|
237
|
+
})
|
|
238
|
+
.where(eq(media.id, id))
|
|
239
|
+
.run();
|
|
240
|
+
});
|
|
241
|
+
await worker('assets/' + id, { method: 'DELETE' });
|
|
242
|
+
db.delete(media).where(eq(media.id, id)).run();
|
|
243
|
+
},
|
|
244
|
+
publicAsset: (id, overrides = {}) => assetData(id, overrides),
|
|
245
|
+
// Metadata only. Bytes still require an authenticated CMS session.
|
|
246
|
+
previewAsset: (id, overrides = {}) => assetData(id, overrides, true),
|
|
247
|
+
async deliver(key, method, preview = false, ifNoneMatch = null) {
|
|
248
|
+
const asset = get(key.split('/')[0]);
|
|
249
|
+
if (!asset?.activeVersion ||
|
|
250
|
+
!asset.variants.some((v) => v.key === key) ||
|
|
251
|
+
(!preview && !isPublic(asset.id)))
|
|
252
|
+
return new Response('Not found', { status: 404 });
|
|
253
|
+
try {
|
|
254
|
+
const response = await worker('media/' + key, {
|
|
255
|
+
method,
|
|
256
|
+
headers: !preview && ifNoneMatch ? { 'if-none-match': ifNoneMatch } : {}
|
|
257
|
+
});
|
|
258
|
+
// Publication can change while the remote read is in flight.
|
|
259
|
+
const current = get(asset.id);
|
|
260
|
+
if (!current?.variants.some((v) => v.key === key) || (!preview && !isPublic(asset.id))) {
|
|
261
|
+
await response.body?.cancel();
|
|
262
|
+
return new Response('Not found', { status: 404 });
|
|
263
|
+
}
|
|
264
|
+
return response;
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
if (error instanceof WorkerResponseError && error.status === 404)
|
|
268
|
+
return new Response('Not found', { status: 404 });
|
|
269
|
+
return new Response('Media unavailable', { status: 502 });
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
publicGallery: (rows, field) => galleryData(rows, field),
|
|
273
|
+
previewGallery: (rows, field) => galleryData(rows, field, true),
|
|
274
|
+
start: () => {
|
|
275
|
+
const timer = setInterval(() => void tick().catch((e) => console.error('SandCMS media job failed', e)), 1000);
|
|
276
|
+
timer.unref();
|
|
277
|
+
return () => clearInterval(timer);
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Store } from './db/store.js';
|
|
2
|
+
import type { SiteDefinition } from '../blueprints/types.js';
|
|
3
|
+
import { type NotificationSettings } from './db/schema.js';
|
|
4
|
+
import { type createEmail } from './email/index.js';
|
|
5
|
+
export declare function createNotifications(store: Store, definition: SiteDefinition, email: ReturnType<typeof createEmail>, origin: string): {
|
|
6
|
+
get: (formId: string) => NotificationSettings;
|
|
7
|
+
save: (formId: string, input: unknown, actor: string) => NotificationSettings;
|
|
8
|
+
send: (id: string, manual?: boolean) => Promise<void>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { eq, inArray } from 'drizzle-orm';
|
|
2
|
+
import { formNotifications, submissions, user, audit } from './db/schema.js';
|
|
3
|
+
import { address } from './email/index.js';
|
|
4
|
+
import { notificationFields, notificationValue } from '../notification-fields.js';
|
|
5
|
+
import { emailTemplate } from './email/template.js';
|
|
6
|
+
import { rateLimit } from './forms.js';
|
|
7
|
+
const defaults = () => ({
|
|
8
|
+
enabled: false,
|
|
9
|
+
userIds: [],
|
|
10
|
+
addresses: [],
|
|
11
|
+
fields: [],
|
|
12
|
+
replyToField: ''
|
|
13
|
+
});
|
|
14
|
+
export function createNotifications(store, definition, email, origin) {
|
|
15
|
+
const get = (formId) => store.db.select().from(formNotifications).where(eq(formNotifications.formId, formId)).get()
|
|
16
|
+
?.settings ?? defaults();
|
|
17
|
+
function save(formId, input, actor) {
|
|
18
|
+
const blueprint = definition.blueprints.find((b) => b.kind === 'form' && b.id === formId);
|
|
19
|
+
if (!blueprint)
|
|
20
|
+
throw new Error('Unknown form');
|
|
21
|
+
if (!input || typeof input !== 'object')
|
|
22
|
+
throw new Error('Invalid notification settings');
|
|
23
|
+
const value = input;
|
|
24
|
+
if (typeof value.enabled !== 'boolean' || typeof value.replyToField !== 'string')
|
|
25
|
+
throw new Error('Invalid notification settings');
|
|
26
|
+
const strings = (key, limit) => {
|
|
27
|
+
const list = value[key];
|
|
28
|
+
if (!Array.isArray(list) || list.length > limit || list.some((v) => typeof v !== 'string'))
|
|
29
|
+
throw new Error('Invalid ' + key);
|
|
30
|
+
return [...new Set(list)];
|
|
31
|
+
};
|
|
32
|
+
const settings = {
|
|
33
|
+
enabled: value.enabled,
|
|
34
|
+
userIds: strings('userIds', 20),
|
|
35
|
+
addresses: strings('addresses', 20).map((v) => v.trim().toLowerCase()),
|
|
36
|
+
fields: strings('fields', 100),
|
|
37
|
+
replyToField: value.replyToField
|
|
38
|
+
};
|
|
39
|
+
if (settings.enabled && !email.enabled)
|
|
40
|
+
throw new Error('Configure email before enabling notifications');
|
|
41
|
+
if (settings.addresses.some((v) => !address(v)))
|
|
42
|
+
throw new Error('Enter valid recipient email addresses');
|
|
43
|
+
const users = store.db.select({ id: user.id }).from(user).all();
|
|
44
|
+
if (settings.userIds.some((id) => !users.some((u) => u.id === id)))
|
|
45
|
+
throw new Error('Choose existing CMS users');
|
|
46
|
+
if (settings.addresses.length + settings.userIds.length > 20)
|
|
47
|
+
throw new Error('Choose up to 20 recipients');
|
|
48
|
+
if (settings.enabled && !settings.addresses.length && !settings.userIds.length)
|
|
49
|
+
throw new Error('Choose at least one recipient');
|
|
50
|
+
const fields = notificationFields(blueprint.fields);
|
|
51
|
+
if (settings.fields.some((key) => !fields.some((f) => f.value === key)) ||
|
|
52
|
+
(settings.replyToField &&
|
|
53
|
+
!fields.some((f) => f.value === settings.replyToField && f.type === 'text')))
|
|
54
|
+
throw new Error('Choose current form fields');
|
|
55
|
+
store.db.transaction(() => {
|
|
56
|
+
store.db
|
|
57
|
+
.insert(formNotifications)
|
|
58
|
+
.values({ formId, settings })
|
|
59
|
+
.onConflictDoUpdate({ target: formNotifications.formId, set: { settings } })
|
|
60
|
+
.run();
|
|
61
|
+
store.db
|
|
62
|
+
.insert(audit)
|
|
63
|
+
.values({
|
|
64
|
+
id: crypto.randomUUID(),
|
|
65
|
+
action: 'form.notifications',
|
|
66
|
+
actor,
|
|
67
|
+
detail: { formId },
|
|
68
|
+
createdAt: Date.now()
|
|
69
|
+
})
|
|
70
|
+
.run();
|
|
71
|
+
});
|
|
72
|
+
return settings;
|
|
73
|
+
}
|
|
74
|
+
async function send(id, manual = false) {
|
|
75
|
+
const row = store.db.select().from(submissions).where(eq(submissions.id, id)).get();
|
|
76
|
+
if (!row)
|
|
77
|
+
throw new Error('Submission not found');
|
|
78
|
+
const settings = get(row.formId);
|
|
79
|
+
if (!settings.enabled) {
|
|
80
|
+
if (manual)
|
|
81
|
+
throw new Error('Notifications are disabled for this form');
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (manual)
|
|
85
|
+
rateLimit(store, 'notification:' + id, 3);
|
|
86
|
+
const users = settings.userIds.length
|
|
87
|
+
? store.db
|
|
88
|
+
.select({ email: user.email })
|
|
89
|
+
.from(user)
|
|
90
|
+
.where(inArray(user.id, settings.userIds))
|
|
91
|
+
.all()
|
|
92
|
+
: [];
|
|
93
|
+
const recipients = [
|
|
94
|
+
...new Set([...settings.addresses, ...users.map((u) => u.email)].map((v) => v.toLowerCase()))
|
|
95
|
+
];
|
|
96
|
+
const attemptedAt = Date.now();
|
|
97
|
+
const outcomes = recipients.map((to) => ({ to, status: 'sending' }));
|
|
98
|
+
store.db.transaction(() => {
|
|
99
|
+
const current = store.db.select().from(submissions).where(eq(submissions.id, id)).get();
|
|
100
|
+
if (!current)
|
|
101
|
+
throw new Error('Submission not found');
|
|
102
|
+
if (current.notification?.outcomes.some((o) => o.status === 'sending') &&
|
|
103
|
+
attemptedAt - current.notification.attemptedAt < 120_000)
|
|
104
|
+
throw new Error('An email attempt is already in progress');
|
|
105
|
+
store.db
|
|
106
|
+
.update(submissions)
|
|
107
|
+
.set({ notification: { attemptedAt, outcomes } })
|
|
108
|
+
.where(eq(submissions.id, id))
|
|
109
|
+
.run();
|
|
110
|
+
});
|
|
111
|
+
const currentBlueprint = definition.blueprints.find((b) => b.id === row.formId && b.kind === 'form');
|
|
112
|
+
const allowed = notificationFields(currentBlueprint?.fields ?? {});
|
|
113
|
+
const historical = notificationFields(row.schema.fields);
|
|
114
|
+
const answers = settings.fields
|
|
115
|
+
.filter((key) => allowed.some((f) => f.value === key) && historical.some((f) => f.value === key))
|
|
116
|
+
.map((key) => {
|
|
117
|
+
const value = notificationValue(row.data, key);
|
|
118
|
+
return `${historical.find((f) => f.value === key).label}: ${value === undefined || value === null ? '—' : Array.isArray(value) ? value.join(', ') : String(value)}`;
|
|
119
|
+
});
|
|
120
|
+
const reply = settings.replyToField &&
|
|
121
|
+
allowed.some((f) => f.value === settings.replyToField && f.type === 'text')
|
|
122
|
+
? notificationValue(row.data, settings.replyToField)
|
|
123
|
+
: undefined;
|
|
124
|
+
const label = row.schema.label.replace(/[\x00-\x1f\x7f]/g, ' ').slice(0, 200);
|
|
125
|
+
await Promise.all(outcomes.map(async (outcome) => {
|
|
126
|
+
try {
|
|
127
|
+
await email.send({
|
|
128
|
+
to: outcome.to,
|
|
129
|
+
subject: `New submission: ${label}`,
|
|
130
|
+
html: emailTemplate({
|
|
131
|
+
title: 'New form submission',
|
|
132
|
+
intro: `A new ${label} submission was received.`,
|
|
133
|
+
details: answers,
|
|
134
|
+
action: 'View submission',
|
|
135
|
+
url: `${origin}/admin/forms/${encodeURIComponent(row.formId)}?submission=${encodeURIComponent(id)}`,
|
|
136
|
+
footer: 'Sign in to SandCMS to view and manage this submission.'
|
|
137
|
+
}),
|
|
138
|
+
text: [
|
|
139
|
+
`A new ${label} submission was received.`,
|
|
140
|
+
...answers,
|
|
141
|
+
`${origin}/admin/forms/${encodeURIComponent(row.formId)}?submission=${encodeURIComponent(id)}`
|
|
142
|
+
].join('\n\n'),
|
|
143
|
+
...(address(reply) ? { replyTo: reply } : {})
|
|
144
|
+
});
|
|
145
|
+
outcome.status = 'accepted';
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
outcome.status = 'failed';
|
|
149
|
+
}
|
|
150
|
+
}));
|
|
151
|
+
// A process interruption leaves "sending" visible as an uncertain outcome.
|
|
152
|
+
const current = store.db.select().from(submissions).where(eq(submissions.id, id)).get();
|
|
153
|
+
if (current?.notification?.attemptedAt === attemptedAt)
|
|
154
|
+
store.db
|
|
155
|
+
.update(submissions)
|
|
156
|
+
.set({ notification: { attemptedAt, outcomes } })
|
|
157
|
+
.where(eq(submissions.id, id))
|
|
158
|
+
.run();
|
|
159
|
+
}
|
|
160
|
+
return { get, save, send };
|
|
161
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { error } from '@sveltejs/kit';
|
|
2
|
+
export async function boundedJson(request, limit = 1_000_000) {
|
|
3
|
+
const bytes = await boundedBytes(request, limit);
|
|
4
|
+
let data;
|
|
5
|
+
try {
|
|
6
|
+
data = JSON.parse(new TextDecoder().decode(bytes));
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
error(400, 'Invalid JSON');
|
|
10
|
+
}
|
|
11
|
+
if (!data || typeof data !== 'object' || Array.isArray(data))
|
|
12
|
+
error(400, 'Expected an object');
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
export async function boundedBytes(request, limit) {
|
|
16
|
+
const reader = request.body?.getReader();
|
|
17
|
+
if (!reader)
|
|
18
|
+
error(400, 'Missing request body');
|
|
19
|
+
let length = 0;
|
|
20
|
+
const chunks = [];
|
|
21
|
+
while (true) {
|
|
22
|
+
const next = await reader.read();
|
|
23
|
+
if (next.done)
|
|
24
|
+
break;
|
|
25
|
+
length += next.value.byteLength;
|
|
26
|
+
if (length > limit) {
|
|
27
|
+
await reader.cancel();
|
|
28
|
+
error(413, 'Request too large');
|
|
29
|
+
}
|
|
30
|
+
chunks.push(next.value);
|
|
31
|
+
}
|
|
32
|
+
const data = new Uint8Array(length);
|
|
33
|
+
let offset = 0;
|
|
34
|
+
for (const chunk of chunks) {
|
|
35
|
+
data.set(chunk, offset);
|
|
36
|
+
offset += chunk.length;
|
|
37
|
+
}
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SiteDefinition } from '../blueprints/types.js';
|
|
2
|
+
import type { createContent } from './content.js';
|
|
3
|
+
export interface SeoOptions {
|
|
4
|
+
/** Blueprint IDs mapped to public paths. Collections require {slug}. */
|
|
5
|
+
routes?: Record<string, string>;
|
|
6
|
+
/** Public paths that exist independently of published CMS content. */
|
|
7
|
+
pages?: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare function createSEO(origin: string, definition: SiteDefinition, content: ReturnType<typeof createContent>, options: SeoOptions): {
|
|
10
|
+
robots(): string;
|
|
11
|
+
sitemap(): string;
|
|
12
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const escapeXml = (value) => value.replace(/[&<>"']/g, (char) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[char]);
|
|
2
|
+
export function createSEO(origin, definition, content, options) {
|
|
3
|
+
const absolute = (path) => {
|
|
4
|
+
if (!/^\/(?!\/)[^?#\\\s{}]*$/.test(path))
|
|
5
|
+
throw new Error(`SEO paths must be local absolute paths without queries or fragments: ${path}`);
|
|
6
|
+
const url = new URL(path, origin);
|
|
7
|
+
if (url.origin !== origin || url.href.length >= 2048)
|
|
8
|
+
throw new Error(`Invalid SEO URL: ${path}`);
|
|
9
|
+
return url.href;
|
|
10
|
+
};
|
|
11
|
+
const pages = (options.pages ?? []).map(absolute);
|
|
12
|
+
const routes = Object.entries(options.routes ?? {}).map(([id, path]) => {
|
|
13
|
+
const blueprint = definition.blueprints.find((item) => item.id === id);
|
|
14
|
+
if (!blueprint || !['page', 'collection'].includes(blueprint.kind))
|
|
15
|
+
throw new Error(`SEO route must reference a page or collection blueprint: ${id}`);
|
|
16
|
+
if (blueprint.kind === 'collection') {
|
|
17
|
+
if (path.split('{slug}').length !== 2 || blueprint.fields.slug?.type !== 'slug')
|
|
18
|
+
throw new Error(`SEO collection route requires one {slug} and a slug field: ${id}`);
|
|
19
|
+
}
|
|
20
|
+
else if (path.includes('{slug}')) {
|
|
21
|
+
throw new Error(`SEO page route cannot contain {slug}: ${id}`);
|
|
22
|
+
}
|
|
23
|
+
absolute(path.replace('{slug}', 'example'));
|
|
24
|
+
return { id, path };
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
robots() {
|
|
28
|
+
return [
|
|
29
|
+
'User-agent: *',
|
|
30
|
+
'Disallow: /admin',
|
|
31
|
+
'Disallow: /api/cms/',
|
|
32
|
+
'',
|
|
33
|
+
`Sitemap: ${origin}/sitemap.xml`,
|
|
34
|
+
''
|
|
35
|
+
].join('\n');
|
|
36
|
+
},
|
|
37
|
+
sitemap() {
|
|
38
|
+
const urls = new Set(pages);
|
|
39
|
+
for (const { id, path } of routes) {
|
|
40
|
+
for (const entry of content.published(id)) {
|
|
41
|
+
const slug = entry.data.slug;
|
|
42
|
+
if (path.includes('{slug}') &&
|
|
43
|
+
(typeof slug !== 'string' || !slug || slug === '.' || slug === '..'))
|
|
44
|
+
continue;
|
|
45
|
+
urls.add(absolute(path.replace('{slug}', () => encodeURIComponent(String(slug)))));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (urls.size > 50_000)
|
|
49
|
+
throw new Error('SEO sitemap exceeds 50,000 URLs; provide a custom sitemap index.');
|
|
50
|
+
const xml = '<?xml version="1.0" encoding="UTF-8"?>\n' +
|
|
51
|
+
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' +
|
|
52
|
+
[...urls]
|
|
53
|
+
.sort()
|
|
54
|
+
.map((url) => ` <url><loc>${escapeXml(url)}</loc></url>`)
|
|
55
|
+
.join('\n') +
|
|
56
|
+
'\n</urlset>\n';
|
|
57
|
+
if (new TextEncoder().encode(xml).length > 52_428_800)
|
|
58
|
+
throw new Error('SEO sitemap exceeds 50 MB; provide a custom sitemap index.');
|
|
59
|
+
return xml;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { R2Bucket, ImagesBinding } from '@cloudflare/workers-types/index.ts';
|
|
2
|
+
export interface WorkerEnv {
|
|
3
|
+
MEDIA: R2Bucket;
|
|
4
|
+
IMAGES: ImagesBinding;
|
|
5
|
+
CMS_TOKEN: string;
|
|
6
|
+
}
|
|
7
|
+
declare const _default: {
|
|
8
|
+
fetch(request: Request, env: WorkerEnv): Promise<Response>;
|
|
9
|
+
};
|
|
10
|
+
export default _default;
|