katecms 0.0.0-stage → 1.0.0-beta.1
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 +5 -3
- package/dist/module.d.mts +93 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +579 -0
- package/dist/runtime/assets/img/katecms-logo.svg +17 -0
- package/dist/runtime/composables/getCollection.d.ts +62 -0
- package/dist/runtime/composables/getCollection.js +167 -0
- package/dist/runtime/composables/getOptions.d.ts +22 -0
- package/dist/runtime/composables/getOptions.js +22 -0
- package/dist/runtime/composables/getQueryCollection.d.ts +95 -0
- package/dist/runtime/composables/getQueryCollection.js +199 -0
- package/dist/runtime/composables/getTerms.d.ts +79 -0
- package/dist/runtime/composables/getTerms.js +148 -0
- package/dist/runtime/composables/useAuth.d.ts +14 -0
- package/dist/runtime/composables/useAuth.js +33 -0
- package/dist/runtime/composables/useAuthCooldown.d.ts +6 -0
- package/dist/runtime/composables/useAuthCooldown.js +44 -0
- package/dist/runtime/composables/useCmsPaths.d.ts +15 -0
- package/dist/runtime/composables/useCmsPaths.js +21 -0
- package/dist/runtime/composables/useKateCmsExtensions.d.ts +49 -0
- package/dist/runtime/composables/useKateCmsExtensions.js +29 -0
- package/dist/runtime/composables/useMediaLibrary.d.ts +84 -0
- package/dist/runtime/composables/useMediaLibrary.js +140 -0
- package/dist/runtime/composables/useMenuAccess.d.ts +8 -0
- package/dist/runtime/composables/useMenuAccess.js +16 -0
- package/dist/runtime/internal/admin/AdminHeader.d.vue.ts +24 -0
- package/dist/runtime/internal/admin/AdminHeader.vue +91 -0
- package/dist/runtime/internal/admin/AdminHeader.vue.d.ts +24 -0
- package/dist/runtime/internal/admin/AppMenu.d.vue.ts +3 -0
- package/dist/runtime/internal/admin/AppMenu.vue +244 -0
- package/dist/runtime/internal/admin/AppMenu.vue.d.ts +3 -0
- package/dist/runtime/internal/admin/AppUser.d.vue.ts +3 -0
- package/dist/runtime/internal/admin/AppUser.vue +227 -0
- package/dist/runtime/internal/admin/AppUser.vue.d.ts +3 -0
- package/dist/runtime/internal/admin/CollectionEntryForm.d.vue.ts +41 -0
- package/dist/runtime/internal/admin/CollectionEntryForm.vue +916 -0
- package/dist/runtime/internal/admin/CollectionEntryForm.vue.d.ts +41 -0
- package/dist/runtime/internal/admin/ConfirmDialog.d.vue.ts +28 -0
- package/dist/runtime/internal/admin/ConfirmDialog.vue +136 -0
- package/dist/runtime/internal/admin/ConfirmDialog.vue.d.ts +28 -0
- package/dist/runtime/internal/admin/DictionaryTermForm.d.vue.ts +33 -0
- package/dist/runtime/internal/admin/DictionaryTermForm.vue +328 -0
- package/dist/runtime/internal/admin/DictionaryTermForm.vue.d.ts +33 -0
- package/dist/runtime/internal/admin/EntryRevisions.d.vue.ts +15 -0
- package/dist/runtime/internal/admin/EntryRevisions.vue +125 -0
- package/dist/runtime/internal/admin/EntryRevisions.vue.d.ts +15 -0
- package/dist/runtime/internal/admin/MediaLibraryFilters.d.vue.ts +16 -0
- package/dist/runtime/internal/admin/MediaLibraryFilters.vue +153 -0
- package/dist/runtime/internal/admin/MediaLibraryFilters.vue.d.ts +16 -0
- package/dist/runtime/internal/admin/MediaLibraryModal.d.vue.ts +65 -0
- package/dist/runtime/internal/admin/MediaLibraryModal.vue +451 -0
- package/dist/runtime/internal/admin/MediaLibraryModal.vue.d.ts +65 -0
- package/dist/runtime/internal/admin/OptionPageForm.d.vue.ts +26 -0
- package/dist/runtime/internal/admin/OptionPageForm.vue +222 -0
- package/dist/runtime/internal/admin/OptionPageForm.vue.d.ts +26 -0
- package/dist/runtime/internal/admin/UserAvatarField.d.vue.ts +12 -0
- package/dist/runtime/internal/admin/UserAvatarField.vue +305 -0
- package/dist/runtime/internal/admin/UserAvatarField.vue.d.ts +12 -0
- package/dist/runtime/internal/fields/AccordionField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/AccordionField.vue +220 -0
- package/dist/runtime/internal/fields/AccordionField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/ButtonGroupField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/ButtonGroupField.vue +109 -0
- package/dist/runtime/internal/fields/ButtonGroupField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/CheckboxField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/CheckboxField.vue +190 -0
- package/dist/runtime/internal/fields/CheckboxField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/ColorPickerField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/ColorPickerField.vue +791 -0
- package/dist/runtime/internal/fields/ColorPickerField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/DatePickerField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/DatePickerField.vue +26 -0
- package/dist/runtime/internal/fields/DatePickerField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/DateTimePickerField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/DateTimePickerField.vue +26 -0
- package/dist/runtime/internal/fields/DateTimePickerField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/DictionaryField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/DictionaryField.vue +345 -0
- package/dist/runtime/internal/fields/DictionaryField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/EmailField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/EmailField.vue +21 -0
- package/dist/runtime/internal/fields/EmailField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/FileField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/FileField.vue +408 -0
- package/dist/runtime/internal/fields/FileField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/FlexibleContentField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/FlexibleContentField.vue +1114 -0
- package/dist/runtime/internal/fields/FlexibleContentField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/GalleryField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/GalleryField.vue +584 -0
- package/dist/runtime/internal/fields/GalleryField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/GroupField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/GroupField.vue +111 -0
- package/dist/runtime/internal/fields/GroupField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/ImageField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/ImageField.vue +638 -0
- package/dist/runtime/internal/fields/ImageField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/ImageSelectField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/ImageSelectField.vue +179 -0
- package/dist/runtime/internal/fields/ImageSelectField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/LinkField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/LinkField.vue +303 -0
- package/dist/runtime/internal/fields/LinkField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/NumberField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/NumberField.vue +25 -0
- package/dist/runtime/internal/fields/NumberField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/OembedField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/OembedField.vue +161 -0
- package/dist/runtime/internal/fields/OembedField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/OpenStreetMapField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/OpenStreetMapField.vue +1502 -0
- package/dist/runtime/internal/fields/OpenStreetMapField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/PageLinkField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/PageLinkField.vue +153 -0
- package/dist/runtime/internal/fields/PageLinkField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/PasswordField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/PasswordField.vue +108 -0
- package/dist/runtime/internal/fields/PasswordField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/PostObjectField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/PostObjectField.vue +151 -0
- package/dist/runtime/internal/fields/PostObjectField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/RadioField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/RadioField.vue +163 -0
- package/dist/runtime/internal/fields/RadioField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/RangeField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/RangeField.vue +48 -0
- package/dist/runtime/internal/fields/RangeField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/RelationshipField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/RelationshipField.vue +525 -0
- package/dist/runtime/internal/fields/RelationshipField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/RepeaterField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/RepeaterField.vue +856 -0
- package/dist/runtime/internal/fields/RepeaterField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/SelectField.d.vue.ts +21 -0
- package/dist/runtime/internal/fields/SelectField.vue +101 -0
- package/dist/runtime/internal/fields/SelectField.vue.d.ts +21 -0
- package/dist/runtime/internal/fields/SeparatorField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/SeparatorField.vue +63 -0
- package/dist/runtime/internal/fields/SeparatorField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/TabField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/TabField.vue +210 -0
- package/dist/runtime/internal/fields/TabField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/TextField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/TextField.vue +22 -0
- package/dist/runtime/internal/fields/TextField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/TextareaField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/TextareaField.vue +62 -0
- package/dist/runtime/internal/fields/TextareaField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/TimePickerField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/TimePickerField.vue +24 -0
- package/dist/runtime/internal/fields/TimePickerField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/TrueFalseField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/TrueFalseField.vue +151 -0
- package/dist/runtime/internal/fields/TrueFalseField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/UrlField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/UrlField.vue +21 -0
- package/dist/runtime/internal/fields/UrlField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/UserField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/UserField.vue +164 -0
- package/dist/runtime/internal/fields/UserField.vue.d.ts +0 -0
- package/dist/runtime/internal/fields/WysiwygField.d.vue.ts +0 -0
- package/dist/runtime/internal/fields/WysiwygField.vue +971 -0
- package/dist/runtime/internal/fields/WysiwygField.vue.d.ts +0 -0
- package/dist/runtime/internal/parts/DateTimeControl.d.vue.ts +90 -0
- package/dist/runtime/internal/parts/DateTimeControl.vue +568 -0
- package/dist/runtime/internal/parts/DateTimeControl.vue.d.ts +90 -0
- package/dist/runtime/internal/parts/FieldAddon.d.vue.ts +0 -0
- package/dist/runtime/internal/parts/FieldAddon.vue +43 -0
- package/dist/runtime/internal/parts/FieldAddon.vue.d.ts +0 -0
- package/dist/runtime/internal/parts/FieldInstructions.d.vue.ts +0 -0
- package/dist/runtime/internal/parts/FieldInstructions.vue +24 -0
- package/dist/runtime/internal/parts/FieldInstructions.vue.d.ts +0 -0
- package/dist/runtime/internal/parts/FieldLabel.d.vue.ts +0 -0
- package/dist/runtime/internal/parts/FieldLabel.vue +40 -0
- package/dist/runtime/internal/parts/FieldLabel.vue.d.ts +0 -0
- package/dist/runtime/internal/parts/FieldWrapper.d.vue.ts +0 -0
- package/dist/runtime/internal/parts/FieldWrapper.vue +47 -0
- package/dist/runtime/internal/parts/FieldWrapper.vue.d.ts +0 -0
- package/dist/runtime/internal/parts/ImageCropper.d.vue.ts +17 -0
- package/dist/runtime/internal/parts/ImageCropper.vue +363 -0
- package/dist/runtime/internal/parts/ImageCropper.vue.d.ts +17 -0
- package/dist/runtime/internal/parts/InputControl.d.vue.ts +0 -0
- package/dist/runtime/internal/parts/InputControl.vue +163 -0
- package/dist/runtime/internal/parts/InputControl.vue.d.ts +0 -0
- package/dist/runtime/internal/ui/UiButton.d.vue.ts +35 -0
- package/dist/runtime/internal/ui/UiButton.vue +204 -0
- package/dist/runtime/internal/ui/UiButton.vue.d.ts +35 -0
- package/dist/runtime/internal/ui/UiNotice.d.vue.ts +40 -0
- package/dist/runtime/internal/ui/UiNotice.vue +253 -0
- package/dist/runtime/internal/ui/UiNotice.vue.d.ts +40 -0
- package/dist/runtime/internal/ui/UiSelect.d.vue.ts +61 -0
- package/dist/runtime/internal/ui/UiSelect.vue +1212 -0
- package/dist/runtime/internal/ui/UiSelect.vue.d.ts +61 -0
- package/dist/runtime/middleware/auth-guard.d.ts +9 -0
- package/dist/runtime/middleware/auth-guard.js +37 -0
- package/dist/runtime/pages/admin/collections/[id].d.vue.ts +3 -0
- package/dist/runtime/pages/admin/collections/[id].vue +423 -0
- package/dist/runtime/pages/admin/collections/[id].vue.d.ts +3 -0
- package/dist/runtime/pages/admin/collections/create.d.vue.ts +3 -0
- package/dist/runtime/pages/admin/collections/create.vue +179 -0
- package/dist/runtime/pages/admin/collections/create.vue.d.ts +3 -0
- package/dist/runtime/pages/admin/collections/index.d.vue.ts +3 -0
- package/dist/runtime/pages/admin/collections/index.vue +828 -0
- package/dist/runtime/pages/admin/collections/index.vue.d.ts +3 -0
- package/dist/runtime/pages/admin/demo-fields.d.vue.ts +3 -0
- package/dist/runtime/pages/admin/demo-fields.vue +1327 -0
- package/dist/runtime/pages/admin/demo-fields.vue.d.ts +3 -0
- package/dist/runtime/pages/admin/dictionaries/[id].d.vue.ts +3 -0
- package/dist/runtime/pages/admin/dictionaries/[id].vue +213 -0
- package/dist/runtime/pages/admin/dictionaries/[id].vue.d.ts +3 -0
- package/dist/runtime/pages/admin/dictionaries/index.d.vue.ts +3 -0
- package/dist/runtime/pages/admin/dictionaries/index.vue +387 -0
- package/dist/runtime/pages/admin/dictionaries/index.vue.d.ts +3 -0
- package/dist/runtime/pages/admin/index.d.vue.ts +3 -0
- package/dist/runtime/pages/admin/index.vue +138 -0
- package/dist/runtime/pages/admin/index.vue.d.ts +3 -0
- package/dist/runtime/pages/admin/login.d.vue.ts +3 -0
- package/dist/runtime/pages/admin/login.vue +373 -0
- package/dist/runtime/pages/admin/login.vue.d.ts +3 -0
- package/dist/runtime/pages/admin/media.d.vue.ts +3 -0
- package/dist/runtime/pages/admin/media.vue +1054 -0
- package/dist/runtime/pages/admin/media.vue.d.ts +3 -0
- package/dist/runtime/pages/admin/options/[page].d.vue.ts +3 -0
- package/dist/runtime/pages/admin/options/[page].vue +151 -0
- package/dist/runtime/pages/admin/options/[page].vue.d.ts +3 -0
- package/dist/runtime/pages/admin/register.d.vue.ts +3 -0
- package/dist/runtime/pages/admin/register.vue +391 -0
- package/dist/runtime/pages/admin/register.vue.d.ts +3 -0
- package/dist/runtime/pages/admin/users/[id].d.vue.ts +3 -0
- package/dist/runtime/pages/admin/users/[id].vue +337 -0
- package/dist/runtime/pages/admin/users/[id].vue.d.ts +3 -0
- package/dist/runtime/pages/admin/users/create.d.vue.ts +3 -0
- package/dist/runtime/pages/admin/users/create.vue +201 -0
- package/dist/runtime/pages/admin/users/create.vue.d.ts +3 -0
- package/dist/runtime/pages/admin/users/index.d.vue.ts +3 -0
- package/dist/runtime/pages/admin/users/index.vue +329 -0
- package/dist/runtime/pages/admin/users/index.vue.d.ts +3 -0
- package/dist/runtime/pages/index.d.vue.ts +3 -0
- package/dist/runtime/pages/index.vue +399 -0
- package/dist/runtime/pages/index.vue.d.ts +3 -0
- package/dist/runtime/server/api/_katecms/auth/login.post.d.ts +5 -0
- package/dist/runtime/server/api/_katecms/auth/login.post.js +44 -0
- package/dist/runtime/server/api/_katecms/auth/logout.post.d.ts +4 -0
- package/dist/runtime/server/api/_katecms/auth/logout.post.js +6 -0
- package/dist/runtime/server/api/_katecms/auth/register.post.d.ts +19 -0
- package/dist/runtime/server/api/_katecms/auth/register.post.js +83 -0
- package/dist/runtime/server/api/_katecms/auth/state.get.d.ts +9 -0
- package/dist/runtime/server/api/_katecms/auth/state.get.js +12 -0
- package/dist/runtime/server/api/_katecms/collections/[collection]/[id].delete.d.ts +15 -0
- package/dist/runtime/server/api/_katecms/collections/[collection]/[id].delete.js +59 -0
- package/dist/runtime/server/api/_katecms/collections/[collection]/[id].get.d.ts +4 -0
- package/dist/runtime/server/api/_katecms/collections/[collection]/[id].get.js +50 -0
- package/dist/runtime/server/api/_katecms/collections/[collection]/[id].patch.d.ts +4 -0
- package/dist/runtime/server/api/_katecms/collections/[collection]/[id].patch.js +130 -0
- package/dist/runtime/server/api/_katecms/collections/[collection]/revisions/[revisionId].post.d.ts +4 -0
- package/dist/runtime/server/api/_katecms/collections/[collection]/revisions/[revisionId].post.js +123 -0
- package/dist/runtime/server/api/_katecms/collections/[collection]/revisions.get.d.ts +6 -0
- package/dist/runtime/server/api/_katecms/collections/[collection]/revisions.get.js +31 -0
- package/dist/runtime/server/api/_katecms/collections/[collection].get.d.ts +8 -0
- package/dist/runtime/server/api/_katecms/collections/[collection].get.js +135 -0
- package/dist/runtime/server/api/_katecms/collections/[collection].post.d.ts +4 -0
- package/dist/runtime/server/api/_katecms/collections/[collection].post.js +91 -0
- package/dist/runtime/server/api/_katecms/dictionaries/[dictionary]/[id].delete.d.ts +7 -0
- package/dist/runtime/server/api/_katecms/dictionaries/[dictionary]/[id].delete.js +31 -0
- package/dist/runtime/server/api/_katecms/dictionaries/[dictionary]/[id].get.d.ts +4 -0
- package/dist/runtime/server/api/_katecms/dictionaries/[dictionary]/[id].get.js +45 -0
- package/dist/runtime/server/api/_katecms/dictionaries/[dictionary]/[id].patch.d.ts +4 -0
- package/dist/runtime/server/api/_katecms/dictionaries/[dictionary]/[id].patch.js +83 -0
- package/dist/runtime/server/api/_katecms/dictionaries/[dictionary].get.d.ts +4 -0
- package/dist/runtime/server/api/_katecms/dictionaries/[dictionary].get.js +38 -0
- package/dist/runtime/server/api/_katecms/dictionaries/[dictionary].post.d.ts +4 -0
- package/dist/runtime/server/api/_katecms/dictionaries/[dictionary].post.js +64 -0
- package/dist/runtime/server/api/_katecms/media/[id]/regenerate.post.d.ts +8 -0
- package/dist/runtime/server/api/_katecms/media/[id]/regenerate.post.js +30 -0
- package/dist/runtime/server/api/_katecms/media/[id].delete.d.ts +7 -0
- package/dist/runtime/server/api/_katecms/media/[id].delete.js +22 -0
- package/dist/runtime/server/api/_katecms/media/[id].get.d.ts +9 -0
- package/dist/runtime/server/api/_katecms/media/[id].get.js +17 -0
- package/dist/runtime/server/api/_katecms/media/[id].patch.d.ts +6 -0
- package/dist/runtime/server/api/_katecms/media/[id].patch.js +48 -0
- package/dist/runtime/server/api/_katecms/media/index.get.d.ts +5 -0
- package/dist/runtime/server/api/_katecms/media/index.get.js +75 -0
- package/dist/runtime/server/api/_katecms/media/index.post.d.ts +9 -0
- package/dist/runtime/server/api/_katecms/media/index.post.js +84 -0
- package/dist/runtime/server/api/_katecms/media/regenerate.post.d.ts +7 -0
- package/dist/runtime/server/api/_katecms/media/regenerate.post.js +30 -0
- package/dist/runtime/server/api/_katecms/menu.get.d.ts +8 -0
- package/dist/runtime/server/api/_katecms/menu.get.js +14 -0
- package/dist/runtime/server/api/_katecms/oembed.get.d.ts +2 -0
- package/dist/runtime/server/api/_katecms/oembed.get.js +53 -0
- package/dist/runtime/server/api/_katecms/options/[page].get.d.ts +7 -0
- package/dist/runtime/server/api/_katecms/options/[page].get.js +28 -0
- package/dist/runtime/server/api/_katecms/options/[page].patch.d.ts +4 -0
- package/dist/runtime/server/api/_katecms/options/[page].patch.js +36 -0
- package/dist/runtime/server/api/_katecms/query.get.d.ts +24 -0
- package/dist/runtime/server/api/_katecms/query.get.js +270 -0
- package/dist/runtime/server/api/_katecms/relation/entries.get.d.ts +17 -0
- package/dist/runtime/server/api/_katecms/relation/entries.get.js +74 -0
- package/dist/runtime/server/api/_katecms/relation/terms.get.d.ts +17 -0
- package/dist/runtime/server/api/_katecms/relation/terms.get.js +51 -0
- package/dist/runtime/server/api/_katecms/resolve.get.d.ts +17 -0
- package/dist/runtime/server/api/_katecms/resolve.get.js +116 -0
- package/dist/runtime/server/api/_katecms/terms.get.d.ts +20 -0
- package/dist/runtime/server/api/_katecms/terms.get.js +201 -0
- package/dist/runtime/server/api/_katecms/users/[id].delete.d.ts +11 -0
- package/dist/runtime/server/api/_katecms/users/[id].delete.js +45 -0
- package/dist/runtime/server/api/_katecms/users/[id].patch.d.ts +19 -0
- package/dist/runtime/server/api/_katecms/users/[id].patch.js +129 -0
- package/dist/runtime/server/api/_katecms/users.get.d.ts +10 -0
- package/dist/runtime/server/api/_katecms/users.get.js +34 -0
- package/dist/runtime/server/api/_katecms/users.post.d.ts +10 -0
- package/dist/runtime/server/api/_katecms/users.post.js +62 -0
- package/dist/runtime/server/api/uploads/[...key].get.d.ts +3 -0
- package/dist/runtime/server/api/uploads/[...key].get.js +28 -0
- package/dist/runtime/server/kit.d.ts +5 -0
- package/dist/runtime/server/kit.js +5 -0
- package/dist/runtime/server/middleware/admin-headers.d.ts +3 -0
- package/dist/runtime/server/middleware/admin-headers.js +12 -0
- package/dist/runtime/server/plugins/auto-migrate.d.ts +2 -0
- package/dist/runtime/server/plugins/auto-migrate.js +45 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/runtime/server/utils/auth-attempts.d.ts +22 -0
- package/dist/runtime/server/utils/auth-attempts.js +42 -0
- package/dist/runtime/server/utils/auth-rate-limit.d.ts +11 -0
- package/dist/runtime/server/utils/auth-rate-limit.js +36 -0
- package/dist/runtime/server/utils/client-address.d.ts +16 -0
- package/dist/runtime/server/utils/client-address.js +23 -0
- package/dist/runtime/server/utils/collections.d.ts +42 -0
- package/dist/runtime/server/utils/collections.js +300 -0
- package/dist/runtime/server/utils/db.d.ts +3 -0
- package/dist/runtime/server/utils/db.js +25 -0
- package/dist/runtime/server/utils/dictionaries.d.ts +53 -0
- package/dist/runtime/server/utils/dictionaries.js +301 -0
- package/dist/runtime/server/utils/media-list.d.ts +18 -0
- package/dist/runtime/server/utils/media-list.js +84 -0
- package/dist/runtime/server/utils/media.d.ts +12 -0
- package/dist/runtime/server/utils/media.js +77 -0
- package/dist/runtime/server/utils/oembed-fetch.d.ts +4 -0
- package/dist/runtime/server/utils/oembed-fetch.js +142 -0
- package/dist/runtime/server/utils/options.d.ts +17 -0
- package/dist/runtime/server/utils/options.js +66 -0
- package/dist/runtime/server/utils/permissions.d.ts +13 -0
- package/dist/runtime/server/utils/permissions.js +20 -0
- package/dist/runtime/server/utils/public-fields-query.d.ts +6 -0
- package/dist/runtime/server/utils/public-fields-query.js +8 -0
- package/dist/runtime/server/utils/public-term.d.ts +8 -0
- package/dist/runtime/server/utils/public-term.js +80 -0
- package/dist/runtime/server/utils/regenerate.d.ts +12 -0
- package/dist/runtime/server/utils/regenerate.js +40 -0
- package/dist/runtime/server/utils/relation.d.ts +18 -0
- package/dist/runtime/server/utils/relation.js +77 -0
- package/dist/runtime/server/utils/request-address.d.ts +6 -0
- package/dist/runtime/server/utils/request-address.js +10 -0
- package/dist/runtime/server/utils/revisions.d.ts +20 -0
- package/dist/runtime/server/utils/revisions.js +172 -0
- package/dist/runtime/server/utils/session.d.ts +18 -0
- package/dist/runtime/server/utils/session.js +71 -0
- package/dist/runtime/server/utils/upload-headers.d.ts +2 -0
- package/dist/runtime/server/utils/upload-headers.js +30 -0
- package/dist/runtime/server/utils/users.d.ts +13 -0
- package/dist/runtime/server/utils/users.js +47 -0
- package/dist/runtime/utils/admin-users.d.ts +20 -0
- package/dist/runtime/utils/admin-users.js +19 -0
- package/dist/runtime/utils/auth-error.d.ts +6 -0
- package/dist/runtime/utils/auth-error.js +11 -0
- package/dist/runtime/utils/cms-paths.d.ts +5 -0
- package/dist/runtime/utils/cms-paths.js +13 -0
- package/dist/runtime/utils/collections.d.ts +176 -0
- package/dist/runtime/utils/collections.js +30 -0
- package/dist/runtime/utils/dictionaries.d.ts +65 -0
- package/dist/runtime/utils/dictionaries.js +14 -0
- package/dist/runtime/utils/field-errors.d.ts +4 -0
- package/dist/runtime/utils/field-errors.js +9 -0
- package/dist/runtime/utils/field-values.d.ts +19 -0
- package/dist/runtime/utils/field-values.js +82 -0
- package/dist/runtime/utils/helpers.d.ts +4 -0
- package/dist/runtime/utils/helpers.js +20 -0
- package/dist/runtime/utils/media-library-query.d.ts +54 -0
- package/dist/runtime/utils/media-library-query.js +190 -0
- package/dist/runtime/utils/options.d.ts +19 -0
- package/dist/runtime/utils/options.js +3 -0
- package/dist/runtime/utils/preview.d.ts +22 -0
- package/dist/runtime/utils/preview.js +33 -0
- package/dist/runtime/utils/relation.d.ts +33 -0
- package/dist/runtime/utils/relation.js +23 -0
- package/dist/runtime/utils/slugify.d.ts +2 -0
- package/dist/runtime/utils/slugify.js +4 -0
- package/dist/types.d.mts +7 -0
- package/package.json +84 -3
- package/src/admin-components.ts +124 -0
- package/src/module.ts +592 -0
- package/src/runtime/assets/img/katecms-logo.svg +17 -0
- package/src/runtime/assets/styles/_functions.scss +70 -0
- package/src/runtime/assets/styles/_index.scss +3 -0
- package/src/runtime/assets/styles/_mixins.scss +256 -0
- package/src/runtime/assets/styles/_variables.scss +35 -0
- package/src/runtime/composables/getCollection.ts +253 -0
- package/src/runtime/composables/getOptions.ts +42 -0
- package/src/runtime/composables/getQueryCollection.ts +325 -0
- package/src/runtime/composables/getTerms.ts +231 -0
- package/src/runtime/composables/useAuth.ts +43 -0
- package/src/runtime/composables/useAuthCooldown.ts +52 -0
- package/src/runtime/composables/useCmsPaths.ts +24 -0
- package/src/runtime/composables/useKateCmsExtensions.ts +81 -0
- package/src/runtime/composables/useMediaLibrary.ts +168 -0
- package/src/runtime/composables/useMenuAccess.ts +25 -0
- package/src/runtime/internal/admin/AdminHeader.vue +106 -0
- package/src/runtime/internal/admin/AppMenu.vue +290 -0
- package/src/runtime/internal/admin/AppUser.vue +260 -0
- package/src/runtime/internal/admin/CollectionEntryForm.vue +1044 -0
- package/src/runtime/internal/admin/ConfirmDialog.vue +164 -0
- package/src/runtime/internal/admin/DictionaryTermForm.vue +400 -0
- package/src/runtime/internal/admin/EntryRevisions.vue +145 -0
- package/src/runtime/internal/admin/MediaLibraryFilters.vue +186 -0
- package/src/runtime/internal/admin/MediaLibraryModal.vue +526 -0
- package/src/runtime/internal/admin/OptionPageForm.vue +277 -0
- package/src/runtime/internal/admin/UserAvatarField.vue +337 -0
- package/src/runtime/internal/fields/AccordionField.vue +258 -0
- package/src/runtime/internal/fields/ButtonGroupField.vue +144 -0
- package/src/runtime/internal/fields/CheckboxField.vue +228 -0
- package/src/runtime/internal/fields/ColorPickerField.vue +926 -0
- package/src/runtime/internal/fields/DatePickerField.vue +33 -0
- package/src/runtime/internal/fields/DateTimePickerField.vue +33 -0
- package/src/runtime/internal/fields/DictionaryField.vue +403 -0
- package/src/runtime/internal/fields/EmailField.vue +28 -0
- package/src/runtime/internal/fields/FileField.vue +480 -0
- package/src/runtime/internal/fields/FlexibleContentField.vue +1296 -0
- package/src/runtime/internal/fields/GalleryField.vue +677 -0
- package/src/runtime/internal/fields/GroupField.vue +136 -0
- package/src/runtime/internal/fields/ImageField.vue +730 -0
- package/src/runtime/internal/fields/ImageSelectField.vue +213 -0
- package/src/runtime/internal/fields/LinkField.vue +338 -0
- package/src/runtime/internal/fields/NumberField.vue +32 -0
- package/src/runtime/internal/fields/OembedField.vue +187 -0
- package/src/runtime/internal/fields/OpenStreetMapField.vue +1716 -0
- package/src/runtime/internal/fields/PageLinkField.vue +186 -0
- package/src/runtime/internal/fields/PasswordField.vue +127 -0
- package/src/runtime/internal/fields/PostObjectField.vue +187 -0
- package/src/runtime/internal/fields/RadioField.vue +195 -0
- package/src/runtime/internal/fields/RangeField.vue +62 -0
- package/src/runtime/internal/fields/RelationshipField.vue +604 -0
- package/src/runtime/internal/fields/RepeaterField.vue +999 -0
- package/src/runtime/internal/fields/SelectField.vue +118 -0
- package/src/runtime/internal/fields/SeparatorField.vue +77 -0
- package/src/runtime/internal/fields/TabField.vue +249 -0
- package/src/runtime/internal/fields/TextField.vue +29 -0
- package/src/runtime/internal/fields/TextareaField.vue +61 -0
- package/src/runtime/internal/fields/TimePickerField.vue +31 -0
- package/src/runtime/internal/fields/TrueFalseField.vue +181 -0
- package/src/runtime/internal/fields/UrlField.vue +28 -0
- package/src/runtime/internal/fields/UserField.vue +203 -0
- package/src/runtime/internal/fields/WysiwygField.vue +1061 -0
- package/src/runtime/internal/parts/DateTimeControl.vue +657 -0
- package/src/runtime/internal/parts/FieldAddon.vue +60 -0
- package/src/runtime/internal/parts/FieldInstructions.vue +38 -0
- package/src/runtime/internal/parts/FieldLabel.vue +56 -0
- package/src/runtime/internal/parts/FieldWrapper.vue +63 -0
- package/src/runtime/internal/parts/ImageCropper.vue +415 -0
- package/src/runtime/internal/parts/InputControl.vue +189 -0
- package/src/runtime/internal/ui/UiButton.vue +274 -0
- package/src/runtime/internal/ui/UiNotice.vue +302 -0
- package/src/runtime/internal/ui/UiSelect.vue +1420 -0
- package/src/runtime/middleware/auth-guard.ts +52 -0
- package/src/runtime/pages/admin/collections/[id].vue +486 -0
- package/src/runtime/pages/admin/collections/create.vue +208 -0
- package/src/runtime/pages/admin/collections/index.vue +955 -0
- package/src/runtime/pages/admin/demo-fields.vue +1354 -0
- package/src/runtime/pages/admin/dictionaries/[id].vue +246 -0
- package/src/runtime/pages/admin/dictionaries/index.vue +438 -0
- package/src/runtime/pages/admin/index.vue +155 -0
- package/src/runtime/pages/admin/login.vue +159 -0
- package/src/runtime/pages/admin/media.vue +1176 -0
- package/src/runtime/pages/admin/options/[page].vue +174 -0
- package/src/runtime/pages/admin/register.vue +179 -0
- package/src/runtime/pages/admin/users/[id].vue +382 -0
- package/src/runtime/pages/admin/users/create.vue +232 -0
- package/src/runtime/pages/admin/users/index.vue +374 -0
- package/src/runtime/pages/index.vue +265 -0
- package/src/runtime/server/api/_katecms/auth/login.post.ts +62 -0
- package/src/runtime/server/api/_katecms/auth/logout.post.ts +7 -0
- package/src/runtime/server/api/_katecms/auth/register.post.ts +112 -0
- package/src/runtime/server/api/_katecms/auth/state.get.ts +19 -0
- package/src/runtime/server/api/_katecms/collections/[collection]/[id].delete.ts +77 -0
- package/src/runtime/server/api/_katecms/collections/[collection]/[id].get.ts +57 -0
- package/src/runtime/server/api/_katecms/collections/[collection]/[id].patch.ts +157 -0
- package/src/runtime/server/api/_katecms/collections/[collection]/revisions/[revisionId].post.ts +133 -0
- package/src/runtime/server/api/_katecms/collections/[collection]/revisions.get.ts +35 -0
- package/src/runtime/server/api/_katecms/collections/[collection].get.ts +177 -0
- package/src/runtime/server/api/_katecms/collections/[collection].post.ts +111 -0
- package/src/runtime/server/api/_katecms/dictionaries/[dictionary]/[id].delete.ts +37 -0
- package/src/runtime/server/api/_katecms/dictionaries/[dictionary]/[id].get.ts +51 -0
- package/src/runtime/server/api/_katecms/dictionaries/[dictionary]/[id].patch.ts +101 -0
- package/src/runtime/server/api/_katecms/dictionaries/[dictionary].get.ts +43 -0
- package/src/runtime/server/api/_katecms/dictionaries/[dictionary].post.ts +78 -0
- package/src/runtime/server/api/_katecms/media/[id]/regenerate.post.ts +39 -0
- package/src/runtime/server/api/_katecms/media/[id].delete.ts +28 -0
- package/src/runtime/server/api/_katecms/media/[id].get.ts +25 -0
- package/src/runtime/server/api/_katecms/media/[id].patch.ts +60 -0
- package/src/runtime/server/api/_katecms/media/index.get.ts +96 -0
- package/src/runtime/server/api/_katecms/media/index.post.ts +104 -0
- package/src/runtime/server/api/_katecms/media/regenerate.post.ts +38 -0
- package/src/runtime/server/api/_katecms/menu.get.ts +19 -0
- package/src/runtime/server/api/_katecms/oembed.get.ts +62 -0
- package/src/runtime/server/api/_katecms/options/[page].get.ts +35 -0
- package/src/runtime/server/api/_katecms/options/[page].patch.ts +46 -0
- package/src/runtime/server/api/_katecms/query.get.ts +332 -0
- package/src/runtime/server/api/_katecms/relation/entries.get.ts +98 -0
- package/src/runtime/server/api/_katecms/relation/terms.get.ts +61 -0
- package/src/runtime/server/api/_katecms/resolve.get.ts +148 -0
- package/src/runtime/server/api/_katecms/terms.get.ts +258 -0
- package/src/runtime/server/api/_katecms/users/[id].delete.ts +57 -0
- package/src/runtime/server/api/_katecms/users/[id].patch.ts +177 -0
- package/src/runtime/server/api/_katecms/users.get.ts +48 -0
- package/src/runtime/server/api/_katecms/users.post.ts +85 -0
- package/src/runtime/server/api/uploads/[...key].get.ts +33 -0
- package/src/runtime/server/kit.ts +5 -0
- package/src/runtime/server/middleware/admin-headers.ts +14 -0
- package/src/runtime/server/plugins/auto-migrate.ts +53 -0
- package/src/runtime/server/tsconfig.json +3 -0
- package/src/runtime/server/utils/auth-attempts.ts +71 -0
- package/src/runtime/server/utils/auth-rate-limit.ts +48 -0
- package/src/runtime/server/utils/client-address.ts +41 -0
- package/src/runtime/server/utils/collections.ts +381 -0
- package/src/runtime/server/utils/db.ts +36 -0
- package/src/runtime/server/utils/dictionaries.ts +397 -0
- package/src/runtime/server/utils/media-list.ts +131 -0
- package/src/runtime/server/utils/media.ts +94 -0
- package/src/runtime/server/utils/oembed-fetch.ts +157 -0
- package/src/runtime/server/utils/options.ts +86 -0
- package/src/runtime/server/utils/permissions.ts +44 -0
- package/src/runtime/server/utils/public-fields-query.ts +14 -0
- package/src/runtime/server/utils/public-term.ts +98 -0
- package/src/runtime/server/utils/regenerate.ts +56 -0
- package/src/runtime/server/utils/relation.ts +96 -0
- package/src/runtime/server/utils/request-address.ts +16 -0
- package/src/runtime/server/utils/revisions.ts +256 -0
- package/src/runtime/server/utils/session.ts +112 -0
- package/src/runtime/server/utils/upload-headers.ts +35 -0
- package/src/runtime/server/utils/users.ts +67 -0
- package/src/runtime/utils/admin-users.ts +43 -0
- package/src/runtime/utils/auth-error.ts +22 -0
- package/src/runtime/utils/cms-paths.ts +17 -0
- package/src/runtime/utils/collections.ts +228 -0
- package/src/runtime/utils/dictionaries.ts +89 -0
- package/src/runtime/utils/field-errors.ts +12 -0
- package/src/runtime/utils/field-values.ts +101 -0
- package/src/runtime/utils/helpers.ts +33 -0
- package/src/runtime/utils/media-library-query.ts +263 -0
- package/src/runtime/utils/options.ts +25 -0
- package/src/runtime/utils/preview.ts +56 -0
- package/src/runtime/utils/relation.ts +60 -0
- package/src/runtime/utils/slugify.ts +10 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { defineEventHandler, getQuery } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
import {
|
|
4
|
+
buildSlugPathMap,
|
|
5
|
+
can,
|
|
6
|
+
collectionListPaging,
|
|
7
|
+
collectionPerPage,
|
|
8
|
+
countCollections,
|
|
9
|
+
findCollectionBySlugPath,
|
|
10
|
+
listCollections,
|
|
11
|
+
matchPublicCollectionRoute
|
|
12
|
+
} from "@katecms/core";
|
|
13
|
+
import { getDb } from "../../utils/db.js";
|
|
14
|
+
import { getCurrentUser } from "../../utils/session.js";
|
|
15
|
+
import {
|
|
16
|
+
fail,
|
|
17
|
+
getCollectionDefinition,
|
|
18
|
+
getCollections,
|
|
19
|
+
readPage,
|
|
20
|
+
readPerPage,
|
|
21
|
+
toAdminEntry,
|
|
22
|
+
toCollectionMeta
|
|
23
|
+
} from "../../utils/collections.js";
|
|
24
|
+
import { loadAssignedEntryDictionaries } from "../../utils/dictionaries.js";
|
|
25
|
+
import { resolvePublicDictionaryTerm } from "../../utils/public-term.js";
|
|
26
|
+
import {
|
|
27
|
+
isTruthyQueryParam,
|
|
28
|
+
parsePublicStatusParam,
|
|
29
|
+
resolvePublicStatuses
|
|
30
|
+
} from "../../../utils/preview.js";
|
|
31
|
+
function listStatusFromPublic(statuses) {
|
|
32
|
+
const published = statuses.includes("published");
|
|
33
|
+
const draft = statuses.includes("draft");
|
|
34
|
+
if (published && draft) {
|
|
35
|
+
return "active";
|
|
36
|
+
}
|
|
37
|
+
if (draft) {
|
|
38
|
+
return "draft";
|
|
39
|
+
}
|
|
40
|
+
return "published";
|
|
41
|
+
}
|
|
42
|
+
export default defineEventHandler(async (event) => {
|
|
43
|
+
const query = getQuery(event);
|
|
44
|
+
const path = typeof query.path === "string" ? query.path : "";
|
|
45
|
+
if (!path.trim()) {
|
|
46
|
+
fail(400, "Missing path.");
|
|
47
|
+
}
|
|
48
|
+
const collections = getCollections();
|
|
49
|
+
const matched = matchPublicCollectionRoute(collections, path);
|
|
50
|
+
if (!matched) {
|
|
51
|
+
const db2 = getDb();
|
|
52
|
+
const termPage = await resolvePublicDictionaryTerm(db2, path);
|
|
53
|
+
if (termPage) {
|
|
54
|
+
return termPage;
|
|
55
|
+
}
|
|
56
|
+
fail(404, "Page not found.");
|
|
57
|
+
}
|
|
58
|
+
const def = getCollectionDefinition(matched.collectionSlug);
|
|
59
|
+
if (!def || def.public === false) {
|
|
60
|
+
fail(404, "Page not found.");
|
|
61
|
+
}
|
|
62
|
+
const previewRequested = isTruthyQueryParam(query.preview);
|
|
63
|
+
const actor = previewRequested ? await getCurrentUser(event) : null;
|
|
64
|
+
const roles = useRuntimeConfig().katecms?.roles ?? {};
|
|
65
|
+
const previewAllowed = actor != null && can(actor, "collections", "read", { roles, scope: matched.collectionSlug });
|
|
66
|
+
const { statuses, preview } = resolvePublicStatuses({
|
|
67
|
+
previewRequested,
|
|
68
|
+
previewAllowed,
|
|
69
|
+
requested: parsePublicStatusParam(query.status)
|
|
70
|
+
});
|
|
71
|
+
const db = getDb();
|
|
72
|
+
const meta = toCollectionMeta(matched.collectionSlug, def);
|
|
73
|
+
if (matched.kind === "archive") {
|
|
74
|
+
const page = readPage(query.page);
|
|
75
|
+
const perPage = readPerPage(query.perPage, collectionPerPage(def));
|
|
76
|
+
const listStatus = listStatusFromPublic(statuses);
|
|
77
|
+
const [rows, total, pathRows] = await Promise.all([
|
|
78
|
+
listCollections(db, matched.collectionSlug, {
|
|
79
|
+
status: listStatus,
|
|
80
|
+
...collectionListPaging(page, perPage)
|
|
81
|
+
}),
|
|
82
|
+
countCollections(db, matched.collectionSlug, { status: listStatus }),
|
|
83
|
+
db.selectFrom("collections").select(["id", "slug", "parent_id"]).where("type", "=", matched.collectionSlug).execute()
|
|
84
|
+
]);
|
|
85
|
+
const paths = buildSlugPathMap(pathRows);
|
|
86
|
+
const entries = await Promise.all(rows.map(async (row2) => {
|
|
87
|
+
const dictionaries2 = await loadAssignedEntryDictionaries(db, row2.id, matched.collectionSlug);
|
|
88
|
+
return toAdminEntry(row2, paths.get(row2.id) ?? row2.slug, { dictionaries: dictionaries2 });
|
|
89
|
+
}));
|
|
90
|
+
return {
|
|
91
|
+
kind: "archive",
|
|
92
|
+
collection: meta,
|
|
93
|
+
entries,
|
|
94
|
+
preview,
|
|
95
|
+
page,
|
|
96
|
+
perPage,
|
|
97
|
+
total
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const row = await findCollectionBySlugPath(
|
|
101
|
+
db,
|
|
102
|
+
matched.collectionSlug,
|
|
103
|
+
matched.segments,
|
|
104
|
+
statuses
|
|
105
|
+
);
|
|
106
|
+
if (!row) {
|
|
107
|
+
fail(404, "Page not found.");
|
|
108
|
+
}
|
|
109
|
+
const dictionaries = await loadAssignedEntryDictionaries(db, row.id, matched.collectionSlug);
|
|
110
|
+
return {
|
|
111
|
+
kind: "entry",
|
|
112
|
+
collection: meta,
|
|
113
|
+
entry: toAdminEntry(row, matched.slugPath, { dictionaries }),
|
|
114
|
+
preview
|
|
115
|
+
};
|
|
116
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { QueryTermsResult } from '@katecms/core';
|
|
2
|
+
/**
|
|
3
|
+
* Public dictionary-term query.
|
|
4
|
+
*
|
|
5
|
+
* Query:
|
|
6
|
+
* - `dictionary` (required) — comma-separated dictionary slugs
|
|
7
|
+
* - `perPage` (`-1` or omitted — all), `offset`
|
|
8
|
+
* - `includeIds`, `excludeIds`, `excludeTreeIds`
|
|
9
|
+
* - `parentId` (`0` = top-level), `childOf`, `childless`
|
|
10
|
+
* - `slug`, `title`, `search`
|
|
11
|
+
* - `hideEmpty` (default true), `hierarchical` (default true), `padCounts`
|
|
12
|
+
* - `fieldsQuery` — JSON object (`relation` + `queries`) against term `fields`.
|
|
13
|
+
* `REGEXP` and `NOT REGEXP` are rejected.
|
|
14
|
+
* - `orderBy`, `order`, `orderByField` — JSON `{ key, type? }` when `orderBy=field`
|
|
15
|
+
* - `return` — `all`, `ids`, `titles`, `count`, `idParent`, `idSlug`, `idTitle`
|
|
16
|
+
*
|
|
17
|
+
* `count` is the number of published entries in public collections.
|
|
18
|
+
*/
|
|
19
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<QueryTermsResult>>;
|
|
20
|
+
export default _default;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { defineEventHandler, getQuery } from "h3";
|
|
2
|
+
import {
|
|
3
|
+
isTermOrderBy,
|
|
4
|
+
isTermsReturn,
|
|
5
|
+
parseFieldsQuery,
|
|
6
|
+
queryTerms,
|
|
7
|
+
UNLIMITED_COLLECTION_PER_PAGE
|
|
8
|
+
} from "@katecms/core";
|
|
9
|
+
import { getDb } from "../../utils/db.js";
|
|
10
|
+
import { rejectPublicRegexp } from "../../utils/public-fields-query.js";
|
|
11
|
+
import { fail, getCollections, readPerPage } from "../../utils/collections.js";
|
|
12
|
+
import { getDictionaries } from "../../utils/dictionaries.js";
|
|
13
|
+
const CASTS = /* @__PURE__ */ new Set(["TEXT", "INTEGER", "NUMERIC", "DATETIME", "DATE", "TIME"]);
|
|
14
|
+
function firstQueryValue(value) {
|
|
15
|
+
return Array.isArray(value) ? value[0] : value;
|
|
16
|
+
}
|
|
17
|
+
function readStringList(value) {
|
|
18
|
+
const parts = Array.isArray(value) ? value : typeof value === "string" ? value.split(",") : [];
|
|
19
|
+
return [...new Set(parts.map((item) => String(item).trim()).filter(Boolean))];
|
|
20
|
+
}
|
|
21
|
+
function readIdList(value) {
|
|
22
|
+
const parts = Array.isArray(value) ? value : typeof value === "string" ? value.split(",") : value == null ? [] : [value];
|
|
23
|
+
const ids = [];
|
|
24
|
+
const seen = /* @__PURE__ */ new Set();
|
|
25
|
+
for (const part of parts) {
|
|
26
|
+
const n = Number(part);
|
|
27
|
+
if (!Number.isInteger(n) || n < 1 || seen.has(n)) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
seen.add(n);
|
|
31
|
+
ids.push(n);
|
|
32
|
+
}
|
|
33
|
+
return ids;
|
|
34
|
+
}
|
|
35
|
+
function hasQueryParam(query, key) {
|
|
36
|
+
return query[key] !== void 0;
|
|
37
|
+
}
|
|
38
|
+
function readBool(value, fallback) {
|
|
39
|
+
const raw = firstQueryValue(value);
|
|
40
|
+
if (raw == null || raw === "") {
|
|
41
|
+
return fallback;
|
|
42
|
+
}
|
|
43
|
+
if (typeof raw === "boolean") {
|
|
44
|
+
return raw;
|
|
45
|
+
}
|
|
46
|
+
const token = String(raw).trim().toLowerCase();
|
|
47
|
+
if (token === "1" || token === "true" || token === "yes") {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
if (token === "0" || token === "false" || token === "no") {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return fallback;
|
|
54
|
+
}
|
|
55
|
+
function readOffset(value) {
|
|
56
|
+
const raw = firstQueryValue(value);
|
|
57
|
+
if (raw == null || raw === "") {
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
const n = Number(raw);
|
|
61
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
62
|
+
fail(400, "Invalid offset.");
|
|
63
|
+
}
|
|
64
|
+
return n;
|
|
65
|
+
}
|
|
66
|
+
function readParentId(value) {
|
|
67
|
+
const raw = firstQueryValue(value);
|
|
68
|
+
if (raw == null || raw === "" || raw === "null" || raw === 0 || raw === "0") {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const n = Number(raw);
|
|
72
|
+
if (!Number.isInteger(n) || n < 1) {
|
|
73
|
+
fail(400, "Invalid parentId.");
|
|
74
|
+
}
|
|
75
|
+
return n;
|
|
76
|
+
}
|
|
77
|
+
function readChildOf(value) {
|
|
78
|
+
const raw = firstQueryValue(value);
|
|
79
|
+
if (raw == null || raw === "" || raw === 0 || raw === "0") {
|
|
80
|
+
return void 0;
|
|
81
|
+
}
|
|
82
|
+
const n = Number(raw);
|
|
83
|
+
if (!Number.isInteger(n) || n < 1) {
|
|
84
|
+
fail(400, "Invalid childOf.");
|
|
85
|
+
}
|
|
86
|
+
return n;
|
|
87
|
+
}
|
|
88
|
+
function readFieldsQuery(value) {
|
|
89
|
+
const raw = firstQueryValue(value);
|
|
90
|
+
if (raw == null || raw === "") {
|
|
91
|
+
return void 0;
|
|
92
|
+
}
|
|
93
|
+
let parsed = raw;
|
|
94
|
+
if (typeof raw === "string") {
|
|
95
|
+
try {
|
|
96
|
+
parsed = JSON.parse(raw);
|
|
97
|
+
} catch {
|
|
98
|
+
fail(400, "Invalid fieldsQuery.");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (typeof parsed !== "object" || parsed == null || Array.isArray(parsed)) {
|
|
102
|
+
fail(400, "Invalid fieldsQuery.");
|
|
103
|
+
}
|
|
104
|
+
return rejectPublicRegexp(parseFieldsQuery(parsed));
|
|
105
|
+
}
|
|
106
|
+
function readOrderByField(value) {
|
|
107
|
+
const raw = firstQueryValue(value);
|
|
108
|
+
if (raw == null || raw === "") {
|
|
109
|
+
return void 0;
|
|
110
|
+
}
|
|
111
|
+
let parsed = raw;
|
|
112
|
+
if (typeof raw === "string") {
|
|
113
|
+
try {
|
|
114
|
+
parsed = JSON.parse(raw);
|
|
115
|
+
} catch {
|
|
116
|
+
fail(400, "Invalid orderByField.");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
120
|
+
fail(400, "Invalid orderByField.");
|
|
121
|
+
}
|
|
122
|
+
const key = typeof parsed.key === "string" ? parsed.key.trim() : "";
|
|
123
|
+
if (!key) {
|
|
124
|
+
fail(400, "Invalid orderByField.");
|
|
125
|
+
}
|
|
126
|
+
const typeRaw = parsed.type;
|
|
127
|
+
const type = typeof typeRaw === "string" && CASTS.has(typeRaw.trim().toUpperCase()) ? typeRaw.trim().toUpperCase() : void 0;
|
|
128
|
+
return type ? { key, type } : { key };
|
|
129
|
+
}
|
|
130
|
+
function publicCollectionSlugs(all) {
|
|
131
|
+
return Object.keys(all).filter((slug) => all[slug]?.public !== false);
|
|
132
|
+
}
|
|
133
|
+
function resolveDictionaries(requested, all) {
|
|
134
|
+
const known = new Set(Object.keys(all));
|
|
135
|
+
return requested.filter((slug) => known.has(slug));
|
|
136
|
+
}
|
|
137
|
+
export default defineEventHandler(async (event) => {
|
|
138
|
+
const query = getQuery(event);
|
|
139
|
+
const requested = readStringList(query.dictionary);
|
|
140
|
+
if (requested.length === 0) {
|
|
141
|
+
fail(400, "Missing dictionary.");
|
|
142
|
+
}
|
|
143
|
+
const dictionaries = resolveDictionaries(requested, getDictionaries());
|
|
144
|
+
const orderByRaw = firstQueryValue(query.orderBy);
|
|
145
|
+
const orderByToken = typeof orderByRaw === "string" ? orderByRaw.trim() : "";
|
|
146
|
+
const orderBy = isTermOrderBy(orderByToken) ? orderByToken : void 0;
|
|
147
|
+
const orderRaw = firstQueryValue(query.order);
|
|
148
|
+
const orderToken = typeof orderRaw === "string" ? orderRaw.trim().toLowerCase() : "";
|
|
149
|
+
const order = orderToken === "asc" || orderToken === "desc" ? orderToken : void 0;
|
|
150
|
+
const returnRaw = firstQueryValue(query.return);
|
|
151
|
+
const returnToken = typeof returnRaw === "string" ? returnRaw.trim() : "";
|
|
152
|
+
const returnMode = isTermsReturn(returnToken) ? returnToken : void 0;
|
|
153
|
+
const filters = {
|
|
154
|
+
dictionaries,
|
|
155
|
+
perPage: readPerPage(query.perPage, UNLIMITED_COLLECTION_PER_PAGE),
|
|
156
|
+
offset: readOffset(query.offset),
|
|
157
|
+
hideEmpty: readBool(query.hideEmpty, true),
|
|
158
|
+
hierarchical: readBool(query.hierarchical, true),
|
|
159
|
+
padCounts: readBool(query.padCounts, false),
|
|
160
|
+
childless: readBool(query.childless, false),
|
|
161
|
+
countTypes: publicCollectionSlugs(getCollections()),
|
|
162
|
+
search: typeof firstQueryValue(query.search) === "string" ? String(firstQueryValue(query.search)) : void 0
|
|
163
|
+
};
|
|
164
|
+
if (orderBy) {
|
|
165
|
+
filters.orderBy = orderBy;
|
|
166
|
+
}
|
|
167
|
+
if (order) {
|
|
168
|
+
filters.order = order;
|
|
169
|
+
}
|
|
170
|
+
if (returnMode) {
|
|
171
|
+
filters.return = returnMode;
|
|
172
|
+
}
|
|
173
|
+
if (hasQueryParam(query, "includeIds")) {
|
|
174
|
+
filters.includeIds = readIdList(query.includeIds);
|
|
175
|
+
}
|
|
176
|
+
if (hasQueryParam(query, "excludeIds")) {
|
|
177
|
+
filters.excludeIds = readIdList(query.excludeIds);
|
|
178
|
+
}
|
|
179
|
+
if (hasQueryParam(query, "excludeTreeIds")) {
|
|
180
|
+
filters.excludeTreeIds = readIdList(query.excludeTreeIds);
|
|
181
|
+
}
|
|
182
|
+
if (hasQueryParam(query, "slug")) {
|
|
183
|
+
filters.slug = readStringList(query.slug);
|
|
184
|
+
}
|
|
185
|
+
if (hasQueryParam(query, "title")) {
|
|
186
|
+
filters.title = readStringList(query.title);
|
|
187
|
+
}
|
|
188
|
+
if (hasQueryParam(query, "parentId")) {
|
|
189
|
+
filters.parentId = readParentId(query.parentId);
|
|
190
|
+
}
|
|
191
|
+
if (hasQueryParam(query, "childOf")) {
|
|
192
|
+
filters.childOf = readChildOf(query.childOf);
|
|
193
|
+
}
|
|
194
|
+
if (hasQueryParam(query, "fieldsQuery")) {
|
|
195
|
+
filters.fieldsQuery = readFieldsQuery(query.fieldsQuery);
|
|
196
|
+
}
|
|
197
|
+
if (orderBy === "field") {
|
|
198
|
+
filters.orderByField = readOrderByField(query.orderByField);
|
|
199
|
+
}
|
|
200
|
+
return queryTerms(getDb(), filters);
|
|
201
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delete another user.
|
|
3
|
+
*
|
|
4
|
+
* Requires `users` delete. You cannot delete yourself. A site owner can be
|
|
5
|
+
* deleted only by an owner, and never when they are the last owner.
|
|
6
|
+
* Entries and uploads they authored stay; the author link is cleared.
|
|
7
|
+
*/
|
|
8
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
|
|
9
|
+
ok: true;
|
|
10
|
+
}>>;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { defineEventHandler, getRouterParam } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
import {
|
|
4
|
+
can,
|
|
5
|
+
deleteUser,
|
|
6
|
+
findUserById,
|
|
7
|
+
isOwner
|
|
8
|
+
} from "@katecms/core";
|
|
9
|
+
import { getDb } from "../../../utils/db.js";
|
|
10
|
+
import { requireUser } from "../../../utils/session.js";
|
|
11
|
+
import { fail } from "../../../utils/users.js";
|
|
12
|
+
export default defineEventHandler(async (event) => {
|
|
13
|
+
const actor = await requireUser(event);
|
|
14
|
+
const roles = useRuntimeConfig().katecms?.roles ?? {};
|
|
15
|
+
if (!can(actor, "users", "delete", { roles })) {
|
|
16
|
+
fail(403, "Insufficient permissions.");
|
|
17
|
+
}
|
|
18
|
+
const id = Number(getRouterParam(event, "id"));
|
|
19
|
+
if (!Number.isInteger(id) || id <= 0) {
|
|
20
|
+
fail(400, "Invalid user id.");
|
|
21
|
+
}
|
|
22
|
+
if (id === actor.id) {
|
|
23
|
+
fail(403, "You cannot delete your own account.");
|
|
24
|
+
}
|
|
25
|
+
const db = getDb();
|
|
26
|
+
const target = await findUserById(db, id);
|
|
27
|
+
if (!target) {
|
|
28
|
+
fail(404, "User not found.");
|
|
29
|
+
}
|
|
30
|
+
if (isOwner(target, roles) && !isOwner(actor, roles)) {
|
|
31
|
+
fail(403, "The site owner cannot be deleted.");
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const row = await deleteUser(db, id);
|
|
35
|
+
if (!row) {
|
|
36
|
+
fail(404, "User not found.");
|
|
37
|
+
}
|
|
38
|
+
return { ok: true };
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (error instanceof Error && error.message.includes("last owner")) {
|
|
41
|
+
fail(422, "Cannot remove the last owner.");
|
|
42
|
+
}
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AdminUser } from '../../../../utils/admin-users.js';
|
|
2
|
+
/**
|
|
3
|
+
* Update a user.
|
|
4
|
+
*
|
|
5
|
+
* Access rules:
|
|
6
|
+
* - editing your own account is always allowed (name / email / avatar);
|
|
7
|
+
* - changing your own password also requires `currentPassword`;
|
|
8
|
+
* - a manager may set another account's password without the old one;
|
|
9
|
+
* - editing someone else requires the `users` update permission;
|
|
10
|
+
* - `role` and `status` can only be changed by a manager editing *another*
|
|
11
|
+
* account (you can't change your own role/status, which prevents both
|
|
12
|
+
* self-lockout and privilege escalation);
|
|
13
|
+
* - the `owner` account can only be edited by the owner themselves, and the
|
|
14
|
+
* reserved `owner` role can never be assigned.
|
|
15
|
+
*/
|
|
16
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
|
|
17
|
+
user: AdminUser;
|
|
18
|
+
}>>;
|
|
19
|
+
export default _default;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { defineEventHandler, getRouterParam, readBody } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
import {
|
|
4
|
+
can,
|
|
5
|
+
findUserById,
|
|
6
|
+
hashPassword,
|
|
7
|
+
isOwner,
|
|
8
|
+
isUniqueConstraintError,
|
|
9
|
+
isValidRole,
|
|
10
|
+
OWNER_ROLE,
|
|
11
|
+
updateUser,
|
|
12
|
+
validateEmail,
|
|
13
|
+
validatePassword,
|
|
14
|
+
verifyPassword
|
|
15
|
+
} from "@katecms/core";
|
|
16
|
+
import { getDb } from "../../../utils/db.js";
|
|
17
|
+
import {
|
|
18
|
+
assertAuthAttemptAllowed,
|
|
19
|
+
recordAuthAttemptFailure,
|
|
20
|
+
recordAuthAttemptSuccess,
|
|
21
|
+
throwTooManyAttempts
|
|
22
|
+
} from "../../../utils/auth-rate-limit.js";
|
|
23
|
+
import { requireUser, setUserSession } from "../../../utils/session.js";
|
|
24
|
+
import {
|
|
25
|
+
fail,
|
|
26
|
+
readAvatar,
|
|
27
|
+
readName,
|
|
28
|
+
toAdminUser
|
|
29
|
+
} from "../../../utils/users.js";
|
|
30
|
+
const STATUSES = ["active", "banned"];
|
|
31
|
+
export default defineEventHandler(async (event) => {
|
|
32
|
+
const actor = await requireUser(event);
|
|
33
|
+
const roles = useRuntimeConfig().katecms?.roles ?? {};
|
|
34
|
+
const id = Number(getRouterParam(event, "id"));
|
|
35
|
+
if (!Number.isInteger(id) || id <= 0) {
|
|
36
|
+
fail(400, "Invalid user id.");
|
|
37
|
+
}
|
|
38
|
+
const isSelf = actor.id === id;
|
|
39
|
+
const canManage = can(actor, "users", "update", { roles });
|
|
40
|
+
if (!canManage && !isSelf) {
|
|
41
|
+
fail(403, "Insufficient permissions.");
|
|
42
|
+
}
|
|
43
|
+
const db = getDb();
|
|
44
|
+
const target = await findUserById(db, id);
|
|
45
|
+
if (!target) {
|
|
46
|
+
fail(404, "User not found.");
|
|
47
|
+
}
|
|
48
|
+
if (isOwner(target, roles) && !isSelf) {
|
|
49
|
+
fail(403, "The site owner cannot be changed.");
|
|
50
|
+
}
|
|
51
|
+
const body = await readBody(event);
|
|
52
|
+
const patch = {};
|
|
53
|
+
if (body?.email !== void 0) {
|
|
54
|
+
const email = typeof body.email === "string" ? body.email.trim() : "";
|
|
55
|
+
const emailCheck = validateEmail(email);
|
|
56
|
+
if (!emailCheck.ok) {
|
|
57
|
+
fail(422, emailCheck.error);
|
|
58
|
+
}
|
|
59
|
+
patch.email = email;
|
|
60
|
+
}
|
|
61
|
+
if (typeof body?.password === "string" && body.password.length > 0) {
|
|
62
|
+
const passwordCheck = validatePassword(body.password);
|
|
63
|
+
if (!passwordCheck.ok) {
|
|
64
|
+
fail(422, passwordCheck.error);
|
|
65
|
+
}
|
|
66
|
+
if (isSelf) {
|
|
67
|
+
const attemptKey = `password:${actor.id}`;
|
|
68
|
+
assertAuthAttemptAllowed(event, attemptKey);
|
|
69
|
+
const currentPassword = typeof body.currentPassword === "string" ? body.currentPassword : "";
|
|
70
|
+
const matches = currentPassword.length > 0 && await verifyPassword(currentPassword, target.password_hash);
|
|
71
|
+
if (!matches) {
|
|
72
|
+
const { retryAfterMs } = recordAuthAttemptFailure(attemptKey);
|
|
73
|
+
if (retryAfterMs > 0) {
|
|
74
|
+
throwTooManyAttempts(event, retryAfterMs);
|
|
75
|
+
}
|
|
76
|
+
fail(422, "Current password is incorrect.");
|
|
77
|
+
}
|
|
78
|
+
recordAuthAttemptSuccess(attemptKey);
|
|
79
|
+
}
|
|
80
|
+
patch.password_hash = await hashPassword(body.password);
|
|
81
|
+
}
|
|
82
|
+
if (body?.name !== void 0) {
|
|
83
|
+
patch.name = readName(body.name);
|
|
84
|
+
}
|
|
85
|
+
if (body?.avatar !== void 0) {
|
|
86
|
+
patch.avatar = readAvatar(body.avatar);
|
|
87
|
+
}
|
|
88
|
+
if (body?.role !== void 0) {
|
|
89
|
+
if (!canManage || isSelf) {
|
|
90
|
+
fail(403, "Cannot change this account role.");
|
|
91
|
+
}
|
|
92
|
+
const role = typeof body.role === "string" ? body.role : "";
|
|
93
|
+
if (role === OWNER_ROLE) {
|
|
94
|
+
fail(422, "The owner role cannot be assigned.");
|
|
95
|
+
}
|
|
96
|
+
if (!isValidRole(roles, role)) {
|
|
97
|
+
fail(422, "Unknown role.");
|
|
98
|
+
}
|
|
99
|
+
patch.role = role;
|
|
100
|
+
}
|
|
101
|
+
if (body?.status !== void 0) {
|
|
102
|
+
if (!canManage || isSelf) {
|
|
103
|
+
fail(403, "Cannot change this account status.");
|
|
104
|
+
}
|
|
105
|
+
const status = body.status;
|
|
106
|
+
if (!STATUSES.includes(status)) {
|
|
107
|
+
fail(422, "Invalid status.");
|
|
108
|
+
}
|
|
109
|
+
patch.status = status;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const row = await updateUser(db, id, patch);
|
|
113
|
+
if (!row) {
|
|
114
|
+
fail(404, "User not found.");
|
|
115
|
+
}
|
|
116
|
+
if (isSelf && patch.password_hash) {
|
|
117
|
+
await setUserSession(event, row.id, row.session_version);
|
|
118
|
+
}
|
|
119
|
+
return { user: toAdminUser(row) };
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (isUniqueConstraintError(error)) {
|
|
122
|
+
fail(409, "A user with this email already exists.");
|
|
123
|
+
}
|
|
124
|
+
if (error instanceof Error && error.message.includes("last owner")) {
|
|
125
|
+
fail(422, "Cannot remove the last owner.");
|
|
126
|
+
}
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { UsersResponse } from '../../../utils/admin-users.js';
|
|
2
|
+
/**
|
|
3
|
+
* Accounts for the admin users UI and the `user` field picker.
|
|
4
|
+
*
|
|
5
|
+
* Password hashes are never returned. Managers (read/create/update on `users`)
|
|
6
|
+
* see every account; others see only themselves. Extra capability flags power
|
|
7
|
+
* the admin list; the picker only reads `users`.
|
|
8
|
+
*/
|
|
9
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<UsersResponse>>;
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { defineEventHandler } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
import {
|
|
4
|
+
can,
|
|
5
|
+
findUserById,
|
|
6
|
+
listUsers
|
|
7
|
+
} from "@katecms/core";
|
|
8
|
+
import { getDb } from "../../utils/db.js";
|
|
9
|
+
import { requireUser } from "../../utils/session.js";
|
|
10
|
+
import { roleOptions, toAdminUser } from "../../utils/users.js";
|
|
11
|
+
export default defineEventHandler(async (event) => {
|
|
12
|
+
const actor = await requireUser(event);
|
|
13
|
+
const roles = useRuntimeConfig().katecms?.roles ?? {};
|
|
14
|
+
const db = getDb();
|
|
15
|
+
const canCreate = can(actor, "users", "create", { roles });
|
|
16
|
+
const canUpdate = can(actor, "users", "update", { roles });
|
|
17
|
+
const canDelete = can(actor, "users", "delete", { roles });
|
|
18
|
+
const isManager = can(actor, "users", "read", { roles }) || canCreate || canUpdate || canDelete;
|
|
19
|
+
let rows;
|
|
20
|
+
if (isManager) {
|
|
21
|
+
rows = await listUsers(db);
|
|
22
|
+
} else {
|
|
23
|
+
const row = await findUserById(db, actor.id);
|
|
24
|
+
rows = row ? [row] : [];
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
users: rows.map(toAdminUser),
|
|
28
|
+
roles: roleOptions(roles),
|
|
29
|
+
currentUserId: actor.id,
|
|
30
|
+
canCreate,
|
|
31
|
+
canUpdate,
|
|
32
|
+
canDelete
|
|
33
|
+
};
|
|
34
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AdminUser } from '../../../utils/admin-users.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create a user. Requires the `users` create permission (the `owner` superuser
|
|
4
|
+
* always passes). The reserved `owner` role can't be assigned — ownership is
|
|
5
|
+
* only ever granted to the first registered account.
|
|
6
|
+
*/
|
|
7
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
|
|
8
|
+
user: AdminUser;
|
|
9
|
+
}>>;
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { defineEventHandler, readBody } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
import {
|
|
4
|
+
createUser,
|
|
5
|
+
hashPassword,
|
|
6
|
+
isUniqueConstraintError,
|
|
7
|
+
isValidRole,
|
|
8
|
+
OWNER_ROLE,
|
|
9
|
+
validateEmail,
|
|
10
|
+
validatePassword
|
|
11
|
+
} from "@katecms/core";
|
|
12
|
+
import { getDb } from "../../utils/db.js";
|
|
13
|
+
import { requirePermission } from "../../utils/permissions.js";
|
|
14
|
+
import { requireUser } from "../../utils/session.js";
|
|
15
|
+
import {
|
|
16
|
+
defaultAssignableRole,
|
|
17
|
+
fail,
|
|
18
|
+
readAvatar,
|
|
19
|
+
readName,
|
|
20
|
+
toAdminUser
|
|
21
|
+
} from "../../utils/users.js";
|
|
22
|
+
export default defineEventHandler(async (event) => {
|
|
23
|
+
const actor = await requireUser(event);
|
|
24
|
+
const roles = useRuntimeConfig().katecms?.roles ?? {};
|
|
25
|
+
requirePermission(actor, "users", "create", roles);
|
|
26
|
+
const body = await readBody(event);
|
|
27
|
+
const email = typeof body?.email === "string" ? body.email.trim() : "";
|
|
28
|
+
const password = typeof body?.password === "string" ? body.password : "";
|
|
29
|
+
const name = readName(body?.name);
|
|
30
|
+
const avatar = readAvatar(body?.avatar);
|
|
31
|
+
const role = typeof body?.role === "string" && body.role.trim() ? body.role.trim() : defaultAssignableRole(roles);
|
|
32
|
+
const emailCheck = validateEmail(email);
|
|
33
|
+
if (!emailCheck.ok) {
|
|
34
|
+
fail(422, emailCheck.error);
|
|
35
|
+
}
|
|
36
|
+
const passwordCheck = validatePassword(password);
|
|
37
|
+
if (!passwordCheck.ok) {
|
|
38
|
+
fail(422, passwordCheck.error);
|
|
39
|
+
}
|
|
40
|
+
if (role === OWNER_ROLE) {
|
|
41
|
+
fail(422, "The owner role cannot be assigned.");
|
|
42
|
+
}
|
|
43
|
+
if (!isValidRole(roles, role)) {
|
|
44
|
+
fail(422, "Unknown role.");
|
|
45
|
+
}
|
|
46
|
+
const passwordHash = await hashPassword(password);
|
|
47
|
+
try {
|
|
48
|
+
const row = await createUser(getDb(), {
|
|
49
|
+
email,
|
|
50
|
+
password_hash: passwordHash,
|
|
51
|
+
name,
|
|
52
|
+
avatar,
|
|
53
|
+
role
|
|
54
|
+
});
|
|
55
|
+
return { user: toAdminUser(row) };
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (isUniqueConstraintError(error)) {
|
|
58
|
+
fail(409, "A user with this email already exists.");
|
|
59
|
+
}
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
});
|