create-snapify-app 0.0.0-stage → 1.1.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/LICENSE.md +24 -0
- package/README.md +55 -2
- package/bin/create-snapify-app.mjs +174 -0
- package/lib/args.mjs +59 -0
- package/lib/copy.mjs +44 -0
- package/lib/env.mjs +84 -0
- package/lib/prompt.mjs +63 -0
- package/package.json +35 -4
- package/template/.env.example +79 -0
- package/template/.github/workflows/ci.yml +23 -0
- package/template/.github/workflows/deploy.yml +26 -0
- package/template/.github/workflows/ping.yml +8 -0
- package/template/.github/workflows/release.yml +67 -0
- package/template/.snapify-install.json +5 -0
- package/template/CHANGELOG.md +28 -0
- package/template/LICENSE +14 -0
- package/template/README.md +287 -0
- package/template/administrator.html +23 -0
- package/template/apps/client/src/App.tsx +765 -0
- package/template/apps/client/src/auth.css +400 -0
- package/template/apps/client/src/lib/api.ts +22 -0
- package/template/apps/client/src/main.tsx +20 -0
- package/template/apps/community/src/App.tsx +592 -0
- package/template/apps/community/src/main.tsx +20 -0
- package/template/apps/community/src/styles.css +24 -0
- package/template/apps/developers/src/App.tsx +643 -0
- package/template/apps/developers/src/main.tsx +17 -0
- package/template/apps/developers/src/pages.tsx +1587 -0
- package/template/apps/developers/src/styles.css +98 -0
- package/template/apps/developers/src/ui.tsx +179 -0
- package/template/apps/landing/src/App.tsx +598 -0
- package/template/apps/landing/src/LegalPages.tsx +158 -0
- package/template/apps/landing/src/OrderPage.tsx +381 -0
- package/template/apps/landing/src/SeoPages.tsx +923 -0
- package/template/apps/landing/src/copy.ts +195 -0
- package/template/apps/landing/src/main.tsx +20 -0
- package/template/apps/landing/src/styles.css +803 -0
- package/template/apps/landing/src/types.ts +19 -0
- package/template/apps/marketplace/src/App.tsx +1229 -0
- package/template/apps/marketplace/src/developer/DeveloperApp.tsx +1266 -0
- package/template/apps/marketplace/src/main.tsx +20 -0
- package/template/apps/marketplace/src/styles.css +1001 -0
- package/template/apps/shared/AuthContext.tsx +65 -0
- package/template/apps/shared/Logo.tsx +33 -0
- package/template/apps/shared/api.ts +47 -0
- package/template/apps/shared/ui.tsx +128 -0
- package/template/apps/superadmin/src/App.tsx +1264 -0
- package/template/apps/superadmin/src/lib/api.ts +20 -0
- package/template/apps/superadmin/src/lib/hooks.ts +20 -0
- package/template/apps/superadmin/src/main.tsx +16 -0
- package/template/apps/superadmin/src/pages/ClientsPage.tsx +185 -0
- package/template/apps/superadmin/src/pages/InvoicesPage.tsx +157 -0
- package/template/apps/superadmin/src/pages/NewsletterPage.tsx +212 -0
- package/template/apps/superadmin/src/pages/OrdersPage.tsx +195 -0
- package/template/apps/superadmin/src/pages/PaymentsPage.tsx +150 -0
- package/template/apps/superadmin/src/pages/PayoutsPage.tsx +133 -0
- package/template/apps/superadmin/src/pages/PublishersPage.tsx +151 -0
- package/template/apps/superadmin/src/pages/SeoControlPage.tsx +692 -0
- package/template/apps/superadmin/src/pages/SettingsPage.tsx +199 -0
- package/template/apps/superadmin/src/pages/SystemPage.tsx +109 -0
- package/template/apps/superadmin/src/pages/TicketsPage.tsx +201 -0
- package/template/apps/superadmin/src/pages/UsersPage.tsx +167 -0
- package/template/client.html +21 -0
- package/template/community/hamdiayari/akhbar/README.md +23 -0
- package/template/community/hamdiayari/akhbar/screenshot.jpg +0 -0
- package/template/community/hamdiayari/akhbar/snapify.theme.json +76 -0
- package/template/community/hamdiayari/akhbar/src/Brand.tsx +26 -0
- package/template/community/hamdiayari/akhbar/src/Footer.tsx +182 -0
- package/template/community/hamdiayari/akhbar/src/Header.tsx +191 -0
- package/template/community/hamdiayari/akhbar/src/Layout.tsx +49 -0
- package/template/community/hamdiayari/akhbar/src/Social.tsx +33 -0
- package/template/community/hamdiayari/akhbar/src/Ticker.tsx +86 -0
- package/template/community/hamdiayari/akhbar/src/Views.tsx +285 -0
- package/template/community/hamdiayari/akhbar/src/blocks/CollectionBlocks.tsx +672 -0
- package/template/community/hamdiayari/akhbar/src/blocks/ContentBlocks.tsx +305 -0
- package/template/community/hamdiayari/akhbar/src/blocks/ConversionBlocks.tsx +569 -0
- package/template/community/hamdiayari/akhbar/src/blocks/HeaderBlocks.tsx +287 -0
- package/template/community/hamdiayari/akhbar/src/index.tsx +51 -0
- package/template/community/hamdiayari/akhbar/src/kit.tsx +357 -0
- package/template/community/hamdiayari/akhbar/src/site.ts +96 -0
- package/template/community/hamdiayari/akhbar/src/styles.css +566 -0
- package/template/community/hamdiayari/akhbar-actualites/README.md +28 -0
- package/template/community/hamdiayari/akhbar-actualites/screenshot.jpg +0 -0
- package/template/community/hamdiayari/akhbar-actualites/snapify.module.json +107 -0
- package/template/community/hamdiayari/akhbar-actualites/src/admin/AudiencePage.tsx +185 -0
- package/template/community/hamdiayari/akhbar-actualites/src/admin/index.tsx +11 -0
- package/template/community/hamdiayari/akhbar-actualites/src/public/Archive.tsx +142 -0
- package/template/community/hamdiayari/akhbar-actualites/src/public/cards.tsx +152 -0
- package/template/community/hamdiayari/akhbar-actualites/src/public/index.tsx +71 -0
- package/template/community/hamdiayari/akhbar-actualites/src/public/posts.ts +103 -0
- package/template/community/hamdiayari/akhbar-actualites/src/public/styles.css +568 -0
- package/template/community/hamdiayari/akhbar-actualites/src/public/widgets.tsx +226 -0
- package/template/community/hamdiayari/akhbar-actualites/src/server.ts +119 -0
- package/template/community/hamdiayari/akhbar-actualites/src/types.ts +25 -0
- package/template/community/hamdiayari/akhbar-urgent/README.md +36 -0
- package/template/community/hamdiayari/akhbar-urgent/screenshot.jpg +0 -0
- package/template/community/hamdiayari/akhbar-urgent/snapify.module.json +64 -0
- package/template/community/hamdiayari/akhbar-urgent/src/admin/FlashesPage.tsx +229 -0
- package/template/community/hamdiayari/akhbar-urgent/src/admin/index.tsx +11 -0
- package/template/community/hamdiayari/akhbar-urgent/src/public/Ticker.tsx +81 -0
- package/template/community/hamdiayari/akhbar-urgent/src/public/index.tsx +63 -0
- package/template/community/hamdiayari/akhbar-urgent/src/public/styles.css +142 -0
- package/template/community/hamdiayari/akhbar-urgent/src/server.ts +101 -0
- package/template/community/hamdiayari/akhbar-urgent/src/types.ts +35 -0
- package/template/community.html +21 -0
- package/template/developers.html +24 -0
- package/template/docker-compose.db.yml +24 -0
- package/template/docs/BACKOFFICE_SNAPIFY.md +130 -0
- package/template/docs/CI_CD.md +66 -0
- package/template/docs/MODULES.md +346 -0
- package/template/docs/PLATFORM_DEPLOY.md +54 -0
- package/template/docs/logo.svg +10 -0
- package/template/drizzle/0000_init.sql +147 -0
- package/template/drizzle/0001_page_project.sql +5 -0
- package/template/drizzle/0002_modules.sql +23 -0
- package/template/drizzle/0003_themes.sql +4 -0
- package/template/drizzle/0004_security.sql +82 -0
- package/template/drizzle/0005_module_records.sql +16 -0
- package/template/drizzle/0006_avatars.sql +4 -0
- package/template/drizzle/0007_platform.sql +264 -0
- package/template/drizzle/0008_mp_validation.sql +3 -0
- package/template/drizzle/0009_saas_ops.sql +77 -0
- package/template/drizzle/0010_cms_chrome.sql +13 -0
- package/template/drizzle/0011_client_portal.sql +26 -0
- package/template/drizzle/meta/0000_snapshot.json +998 -0
- package/template/drizzle/meta/0001_snapshot.json +1004 -0
- package/template/drizzle/meta/_journal.json +90 -0
- package/template/drizzle.config.ts +16 -0
- package/template/ecosystem.snapify.cjs +24 -0
- package/template/for.html +1 -0
- package/template/index.html +29 -0
- package/template/landing.html +37 -0
- package/template/marketplace/catalog.json +373 -0
- package/template/marketplace/gallery/hamdiayari.preveris/01-home.jpg +0 -0
- package/template/marketplace/gallery/hamdiayari.recaptcha/01-reglages.jpg +0 -0
- package/template/marketplace/gallery/hamdiayari.recaptcha/02-logo.jpg +0 -0
- package/template/marketplace/gallery/novalabs.ai-articles/01-generer.jpg +0 -0
- package/template/marketplace/gallery/novalabs.ai-articles/02-fournisseur-ia.jpg +0 -0
- package/template/marketplace/gallery/novalabs.calendar/01-agenda-site.jpg +0 -0
- package/template/marketplace/gallery/novalabs.calendar/02-evenements-admin.jpg +0 -0
- package/template/marketplace/gallery/novalabs.calendar/03-reglages.jpg +0 -0
- package/template/marketplace/screenshots/hamdiayari.preveris-1.0.6.jpg +0 -0
- package/template/marketplace/screenshots/hamdiayari.recaptcha-1.0.0.jpg +0 -0
- package/template/marketplace/screenshots/hamdiayari.wp-seo-migrator-1.1.1.jpg +0 -0
- package/template/marketplace/screenshots/novalabs.ai-articles-1.0.1.jpg +0 -0
- package/template/marketplace/screenshots/novalabs.ai-chat-1.0.1.jpg +0 -0
- package/template/marketplace/screenshots/novalabs.calendar-1.0.1.jpg +0 -0
- package/template/marketplace/screenshots/novalabs.cart-1.0.0.jpg +0 -0
- package/template/marketplace/screenshots/novalabs.checkout-1.0.0.jpg +0 -0
- package/template/marketplace/screenshots/novalabs.customers-1.1.0.jpg +0 -0
- package/template/marketplace/screenshots/novalabs.dogga-1.0.0.jpg +0 -0
- package/template/marketplace/screenshots/novalabs.mahdia-1.0.0.jpg +0 -0
- package/template/marketplace/screenshots/novalabs.shop-1.0.0.jpg +0 -0
- package/template/marketplace/screenshots/novalabs.sidibou-1.0.0.jpg +0 -0
- package/template/marketplace/screenshots/novalabs.whatsapp-1.0.1.jpg +0 -0
- package/template/marketplace.html +21 -0
- package/template/metadata.json +7 -0
- package/template/modules/ai-articles/screenshot.jpg +0 -0
- package/template/modules/ai-articles/snapify.module.json +74 -0
- package/template/modules/ai-articles/src/admin/ArticlesPage.tsx +162 -0
- package/template/modules/ai-articles/src/admin/GeneratePage.tsx +118 -0
- package/template/modules/ai-articles/src/admin/index.tsx +12 -0
- package/template/modules/ai-articles/src/public/index.tsx +119 -0
- package/template/modules/ai-articles/src/server.ts +287 -0
- package/template/modules/ai-articles/src/types.ts +30 -0
- package/template/modules/ai-chat/screenshot.jpg +0 -0
- package/template/modules/ai-chat/snapify.module.json +217 -0
- package/template/modules/ai-chat/src/public.tsx +198 -0
- package/template/modules/ai-chat/src/server.ts +142 -0
- package/template/modules/ai-theme-studio/README.md +15 -0
- package/template/modules/ai-theme-studio/screenshot.jpg +0 -0
- package/template/modules/ai-theme-studio/snapify.module.json +175 -0
- package/template/modules/ai-theme-studio/src/admin/HistoryPage.tsx +91 -0
- package/template/modules/ai-theme-studio/src/admin/StudioPage.tsx +414 -0
- package/template/modules/ai-theme-studio/src/admin/index.tsx +11 -0
- package/template/modules/ai-theme-studio/src/lib/images.ts +240 -0
- package/template/modules/ai-theme-studio/src/lib/llm.ts +123 -0
- package/template/modules/ai-theme-studio/src/lib/normalize.ts +714 -0
- package/template/modules/ai-theme-studio/src/lib/prompts.ts +198 -0
- package/template/modules/ai-theme-studio/src/server.ts +137 -0
- package/template/modules/ai-theme-studio/src/types.ts +112 -0
- package/template/modules/calendar/screenshot.jpg +0 -0
- package/template/modules/calendar/snapify.module.json +45 -0
- package/template/modules/calendar/src/admin/EventsPage.tsx +217 -0
- package/template/modules/calendar/src/admin/index.tsx +11 -0
- package/template/modules/calendar/src/public/index.tsx +231 -0
- package/template/modules/calendar/src/server.ts +143 -0
- package/template/modules/calendar/src/types.ts +25 -0
- package/template/modules/cart/screenshot.jpg +0 -0
- package/template/modules/cart/snapify.module.json +90 -0
- package/template/modules/cart/src/admin/index.tsx +265 -0
- package/template/modules/cart/src/public/CartPage.tsx +198 -0
- package/template/modules/cart/src/public/index.tsx +261 -0
- package/template/modules/cart/src/public/useQuote.ts +67 -0
- package/template/modules/cart/src/server.ts +148 -0
- package/template/modules/cart/src/types.ts +31 -0
- package/template/modules/checkout/screenshot.jpg +0 -0
- package/template/modules/checkout/snapify.module.json +264 -0
- package/template/modules/checkout/src/admin/OrderDetailPage.tsx +304 -0
- package/template/modules/checkout/src/admin/badges.tsx +28 -0
- package/template/modules/checkout/src/admin/index.tsx +236 -0
- package/template/modules/checkout/src/public/CheckoutPage.tsx +461 -0
- package/template/modules/checkout/src/public/OrderPages.tsx +153 -0
- package/template/modules/checkout/src/public/index.tsx +23 -0
- package/template/modules/checkout/src/server.ts +383 -0
- package/template/modules/checkout/src/types.ts +70 -0
- package/template/modules/customers/screenshot.jpg +0 -0
- package/template/modules/customers/snapify.module.json +115 -0
- package/template/modules/customers/src/admin/CustomerDetailPage.tsx +274 -0
- package/template/modules/customers/src/admin/index.tsx +194 -0
- package/template/modules/customers/src/public/AccountPages.tsx +470 -0
- package/template/modules/customers/src/public/AddressForm.tsx +115 -0
- package/template/modules/customers/src/public/AuthPages.tsx +349 -0
- package/template/modules/customers/src/public/Avatar.tsx +29 -0
- package/template/modules/customers/src/public/ProfileSection.tsx +291 -0
- package/template/modules/customers/src/public/index.tsx +137 -0
- package/template/modules/customers/src/public/session.ts +51 -0
- package/template/modules/customers/src/server.ts +421 -0
- package/template/modules/customers/src/types.ts +53 -0
- package/template/modules/recaptcha/logo.jpg +0 -0
- package/template/modules/recaptcha/screenshot.jpg +0 -0
- package/template/modules/recaptcha/snapify.module.json +99 -0
- package/template/modules/recaptcha/src/public/index.tsx +94 -0
- package/template/modules/recaptcha/src/server.ts +65 -0
- package/template/modules/recaptcha/src/types.ts +18 -0
- package/template/modules/shop/screenshot.jpg +0 -0
- package/template/modules/shop/snapify.module.json +340 -0
- package/template/modules/shop/src/admin/CategoriesPage.tsx +224 -0
- package/template/modules/shop/src/admin/ProductEditor.tsx +313 -0
- package/template/modules/shop/src/admin/ProductsPage.tsx +307 -0
- package/template/modules/shop/src/admin/index.tsx +14 -0
- package/template/modules/shop/src/public/Catalog.tsx +244 -0
- package/template/modules/shop/src/public/NotFound.tsx +22 -0
- package/template/modules/shop/src/public/ProductPage.tsx +195 -0
- package/template/modules/shop/src/public/index.tsx +134 -0
- package/template/modules/shop/src/public/useFetch.ts +26 -0
- package/template/modules/shop/src/server.ts +493 -0
- package/template/modules/shop/src/shared.ts +41 -0
- package/template/modules/shop/src/types.ts +60 -0
- package/template/modules/whatsapp/screenshot.jpg +0 -0
- package/template/modules/whatsapp/snapify.module.json +121 -0
- package/template/modules/whatsapp/src/public.tsx +119 -0
- package/template/modules/wp-seo-migrator/ARCHITECTURE.md +113 -0
- package/template/modules/wp-seo-migrator/README.md +21 -0
- package/template/modules/wp-seo-migrator/fixtures/aioseo-sample.csv +3 -0
- package/template/modules/wp-seo-migrator/fixtures/sample-exporter.json +39 -0
- package/template/modules/wp-seo-migrator/fixtures/sample-page.html +12 -0
- package/template/modules/wp-seo-migrator/fixtures/sample.htaccess +3 -0
- package/template/modules/wp-seo-migrator/screenshot.jpg +0 -0
- package/template/modules/wp-seo-migrator/snapify.module.json +87 -0
- package/template/modules/wp-seo-migrator/src/admin/HistoryPage.tsx +64 -0
- package/template/modules/wp-seo-migrator/src/admin/WizardPage.tsx +788 -0
- package/template/modules/wp-seo-migrator/src/admin/i18n.ts +156 -0
- package/template/modules/wp-seo-migrator/src/admin/index.tsx +11 -0
- package/template/modules/wp-seo-migrator/src/connectors/CUSTOM_CONNECTOR.md +31 -0
- package/template/modules/wp-seo-migrator/src/connectors/csvSeoFactory.ts +106 -0
- package/template/modules/wp-seo-migrator/src/connectors/exporter.ts +96 -0
- package/template/modules/wp-seo-migrator/src/connectors/gscCsv.ts +53 -0
- package/template/modules/wp-seo-migrator/src/connectors/htaccess.ts +65 -0
- package/template/modules/wp-seo-migrator/src/connectors/htmlCrawler.ts +90 -0
- package/template/modules/wp-seo-migrator/src/connectors/index.ts +113 -0
- package/template/modules/wp-seo-migrator/src/connectors/pluginCsv.ts +77 -0
- package/template/modules/wp-seo-migrator/src/connectors/rankMathCsv.ts +77 -0
- package/template/modules/wp-seo-migrator/src/connectors/redirection.ts +62 -0
- package/template/modules/wp-seo-migrator/src/connectors/sitemap.ts +44 -0
- package/template/modules/wp-seo-migrator/src/connectors/utils.ts +111 -0
- package/template/modules/wp-seo-migrator/src/connectors/wxr.ts +103 -0
- package/template/modules/wp-seo-migrator/src/connectors/yoastCsv.ts +56 -0
- package/template/modules/wp-seo-migrator/src/pipeline/analyze.ts +158 -0
- package/template/modules/wp-seo-migrator/src/pipeline/htmlParse.ts +58 -0
- package/template/modules/wp-seo-migrator/src/pipeline/remoteAuto.ts +328 -0
- package/template/modules/wp-seo-migrator/src/server.ts +492 -0
- package/template/modules/wp-seo-migrator/src/types.ts +151 -0
- package/template/modules/wp-seo-migrator/tests/connectors-extra.test.ts +39 -0
- package/template/modules/wp-seo-migrator/tests/merge.test.ts +25 -0
- package/template/package-lock.json +6016 -0
- package/template/package.json +74 -0
- package/template/public/images/photos/caravane-chameaux-desert.webp +0 -0
- package/template/public/images/photos/hammamet-medina-plage.jpg +0 -0
- package/template/public/images/photos/maison-campagne-collines.webp +0 -0
- package/template/public/images/photos/maisons-troglodytes-desert.jpg +0 -0
- package/template/public/images/photos/panorama-ville.jpg +0 -0
- package/template/public/images/photos/preveris-accessibilite-erp.jpg +0 -0
- package/template/public/images/photos/preveris-collectivites.jpg +0 -0
- package/template/public/images/photos/preveris-etudes-plans.jpg +0 -0
- package/template/public/images/photos/preveris-hero-erp.jpg +0 -0
- package/template/public/images/photos/preveris-ssi-incendie.jpg +0 -0
- package/template/public/images/photos/preveris-suivi-hotel.jpg +0 -0
- package/template/public/images/photos/ruelle-bleue-medina.jpg +0 -0
- package/template/public/images/photos/sidi-bou-said-port.webp +0 -0
- package/template/public/images/photos/terrasse-blanche-mer-voilier.jpg +0 -0
- package/template/public/landing/hero-ai-cms.jpg +0 -0
- package/template/public/landing/shot-dogga.jpg +0 -0
- package/template/public/landing/shot-mahdia.jpg +0 -0
- package/template/public/landing/shot-sidibou.jpg +0 -0
- package/template/public/llms.txt +35 -0
- package/template/public/logo.svg +10 -0
- package/template/scripts/app-pack.ts +155 -0
- package/template/scripts/app-publish.ts +123 -0
- package/template/scripts/apply-ecommerce-home.ts +196 -0
- package/template/scripts/auto-deploy-poll.sh +13 -0
- package/template/scripts/db-backup.sh +16 -0
- package/template/scripts/db-restore.sh +11 -0
- package/template/scripts/deploy.sh +34 -0
- package/template/scripts/github-webhook-deploy.sh +7 -0
- package/template/scripts/install-new-modules.ts +96 -0
- package/template/scripts/refresh-demo-baseline.ts +9 -0
- package/template/scripts/reinstall-marketplace-packs.ts +51 -0
- package/template/scripts/restore-classic-home.ts +13 -0
- package/template/scripts/sdk-pack.ts +289 -0
- package/template/scripts/sdk-publish.ts +75 -0
- package/template/scripts/seed-demo-products.ts +120 -0
- package/template/scripts/seed-theme-content-packs.ts +42 -0
- package/template/scripts/snapify-module.ts +207 -0
- package/template/scripts/test-theme-switch.ts +24 -0
- package/template/sdk/admin.css +18 -0
- package/template/sdk/admin.ts +95 -0
- package/template/sdk/build.ts +249 -0
- package/template/sdk/commerce.ts +512 -0
- package/template/sdk/content.ts +76 -0
- package/template/sdk/icons.ts +101 -0
- package/template/sdk/image.ts +60 -0
- package/template/sdk/index.ts +500 -0
- package/template/sdk/package.ts +298 -0
- package/template/sdk/recaptcha.tsx +122 -0
- package/template/sdk/settings.ts +84 -0
- package/template/sdk/theme.css +29 -0
- package/template/sdk/theme.ts +100 -0
- package/template/sdk/ui/commerce.tsx +385 -0
- package/template/sdk/ui/orders.tsx +136 -0
- package/template/sdk-kit/CHANGELOG.md +17 -0
- package/template/sdk-kit/LICENSE.md +47 -0
- package/template/sdk-kit/README.md +81 -0
- package/template/sdk-kit/cli.ts +339 -0
- package/template/sdk-kit/create-snapify/README.md +28 -0
- package/template/sdk-kit/create-snapify/create-snapify.mjs +11 -0
- package/template/sdk-kit/create-snapify/package.template.json +16 -0
- package/template/sdk-kit/package.template.json +95 -0
- package/template/sdk-kit/templates/common/README.md.tpl +27 -0
- package/template/sdk-kit/templates/common/_gitignore +3 -0
- package/template/sdk-kit/templates/common/package.json.tpl +19 -0
- package/template/sdk-kit/templates/common/src/snapify-env.d.ts +2 -0
- package/template/sdk-kit/templates/common/tsconfig.json +15 -0
- package/template/sdk-kit/templates/module/snapify.module.json.tpl +33 -0
- package/template/sdk-kit/templates/module/src/admin.tsx +53 -0
- package/template/sdk-kit/templates/module/src/public.tsx +49 -0
- package/template/sdk-kit/templates/module/src/server.ts +30 -0
- package/template/sdk-kit/templates/module/src/types.ts +19 -0
- package/template/sdk-kit/templates/theme/snapify.theme.json.tpl +22 -0
- package/template/sdk-kit/templates/theme/src/Footer.tsx +40 -0
- package/template/sdk-kit/templates/theme/src/Header.tsx +47 -0
- package/template/sdk-kit/templates/theme/src/Views.tsx +36 -0
- package/template/sdk-kit/templates/theme/src/blocks.tsx +93 -0
- package/template/sdk-kit/templates/theme/src/index.tsx +30 -0
- package/template/sdk-kit/templates/theme/src/site.tsx +59 -0
- package/template/sdk-kit/templates/theme/src/styles.css +71 -0
- package/template/server/client/routes.ts +252 -0
- package/template/server/cms/analyticsStore.ts +180 -0
- package/template/server/cms/auth.ts +155 -0
- package/template/server/cms/blockCatalog.ts +342 -0
- package/template/server/cms/blocks.ts +521 -0
- package/template/server/cms/contentMigration.ts +1119 -0
- package/template/server/cms/defaults.ts +303 -0
- package/template/server/cms/permissions.ts +154 -0
- package/template/server/cms/restoreClassicHome.ts +183 -0
- package/template/server/cms/revisions.ts +99 -0
- package/template/server/cms/scheduler.ts +78 -0
- package/template/server/cms/seed.ts +72 -0
- package/template/server/cms/seoAnalyzer.ts +213 -0
- package/template/server/cms/store.ts +122 -0
- package/template/server/cms/themeContent.ts +1386 -0
- package/template/server/cms/themePacks/sidibou-branding.json +1 -0
- package/template/server/cms/themePacks/sidibou-home.json +1 -0
- package/template/server/cms/themePacks/sidibou-menus.json +1 -0
- package/template/server/cms/types.ts +432 -0
- package/template/server/community/routes.ts +410 -0
- package/template/server/db/client.ts +43 -0
- package/template/server/db/repository.ts +389 -0
- package/template/server/db/schema.ts +726 -0
- package/template/server/demo/cmsReset.ts +196 -0
- package/template/server/developers/sdk.ts +85 -0
- package/template/server/geoip.ts +15 -0
- package/template/server/http.ts +53 -0
- package/template/server/mail.ts +216 -0
- package/template/server/marketplace/catalog.ts +74 -0
- package/template/server/marketplace/packageValidate.ts +475 -0
- package/template/server/marketplace/payments.ts +193 -0
- package/template/server/marketplace/routes.ts +850 -0
- package/template/server/marketplace/signing.ts +116 -0
- package/template/server/marketplace/syncOfficial.ts +282 -0
- package/template/server/media/images.ts +63 -0
- package/template/server/middleware/adminAuth.ts +134 -0
- package/template/server/modules/legacy.ts +44 -0
- package/template/server/modules/manager.ts +1122 -0
- package/template/server/modules/marketplace.ts +178 -0
- package/template/server/modules/outbound.ts +178 -0
- package/template/server/modules/purchases.ts +149 -0
- package/template/server/modules/records.ts +168 -0
- package/template/server/modules/themeHtml.ts +32 -0
- package/template/server/modules/trust.ts +16 -0
- package/template/server/modules/types.ts +147 -0
- package/template/server/platform/auth.ts +223 -0
- package/template/server/platform/clientWelcome.ts +168 -0
- package/template/server/platform/clients.ts +139 -0
- package/template/server/platform/dailyImprove.ts +356 -0
- package/template/server/platform/flouci.ts +126 -0
- package/template/server/platform/host.ts +69 -0
- package/template/server/platform/hostingProviders.ts +143 -0
- package/template/server/platform/licenseOrders.ts +291 -0
- package/template/server/platform/money.ts +42 -0
- package/template/server/platform/passwords.ts +41 -0
- package/template/server/platform/region.ts +86 -0
- package/template/server/platform/routes.ts +225 -0
- package/template/server/platform/seed.ts +82 -0
- package/template/server/platform/settings.ts +72 -0
- package/template/server/routes/adminAccount.ts +403 -0
- package/template/server/routes/adminCms.ts +808 -0
- package/template/server/routes/adminSystem.ts +243 -0
- package/template/server/routes/adminUsers.ts +449 -0
- package/template/server/routes/googleOAuth.ts +327 -0
- package/template/server/routes/modules.ts +323 -0
- package/template/server/routes/publicCms.ts +313 -0
- package/template/server/routes/seoPublic.ts +158 -0
- package/template/server/security/accounts.ts +121 -0
- package/template/server/security/audit.ts +143 -0
- package/template/server/security/authTokens.ts +74 -0
- package/template/server/security/ip.ts +68 -0
- package/template/server/security/rateLimit.ts +85 -0
- package/template/server/security/retention.ts +46 -0
- package/template/server/security/secrets.ts +44 -0
- package/template/server/security/sessions.ts +140 -0
- package/template/server/security/totp.ts +101 -0
- package/template/server/superadmin/analytics.ts +109 -0
- package/template/server/superadmin/auth.ts +92 -0
- package/template/server/superadmin/backlinksCatalog.ts +210 -0
- package/template/server/superadmin/frSeoContent.ts +165 -0
- package/template/server/superadmin/landingSeo.ts +675 -0
- package/template/server/superadmin/ops.ts +238 -0
- package/template/server/superadmin/routes.ts +1095 -0
- package/template/server/superadmin/tnSeoContent.ts +130 -0
- package/template/server.ts +522 -0
- package/template/src/App.tsx +263 -0
- package/template/src/admin/AdminApp.tsx +162 -0
- package/template/src/admin/account/AuthLayout.tsx +57 -0
- package/template/src/admin/account/SecurityForms.tsx +276 -0
- package/template/src/admin/admin.css +127 -0
- package/template/src/admin/context/AuthContext.tsx +147 -0
- package/template/src/admin/context/SiteContext.tsx +50 -0
- package/template/src/admin/editor/BlockLibrary.tsx +173 -0
- package/template/src/admin/editor/BlocksPanel.tsx +396 -0
- package/template/src/admin/editor/EditorBits.tsx +106 -0
- package/template/src/admin/editor/PreviewFrame.tsx +145 -0
- package/template/src/admin/editor/RichTextEditor.tsx +276 -0
- package/template/src/admin/editor/SeoPanel.tsx +349 -0
- package/template/src/admin/editor/StyleEditor.tsx +114 -0
- package/template/src/admin/editor/blockSchemas.ts +699 -0
- package/template/src/admin/editor/fields.tsx +486 -0
- package/template/src/admin/layout/AdminShell.tsx +418 -0
- package/template/src/admin/layout/nav.ts +95 -0
- package/template/src/admin/lib/api.ts +408 -0
- package/template/src/admin/lib/audit.ts +141 -0
- package/template/src/admin/lib/format.ts +84 -0
- package/template/src/admin/lib/hooks.ts +125 -0
- package/template/src/admin/main.tsx +16 -0
- package/template/src/admin/modules/InstallDialog.tsx +160 -0
- package/template/src/admin/modules/SettingsForm.tsx +145 -0
- package/template/src/admin/modules/kit.tsx +127 -0
- package/template/src/admin/modules/labels.tsx +226 -0
- package/template/src/admin/pages/AccountSetupPage.tsx +62 -0
- package/template/src/admin/pages/AnalyticsPage.tsx +206 -0
- package/template/src/admin/pages/BrandingPage.tsx +154 -0
- package/template/src/admin/pages/DashboardPage.tsx +239 -0
- package/template/src/admin/pages/EngagementPage.tsx +168 -0
- package/template/src/admin/pages/FormsPage.tsx +435 -0
- package/template/src/admin/pages/GeneralPage.tsx +120 -0
- package/template/src/admin/pages/LoginPage.tsx +249 -0
- package/template/src/admin/pages/MaintenancePage.tsx +125 -0
- package/template/src/admin/pages/MarketplacePage.tsx +426 -0
- package/template/src/admin/pages/MediaPage.tsx +251 -0
- package/template/src/admin/pages/MenusPage.tsx +446 -0
- package/template/src/admin/pages/ModuleAdminPage.tsx +113 -0
- package/template/src/admin/pages/ModuleDetailPage.tsx +293 -0
- package/template/src/admin/pages/ModulesPage.tsx +135 -0
- package/template/src/admin/pages/NewsletterPage.tsx +193 -0
- package/template/src/admin/pages/PageEditorPage.tsx +322 -0
- package/template/src/admin/pages/PagesListPage.tsx +277 -0
- package/template/src/admin/pages/PostEditorPage.tsx +292 -0
- package/template/src/admin/pages/PostsListPage.tsx +187 -0
- package/template/src/admin/pages/ProfilePage.tsx +489 -0
- package/template/src/admin/pages/ResetPasswordPage.tsx +110 -0
- package/template/src/admin/pages/SeoPage.tsx +670 -0
- package/template/src/admin/pages/SettingsPage.tsx +189 -0
- package/template/src/admin/pages/ThemeCustomizePage.tsx +170 -0
- package/template/src/admin/pages/ThemesPage.tsx +292 -0
- package/template/src/admin/pages/UsersPage.tsx +57 -0
- package/template/src/admin/pages/WidgetsPage.tsx +200 -0
- package/template/src/admin/seo/GoogleSetup.tsx +529 -0
- package/template/src/admin/settings/EmailTab.tsx +293 -0
- package/template/src/admin/settings/OtherTabs.tsx +270 -0
- package/template/src/admin/settings/SecurityTab.tsx +172 -0
- package/template/src/admin/settings/controls.tsx +133 -0
- package/template/src/admin/ui/Pagination.tsx +170 -0
- package/template/src/admin/ui/SaveBar.tsx +77 -0
- package/template/src/admin/ui/TagInput.tsx +54 -0
- package/template/src/admin/ui/charts.tsx +108 -0
- package/template/src/admin/ui/media.tsx +265 -0
- package/template/src/admin/ui/overlays.tsx +239 -0
- package/template/src/admin/ui/primitives.tsx +544 -0
- package/template/src/admin/users/AuditTab.tsx +104 -0
- package/template/src/admin/users/RolesTab.tsx +368 -0
- package/template/src/admin/users/UsersTab.tsx +723 -0
- package/template/src/admin/users/shared.tsx +278 -0
- package/template/src/cms/icons.ts +7 -0
- package/template/src/components/CookieBanner.tsx +166 -0
- package/template/src/components/MaintenanceGate.tsx +66 -0
- package/template/src/components/SiteAnalytics.tsx +64 -0
- package/template/src/components/SnapifyLogo.tsx +44 -0
- package/template/src/components/cms/BlockRenderer.tsx +154 -0
- package/template/src/components/cms/WidgetArea.tsx +193 -0
- package/template/src/context/SiteConfigContext.tsx +130 -0
- package/template/src/demoBase.ts +23 -0
- package/template/src/index.css +90 -0
- package/template/src/main.tsx +16 -0
- package/template/src/modules/ModuleHost.tsx +197 -0
- package/template/src/preview.ts +63 -0
- package/template/src/runtime.ts +38 -0
- package/template/src/themes/ThemeHost.tsx +168 -0
- package/template/src/themes/fallback.tsx +71 -0
- package/template/src/types.ts +94 -0
- package/template/src/views/BlogPostView.tsx +68 -0
- package/template/src/views/CmsPageView.tsx +34 -0
- package/template/start-pm2.sh +3 -0
- package/template/superadmin.html +20 -0
- package/template/themes/ai-canvas/screenshot.jpg +0 -0
- package/template/themes/ai-canvas/snapify.theme.json +96 -0
- package/template/themes/ai-canvas/src/CeeSimulator.tsx +247 -0
- package/template/themes/ai-canvas/src/Footer.tsx +190 -0
- package/template/themes/ai-canvas/src/Header.tsx +324 -0
- package/template/themes/ai-canvas/src/Layout.tsx +56 -0
- package/template/themes/ai-canvas/src/NotFound.tsx +58 -0
- package/template/themes/ai-canvas/src/Post.tsx +26 -0
- package/template/themes/ai-canvas/src/SnapifyLogo.tsx +44 -0
- package/template/themes/ai-canvas/src/blocks/CollectionBlocks.tsx +711 -0
- package/template/themes/ai-canvas/src/blocks/ContentBlocks.tsx +318 -0
- package/template/themes/ai-canvas/src/blocks/ConversionBlocks.tsx +559 -0
- package/template/themes/ai-canvas/src/blocks/HeaderBlocks.tsx +341 -0
- package/template/themes/ai-canvas/src/index.tsx +54 -0
- package/template/themes/ai-canvas/src/kit.tsx +398 -0
- package/template/themes/ai-canvas/src/site.ts +29 -0
- package/template/themes/ai-canvas/src/styles.css +317 -0
- package/template/themes/dogga/screenshot.jpg +0 -0
- package/template/themes/dogga/snapify.theme.json +55 -0
- package/template/themes/dogga/src/Brand.tsx +41 -0
- package/template/themes/dogga/src/Footer.tsx +202 -0
- package/template/themes/dogga/src/Header.tsx +239 -0
- package/template/themes/dogga/src/Layout.tsx +43 -0
- package/template/themes/dogga/src/Views.tsx +71 -0
- package/template/themes/dogga/src/blocks/CollectionBlocks.tsx +674 -0
- package/template/themes/dogga/src/blocks/ContentBlocks.tsx +307 -0
- package/template/themes/dogga/src/blocks/ConversionBlocks.tsx +571 -0
- package/template/themes/dogga/src/blocks/HeaderBlocks.tsx +289 -0
- package/template/themes/dogga/src/index.tsx +53 -0
- package/template/themes/dogga/src/kit.tsx +362 -0
- package/template/themes/dogga/src/site.ts +56 -0
- package/template/themes/dogga/src/styles.css +396 -0
- package/template/themes/mahdia/screenshot.jpg +0 -0
- package/template/themes/mahdia/snapify.theme.json +65 -0
- package/template/themes/mahdia/src/Brand.tsx +39 -0
- package/template/themes/mahdia/src/Footer.tsx +210 -0
- package/template/themes/mahdia/src/Header.tsx +291 -0
- package/template/themes/mahdia/src/Layout.tsx +44 -0
- package/template/themes/mahdia/src/Views.tsx +79 -0
- package/template/themes/mahdia/src/blocks/CollectionBlocks.tsx +674 -0
- package/template/themes/mahdia/src/blocks/ContentBlocks.tsx +307 -0
- package/template/themes/mahdia/src/blocks/ConversionBlocks.tsx +571 -0
- package/template/themes/mahdia/src/blocks/HeaderBlocks.tsx +289 -0
- package/template/themes/mahdia/src/index.tsx +53 -0
- package/template/themes/mahdia/src/kit.tsx +362 -0
- package/template/themes/mahdia/src/site.ts +75 -0
- package/template/themes/mahdia/src/styles.css +446 -0
- package/template/themes/preveris/screenshot.jpg +0 -0
- package/template/themes/preveris/snapify.theme.json +126 -0
- package/template/themes/preveris/src/Brand.tsx +44 -0
- package/template/themes/preveris/src/Footer.tsx +202 -0
- package/template/themes/preveris/src/Header.tsx +239 -0
- package/template/themes/preveris/src/Layout.tsx +42 -0
- package/template/themes/preveris/src/Views.tsx +71 -0
- package/template/themes/preveris/src/blocks/CollectionBlocks.tsx +678 -0
- package/template/themes/preveris/src/blocks/ContentBlocks.tsx +307 -0
- package/template/themes/preveris/src/blocks/ConversionBlocks.tsx +571 -0
- package/template/themes/preveris/src/blocks/HeaderBlocks.tsx +299 -0
- package/template/themes/preveris/src/index.tsx +53 -0
- package/template/themes/preveris/src/kit.tsx +365 -0
- package/template/themes/preveris/src/site.ts +79 -0
- package/template/themes/preveris/src/styles.css +446 -0
- package/template/themes/sidibou/screenshot.jpg +0 -0
- package/template/themes/sidibou/snapify.theme.json +21 -0
- package/template/themes/sidibou/src/CeeSimulator.tsx +247 -0
- package/template/themes/sidibou/src/Footer.tsx +203 -0
- package/template/themes/sidibou/src/Header.tsx +324 -0
- package/template/themes/sidibou/src/Layout.tsx +53 -0
- package/template/themes/sidibou/src/NotFound.tsx +58 -0
- package/template/themes/sidibou/src/Post.tsx +26 -0
- package/template/themes/sidibou/src/SnapifyLogo.tsx +44 -0
- package/template/themes/sidibou/src/blocks/CollectionBlocks.tsx +711 -0
- package/template/themes/sidibou/src/blocks/ContentBlocks.tsx +318 -0
- package/template/themes/sidibou/src/blocks/ConversionBlocks.tsx +559 -0
- package/template/themes/sidibou/src/blocks/HeaderBlocks.tsx +341 -0
- package/template/themes/sidibou/src/index.tsx +54 -0
- package/template/themes/sidibou/src/kit.tsx +398 -0
- package/template/themes/sidibou/src/site.ts +28 -0
- package/template/themes/sidibou/src/styles.css +317 -0
- package/template/tsconfig.json +33 -0
- package/template/vite.config.ts +42 -0
|
@@ -0,0 +1,808 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Snapify
|
|
3
|
+
* © 2026 NOVALABS WEB DESIGN — Tunisie
|
|
4
|
+
* Contact : contact@novalabs.tn · +216 24 734 647
|
|
5
|
+
* Tous droits réservés. Toute reproduction, modification ou diffusion sans autorisation écrite est interdite.
|
|
6
|
+
*/
|
|
7
|
+
import crypto from 'crypto';
|
|
8
|
+
import fs from 'fs/promises';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import { loadSnapshot, updateSnapshot, getDataPaths } from '../cms/store';
|
|
11
|
+
import { assertPerm, hasPerm, requireAuth, requirePerm, type AuthedRequest } from '../middleware/adminAuth';
|
|
12
|
+
import { analyzePageSeo, analyzePostSeo } from '../cms/seoAnalyzer';
|
|
13
|
+
import { saveRevision, listRevisions, getRevision } from '../cms/revisions';
|
|
14
|
+
import { summarizeAnalytics } from '../cms/analyticsStore';
|
|
15
|
+
import { asyncRouter, HttpError } from '../http';
|
|
16
|
+
import type {
|
|
17
|
+
BlockPattern,
|
|
18
|
+
BlogPost,
|
|
19
|
+
CmsBlock,
|
|
20
|
+
CmsPage,
|
|
21
|
+
CmsSnapshot,
|
|
22
|
+
MenuItem,
|
|
23
|
+
RedirectRule,
|
|
24
|
+
SystemSettings,
|
|
25
|
+
WidgetArea,
|
|
26
|
+
WidgetInstance,
|
|
27
|
+
} from '../cms/types';
|
|
28
|
+
import { defaultSeoForPath } from '../cms/defaults';
|
|
29
|
+
import { publicUser } from '../security/accounts';
|
|
30
|
+
import { smtpSource } from '../mail';
|
|
31
|
+
import { googleOAuthConfigured } from './googleOAuth';
|
|
32
|
+
|
|
33
|
+
/** Types MIME acceptés selon les paramètres « Médias ». */
|
|
34
|
+
function allowedMime(u: SystemSettings['uploads'], mime: string): boolean {
|
|
35
|
+
if (u.allowImages && /^image\/(png|jpe?g|webp|gif|avif)$/.test(mime)) return true;
|
|
36
|
+
if (u.allowSvg && mime === 'image/svg+xml') return true;
|
|
37
|
+
if (u.allowVideo && /^video\/(mp4|webm)$/.test(mime)) return true;
|
|
38
|
+
return u.allowPdf && mime === 'application/pdf';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function allowedLabel(u: SystemSettings['uploads']): string {
|
|
42
|
+
const kinds = [u.allowImages && 'images', u.allowSvg && 'SVG', u.allowVideo && 'vidéos MP4/WebM', u.allowPdf && 'PDF'].filter(Boolean);
|
|
43
|
+
return kinds.length ? kinds.join(', ') : 'aucun format autorisé';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Sans droit de publication, seuls les brouillons sont modifiables (et ils le restent). */
|
|
47
|
+
function assertCanTouchStatus(req: AuthedRequest, perm: 'pages.publish' | 'posts.publish', before: { status: string }, nextStatus?: string) {
|
|
48
|
+
if (hasPerm(req, perm)) return;
|
|
49
|
+
if (before.status !== 'draft') throw new HttpError(403, 'Ce contenu est en ligne ou planifié : seule une personne autorisée à publier peut le modifier', 'FORBIDDEN');
|
|
50
|
+
if (nextStatus && nextStatus !== 'draft') throw new HttpError(403, 'Vous n’êtes pas autorisé à publier : enregistrez en brouillon', 'FORBIDDEN');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function pick<T extends object>(source: unknown, keys: (keyof T)[]): Partial<T> {
|
|
54
|
+
const out: Partial<T> = {};
|
|
55
|
+
if (!source || typeof source !== 'object') return out;
|
|
56
|
+
for (const k of keys) {
|
|
57
|
+
if (k in (source as object)) out[k] = (source as T)[k];
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function normalizePath(input: string): string {
|
|
63
|
+
const cleaned = input
|
|
64
|
+
.trim()
|
|
65
|
+
.toLowerCase()
|
|
66
|
+
.normalize('NFD')
|
|
67
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
68
|
+
.replace(/[^a-z0-9/-]+/g, '-')
|
|
69
|
+
.replace(/\/{2,}/g, '/')
|
|
70
|
+
.replace(/-{2,}/g, '-');
|
|
71
|
+
const withSlashes = `/${cleaned.replace(/^\/+|\/+$/g, '')}/`;
|
|
72
|
+
return withSlashes === '//' ? '/' : withSlashes;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function slugify(input: string): string {
|
|
76
|
+
return normalizePath(input).replace(/^\/|\/$/g, '').replace(/\//g, '-');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const PROTECTED_MENU_IDS = new Set(['primary', 'mobile', 'footer']);
|
|
80
|
+
|
|
81
|
+
function normalizeMenuId(raw: string): string {
|
|
82
|
+
const id = raw
|
|
83
|
+
.trim()
|
|
84
|
+
.toLowerCase()
|
|
85
|
+
.normalize('NFD')
|
|
86
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
87
|
+
.replace(/[^a-z0-9_-]+/g, '-')
|
|
88
|
+
.replace(/^-+|-+$/g, '');
|
|
89
|
+
if (!id) throw new HttpError(400, 'Identifiant de menu invalide');
|
|
90
|
+
return id;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const CORE_WIDGET_KINDS = new Set(['text', 'html', 'menu', 'recent_posts', 'search', 'module']);
|
|
94
|
+
|
|
95
|
+
function sanitizeWidgetInstance(raw: unknown): WidgetInstance {
|
|
96
|
+
const w = raw as WidgetInstance;
|
|
97
|
+
if (!w?.id?.trim()) throw new HttpError(400, 'Chaque widget doit avoir un identifiant');
|
|
98
|
+
if (!CORE_WIDGET_KINDS.has(String(w.kind))) throw new HttpError(400, `Type de widget inconnu : ${String(w.kind)}`);
|
|
99
|
+
return {
|
|
100
|
+
id: w.id.trim(),
|
|
101
|
+
kind: w.kind,
|
|
102
|
+
title: String(w.title ?? '').trim(),
|
|
103
|
+
data: w.data && typeof w.data === 'object' && !Array.isArray(w.data) ? (w.data as Record<string, unknown>) : {},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function sanitizeWidgetAreas(raw: unknown): WidgetArea[] {
|
|
108
|
+
if (!Array.isArray(raw)) throw new HttpError(400, 'Liste de zones invalide');
|
|
109
|
+
return raw.map((area) => {
|
|
110
|
+
const a = area as WidgetArea;
|
|
111
|
+
if (!a?.id?.trim() || !a.label?.trim()) throw new HttpError(400, 'Chaque zone doit avoir un identifiant et un libellé');
|
|
112
|
+
return {
|
|
113
|
+
id: a.id.trim(),
|
|
114
|
+
label: a.label.trim(),
|
|
115
|
+
description: a.description?.trim() || undefined,
|
|
116
|
+
widgets: Array.isArray(a.widgets) ? a.widgets.map(sanitizeWidgetInstance) : [],
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function sanitizeBlockPatterns(raw: unknown): BlockPattern[] {
|
|
122
|
+
if (!Array.isArray(raw)) throw new HttpError(400, 'Liste de modèles invalide');
|
|
123
|
+
return raw.map((p) => {
|
|
124
|
+
const pat = p as BlockPattern;
|
|
125
|
+
if (!pat?.id?.trim() || !pat.name?.trim()) throw new HttpError(400, 'Chaque modèle doit avoir un identifiant et un nom');
|
|
126
|
+
if (!Array.isArray(pat.blocks)) throw new HttpError(400, 'Modèle de blocs invalide');
|
|
127
|
+
return {
|
|
128
|
+
id: pat.id.trim(),
|
|
129
|
+
name: pat.name.trim(),
|
|
130
|
+
description: pat.description?.trim() || undefined,
|
|
131
|
+
blocks: pat.blocks as CmsBlock[],
|
|
132
|
+
createdAt: pat.createdAt || new Date().toISOString(),
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function sanitizeMenuItems(items: unknown, depth = 0): MenuItem[] {
|
|
138
|
+
if (!Array.isArray(items)) throw new HttpError(400, 'Menu invalide');
|
|
139
|
+
return items.map((raw) => {
|
|
140
|
+
const it = raw as MenuItem;
|
|
141
|
+
if (!it.label?.trim() || !it.path?.trim()) throw new HttpError(400, 'Chaque lien doit avoir un libellé et une destination');
|
|
142
|
+
return {
|
|
143
|
+
id: it.id || crypto.randomUUID(),
|
|
144
|
+
label: it.label.trim(),
|
|
145
|
+
path: it.path.trim(),
|
|
146
|
+
openInNewTab: !!it.openInNewTab,
|
|
147
|
+
highlight: !!it.highlight,
|
|
148
|
+
children: depth === 0 && it.children?.length ? sanitizeMenuItems(it.children, 1) : undefined,
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function sanitizeSnapshotForClient(s: CmsSnapshot, req: AuthedRequest) {
|
|
154
|
+
const { oauthRefreshToken, oauthClientSecretEnc: _secret, ...google } = s.google;
|
|
155
|
+
return {
|
|
156
|
+
...s,
|
|
157
|
+
google: { ...google, hasRefreshToken: !!oauthRefreshToken },
|
|
158
|
+
users: hasPerm(req, 'users.view') ? s.users.map(publicUser) : s.users.filter((u) => u.id === req.admin!.sub).map(publicUser),
|
|
159
|
+
system: undefined,
|
|
160
|
+
formSubmissions: undefined,
|
|
161
|
+
subscribers: undefined,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function createAdminCmsRouter() {
|
|
166
|
+
const router = asyncRouter();
|
|
167
|
+
|
|
168
|
+
/* ---------- Lecture globale & tableau de bord ---------- */
|
|
169
|
+
|
|
170
|
+
router.get('/snapshot', requireAuth(), async (req: AuthedRequest, res) => {
|
|
171
|
+
res.json(sanitizeSnapshotForClient(await loadSnapshot(), req));
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
router.get('/dashboard', requireAuth(), async (req: AuthedRequest, res) => {
|
|
175
|
+
const s = await loadSnapshot();
|
|
176
|
+
const canForms = hasPerm(req, 'forms.view');
|
|
177
|
+
const analytics = hasPerm(req, 'analytics.view') ? await summarizeAnalytics(30, new URL(s.settings.publicUrl).hostname) : null;
|
|
178
|
+
const seoScores = [
|
|
179
|
+
...s.pages.filter((p) => p.status === 'published').map((p) => analyzePageSeo(p).score),
|
|
180
|
+
...s.posts.filter((p) => p.status === 'published').map((p) => analyzePostSeo(p).score),
|
|
181
|
+
];
|
|
182
|
+
res.json({
|
|
183
|
+
analytics,
|
|
184
|
+
counts: {
|
|
185
|
+
pages: s.pages.length,
|
|
186
|
+
publishedPages: s.pages.filter((p) => p.status === 'published').length,
|
|
187
|
+
posts: s.posts.length,
|
|
188
|
+
draftPosts: s.posts.filter((p) => p.status === 'draft').length,
|
|
189
|
+
unreadSubmissions: canForms ? s.formSubmissions.filter((x) => !x.read).length : null,
|
|
190
|
+
submissions: canForms ? s.formSubmissions.length : null,
|
|
191
|
+
subscribers: hasPerm(req, 'newsletter.manage') ? s.subscribers.filter((x) => x.status === 'active').length : null,
|
|
192
|
+
media: s.media.length,
|
|
193
|
+
},
|
|
194
|
+
seoAverage: seoScores.length ? Math.round(seoScores.reduce((a, b) => a + b, 0) / seoScores.length) : 0,
|
|
195
|
+
recentSubmissions: canForms ? s.formSubmissions.slice(0, 5) : null,
|
|
196
|
+
maintenance: s.settings.maintenance.enabled,
|
|
197
|
+
health: hasPerm(req, 'settings.manage', 'seo.edit', 'modules.manage')
|
|
198
|
+
? {
|
|
199
|
+
smtp: smtpSource(s) !== 'none',
|
|
200
|
+
gemini: !!process.env.GEMINI_API_KEY,
|
|
201
|
+
google: s.google.connected,
|
|
202
|
+
googleOAuthConfigured: googleOAuthConfigured(s),
|
|
203
|
+
}
|
|
204
|
+
: null,
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
/* ---------- Réglages ---------- */
|
|
209
|
+
|
|
210
|
+
router.put('/general', requirePerm('site.general'), async (req, res) => {
|
|
211
|
+
const patch = pick<CmsSnapshot['general']>(req.body, [
|
|
212
|
+
'legalName', 'baseline', 'slogan', 'phone', 'phoneClean', 'contactEmail', 'slaHours', 'address', 'timezone', 'locale',
|
|
213
|
+
]);
|
|
214
|
+
if (patch.phone && !patch.phoneClean) {
|
|
215
|
+
const digits = patch.phone.replace(/\D/g, '');
|
|
216
|
+
patch.phoneClean = patch.phone.trim().startsWith('+') ? `+${digits}` : digits.startsWith('00') ? `+${digits.slice(2)}` : `+33${digits.replace(/^0/, '')}`;
|
|
217
|
+
}
|
|
218
|
+
await updateSnapshot((s) => {
|
|
219
|
+
s.general = { ...s.general, ...patch };
|
|
220
|
+
});
|
|
221
|
+
res.json({ ok: true });
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
router.put('/branding', requirePerm('appearance.customize'), async (req, res) => {
|
|
225
|
+
const body = req.body as Partial<CmsSnapshot['branding']>;
|
|
226
|
+
const patch = pick<CmsSnapshot['branding']>(body, ['siteName', 'tagline', 'logoUrl', 'logoDarkUrl', 'faviconUrl']);
|
|
227
|
+
await updateSnapshot((s) => {
|
|
228
|
+
s.branding = {
|
|
229
|
+
...s.branding,
|
|
230
|
+
...patch,
|
|
231
|
+
colors: { ...s.branding.colors, ...(body.colors || {}) },
|
|
232
|
+
fonts: { ...s.branding.fonts, ...(body.fonts || {}) },
|
|
233
|
+
};
|
|
234
|
+
});
|
|
235
|
+
res.json({ ok: true });
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
router.put('/settings', requirePerm('site.maintenance', 'settings.manage'), async (req: AuthedRequest, res) => {
|
|
239
|
+
const body = req.body as Partial<CmsSnapshot['settings']>;
|
|
240
|
+
const patch = pick<CmsSnapshot['settings']>(body, [
|
|
241
|
+
'publicUrl', 'cookieBannerEnabled', 'analyticsEnabled', 'robotsTxtExtra', 'sitemapAuto',
|
|
242
|
+
]);
|
|
243
|
+
if (Object.keys(patch).length || body.seo) assertPerm(req, 'settings.manage');
|
|
244
|
+
if (body.maintenance && !hasPerm(req, 'settings.manage')) assertPerm(req, 'site.maintenance');
|
|
245
|
+
res.locals.audit = body.maintenance && !Object.keys(patch).length && !body.seo
|
|
246
|
+
? { action: 'site.maintenance', detail: { enabled: body.maintenance.enabled } }
|
|
247
|
+
: undefined;
|
|
248
|
+
if (patch.publicUrl) {
|
|
249
|
+
try {
|
|
250
|
+
new URL(patch.publicUrl);
|
|
251
|
+
} catch {
|
|
252
|
+
throw new HttpError(400, 'URL publique invalide');
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
await updateSnapshot((s) => {
|
|
256
|
+
s.settings = {
|
|
257
|
+
...s.settings,
|
|
258
|
+
...patch,
|
|
259
|
+
maintenance: { ...s.settings.maintenance, ...(body.maintenance || {}) },
|
|
260
|
+
seo: { ...s.settings.seo, ...(body.seo || {}) },
|
|
261
|
+
};
|
|
262
|
+
});
|
|
263
|
+
res.json({ ok: true });
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
router.put('/seo-settings', requirePerm('seo.edit'), async (req, res) => {
|
|
267
|
+
const patch = pick<CmsSnapshot['settings']['seo']>(req.body || {}, [
|
|
268
|
+
'titleSeparator', 'titleSuffix', 'defaultOgImage', 'organizationName', 'organizationLogo', 'socialProfiles', 'googleVerification', 'bingVerification',
|
|
269
|
+
]);
|
|
270
|
+
if (patch.socialProfiles && !Array.isArray(patch.socialProfiles)) throw new HttpError(400, 'Profils sociaux invalides');
|
|
271
|
+
await updateSnapshot((s) => {
|
|
272
|
+
s.settings.seo = { ...s.settings.seo, ...patch };
|
|
273
|
+
if (typeof req.body?.robotsTxtExtra === 'string') s.settings.robotsTxtExtra = req.body.robotsTxtExtra.slice(0, 5000);
|
|
274
|
+
});
|
|
275
|
+
res.json({ ok: true });
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
router.put('/floating-buttons', requirePerm('engagement.edit'), async (req, res) => {
|
|
279
|
+
const list = Array.isArray(req.body?.buttons) ? req.body.buttons : [];
|
|
280
|
+
await updateSnapshot((s) => {
|
|
281
|
+
s.floatingButtons = list.map((b: CmsSnapshot['floatingButtons'][number]) => ({
|
|
282
|
+
id: b.id || crypto.randomUUID(),
|
|
283
|
+
label: String(b.label || '').trim(),
|
|
284
|
+
path: String(b.path || '').trim(),
|
|
285
|
+
style: b.style || 'primary',
|
|
286
|
+
enabled: !!b.enabled,
|
|
287
|
+
}));
|
|
288
|
+
});
|
|
289
|
+
res.json({ ok: true });
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
router.put('/newsletter', requirePerm('newsletter.manage'), async (req, res) => {
|
|
293
|
+
const patch = pick<CmsSnapshot['newsletter']>(req.body, ['enabled', 'provider', 'doubleOptIn', 'welcomeEmailSubject', 'listId']);
|
|
294
|
+
await updateSnapshot((s) => {
|
|
295
|
+
s.newsletter = { ...s.newsletter, ...patch };
|
|
296
|
+
});
|
|
297
|
+
res.json({ ok: true });
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
router.put('/google', requirePerm('seo.edit'), async (req, res) => {
|
|
301
|
+
const patch = pick<CmsSnapshot['google']>(req.body, ['searchConsoleProperty', 'analyticsPropertyId']);
|
|
302
|
+
await updateSnapshot((s) => {
|
|
303
|
+
s.google = { ...s.google, ...patch };
|
|
304
|
+
});
|
|
305
|
+
res.json({ ok: true });
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
router.post('/menus', requirePerm('menus.edit'), async (req, res) => {
|
|
309
|
+
const id = normalizeMenuId(String(req.body?.id || ''));
|
|
310
|
+
const label = String(req.body?.label || '').trim();
|
|
311
|
+
if (!label) throw new HttpError(400, 'Libellé du menu requis');
|
|
312
|
+
await updateSnapshot((s) => {
|
|
313
|
+
if (s.menus.some((m) => m.id === id)) throw new HttpError(409, 'Un menu porte déjà cet identifiant');
|
|
314
|
+
s.menus.push({ id, label, items: [] });
|
|
315
|
+
});
|
|
316
|
+
res.status(201).json({ ok: true, id });
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
router.put('/menus/:menuId', requirePerm('menus.edit'), async (req, res) => {
|
|
320
|
+
const menuId = req.params.menuId;
|
|
321
|
+
const label = req.body?.label !== undefined ? String(req.body.label).trim() : undefined;
|
|
322
|
+
const hasItems = req.body?.items !== undefined;
|
|
323
|
+
if (hasItems) sanitizeMenuItems(req.body.items);
|
|
324
|
+
await updateSnapshot((s) => {
|
|
325
|
+
let menu = s.menus.find((m) => m.id === menuId);
|
|
326
|
+
if (!menu) {
|
|
327
|
+
if (!label) throw new HttpError(404, 'Menu introuvable');
|
|
328
|
+
menu = { id: menuId, label, items: hasItems ? sanitizeMenuItems(req.body.items) : [] };
|
|
329
|
+
s.menus.push(menu);
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
if (label) menu.label = label;
|
|
333
|
+
if (hasItems) menu.items = sanitizeMenuItems(req.body.items);
|
|
334
|
+
});
|
|
335
|
+
res.json({ ok: true });
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
router.delete('/menus/:menuId', requirePerm('menus.edit'), async (req, res) => {
|
|
339
|
+
const menuId = req.params.menuId;
|
|
340
|
+
if (PROTECTED_MENU_IDS.has(menuId)) throw new HttpError(403, 'Ce menu système ne peut pas être supprimé');
|
|
341
|
+
await updateSnapshot((s) => {
|
|
342
|
+
const before = s.menus.length;
|
|
343
|
+
s.menus = s.menus.filter((m) => m.id !== menuId);
|
|
344
|
+
if (s.menus.length === before) throw new HttpError(404, 'Menu introuvable');
|
|
345
|
+
});
|
|
346
|
+
res.json({ ok: true });
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
router.put('/widget-areas', requirePerm('widgets.edit'), async (req, res) => {
|
|
350
|
+
const areas = sanitizeWidgetAreas(req.body?.areas ?? req.body);
|
|
351
|
+
await updateSnapshot((s) => {
|
|
352
|
+
s.widgetAreas = areas;
|
|
353
|
+
});
|
|
354
|
+
res.json({ ok: true, areas });
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
router.put('/widget-areas/:areaId', requirePerm('widgets.edit'), async (req, res) => {
|
|
358
|
+
const widgets = Array.isArray(req.body?.widgets) ? req.body.widgets.map(sanitizeWidgetInstance) : null;
|
|
359
|
+
if (!widgets) throw new HttpError(400, 'Liste de widgets requise');
|
|
360
|
+
await updateSnapshot((s) => {
|
|
361
|
+
const area = s.widgetAreas.find((a) => a.id === req.params.areaId);
|
|
362
|
+
if (!area) throw new HttpError(404, 'Zone de widgets introuvable');
|
|
363
|
+
area.widgets = widgets;
|
|
364
|
+
});
|
|
365
|
+
res.json({ ok: true });
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
router.get('/block-patterns', requireAuth(), async (_req, res) => {
|
|
369
|
+
const s = await loadSnapshot();
|
|
370
|
+
res.json(s.blockPatterns);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
router.put('/block-patterns', requirePerm('widgets.edit'), async (req, res) => {
|
|
374
|
+
const patterns = sanitizeBlockPatterns(req.body?.patterns ?? req.body);
|
|
375
|
+
await updateSnapshot((s) => {
|
|
376
|
+
s.blockPatterns = patterns;
|
|
377
|
+
});
|
|
378
|
+
res.json({ ok: true, patterns });
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
router.post('/block-patterns', requirePerm('widgets.edit'), async (req, res) => {
|
|
382
|
+
const body = req.body as Partial<BlockPattern>;
|
|
383
|
+
if (!body.name?.trim()) throw new HttpError(400, 'Nom du modèle requis');
|
|
384
|
+
if (!Array.isArray(body.blocks)) throw new HttpError(400, 'Blocs requis');
|
|
385
|
+
const pattern: BlockPattern = {
|
|
386
|
+
id: body.id?.trim() || crypto.randomUUID(),
|
|
387
|
+
name: body.name.trim(),
|
|
388
|
+
description: body.description?.trim(),
|
|
389
|
+
blocks: body.blocks as CmsBlock[],
|
|
390
|
+
createdAt: new Date().toISOString(),
|
|
391
|
+
};
|
|
392
|
+
await updateSnapshot((s) => {
|
|
393
|
+
if (s.blockPatterns.some((p) => p.id === pattern.id)) throw new HttpError(409, 'Identifiant de modèle déjà utilisé');
|
|
394
|
+
s.blockPatterns.unshift(pattern);
|
|
395
|
+
});
|
|
396
|
+
res.status(201).json(pattern);
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
router.delete('/block-patterns/:id', requirePerm('widgets.edit'), async (req, res) => {
|
|
400
|
+
await updateSnapshot((s) => {
|
|
401
|
+
const before = s.blockPatterns.length;
|
|
402
|
+
s.blockPatterns = s.blockPatterns.filter((p) => p.id !== req.params.id);
|
|
403
|
+
if (s.blockPatterns.length === before) throw new HttpError(404, 'Modèle introuvable');
|
|
404
|
+
});
|
|
405
|
+
res.json({ ok: true });
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
router.put('/redirects', requirePerm('seo.edit'), async (req, res) => {
|
|
409
|
+
const list = (Array.isArray(req.body?.redirects) ? req.body.redirects : []) as RedirectRule[];
|
|
410
|
+
const seen = new Set<string>();
|
|
411
|
+
const redirects = list.map((r) => {
|
|
412
|
+
const from = normalizePath(String(r.from || ''));
|
|
413
|
+
const to = String(r.to || '').trim();
|
|
414
|
+
if (!to) throw new HttpError(400, `Destination manquante pour ${from}`);
|
|
415
|
+
if (seen.has(from)) throw new HttpError(400, `Redirection en double : ${from}`);
|
|
416
|
+
if (from === normalizePath(to)) throw new HttpError(400, `Redirection en boucle : ${from}`);
|
|
417
|
+
seen.add(from);
|
|
418
|
+
return { from, to: to.startsWith('http') ? to : normalizePath(to), permanent: r.permanent !== false };
|
|
419
|
+
});
|
|
420
|
+
await updateSnapshot((s) => {
|
|
421
|
+
s.redirects = redirects;
|
|
422
|
+
});
|
|
423
|
+
res.json({ ok: true });
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
/* ---------- Pages ---------- */
|
|
427
|
+
|
|
428
|
+
router.get('/pages', requireAuth(), async (_req, res) => {
|
|
429
|
+
const s = await loadSnapshot();
|
|
430
|
+
res.json(s.pages.map((p) => ({ ...p, seoScore: analyzePageSeo(p).score })));
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
router.post('/pages', requirePerm('pages.edit'), async (req, res) => {
|
|
434
|
+
const body = req.body as Partial<CmsPage>;
|
|
435
|
+
if (!body.title?.trim()) throw new HttpError(400, 'Titre requis');
|
|
436
|
+
const pagePath = normalizePath(body.path || body.title);
|
|
437
|
+
const s = await loadSnapshot();
|
|
438
|
+
if (s.pages.some((p) => p.path === pagePath)) throw new HttpError(409, `L'adresse ${pagePath} est déjà utilisée`);
|
|
439
|
+
const t = new Date().toISOString();
|
|
440
|
+
const template = body.template || 'default';
|
|
441
|
+
const page: CmsPage = {
|
|
442
|
+
id: crypto.randomUUID(),
|
|
443
|
+
path: pagePath,
|
|
444
|
+
title: body.title.trim(),
|
|
445
|
+
status: 'draft',
|
|
446
|
+
contentSource: 'cms',
|
|
447
|
+
template,
|
|
448
|
+
blocks: body.blocks || [],
|
|
449
|
+
seo: body.seo || defaultSeoForPath(pagePath, body.title.trim()),
|
|
450
|
+
...(body.project
|
|
451
|
+
? { project: body.project }
|
|
452
|
+
: template === 'project'
|
|
453
|
+
? { project: { client: '', location: '', sector: 'Industrie', solution: '', summary: '', image: '', results: [] } }
|
|
454
|
+
: {}),
|
|
455
|
+
createdAt: t,
|
|
456
|
+
updatedAt: t,
|
|
457
|
+
};
|
|
458
|
+
await updateSnapshot((snap) => {
|
|
459
|
+
snap.pages.push(page);
|
|
460
|
+
});
|
|
461
|
+
res.locals.audit = { target: page.title };
|
|
462
|
+
res.status(201).json(page);
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
router.put('/pages/:id', requirePerm('pages.edit', 'seo.edit'), async (req: AuthedRequest, res) => {
|
|
466
|
+
const id = req.params.id;
|
|
467
|
+
const s = await loadSnapshot();
|
|
468
|
+
const before = s.pages.find((p) => p.id === id);
|
|
469
|
+
if (!before) throw new HttpError(404, 'Page introuvable');
|
|
470
|
+
const body = req.body as Partial<CmsPage>;
|
|
471
|
+
|
|
472
|
+
// Sans droit d'édition (ou sur un contenu en ligne sans droit de publication), seul le référencement est modifiable.
|
|
473
|
+
const contentEditable = hasPerm(req, 'pages.edit') && (hasPerm(req, 'pages.publish') || before.status === 'draft');
|
|
474
|
+
let patch: Partial<CmsPage>;
|
|
475
|
+
if (contentEditable) {
|
|
476
|
+
patch = pick<CmsPage>(body, ['title', 'path', 'status', 'scheduledAt', 'contentSource', 'template', 'blocks', 'seo', 'project']);
|
|
477
|
+
const statusChange = patch.status !== undefined && patch.status !== before.status;
|
|
478
|
+
const scheduleChange = !!patch.scheduledAt && patch.scheduledAt !== before.scheduledAt;
|
|
479
|
+
if (statusChange || scheduleChange) assertCanTouchStatus(req, 'pages.publish', before, statusChange ? patch.status : 'scheduled');
|
|
480
|
+
} else if (hasPerm(req, 'seo.edit')) {
|
|
481
|
+
patch = { seo: body.seo };
|
|
482
|
+
} else {
|
|
483
|
+
assertCanTouchStatus(req, 'pages.publish', before);
|
|
484
|
+
patch = {};
|
|
485
|
+
}
|
|
486
|
+
if (!patch.seo) delete patch.seo;
|
|
487
|
+
|
|
488
|
+
if (patch.path) {
|
|
489
|
+
patch.path = normalizePath(patch.path);
|
|
490
|
+
if (s.pages.some((p) => p.id !== id && p.path === patch.path)) throw new HttpError(409, `L'adresse ${patch.path} est déjà utilisée`);
|
|
491
|
+
}
|
|
492
|
+
if (patch.status === 'scheduled' && !(patch.scheduledAt || before.scheduledAt)) {
|
|
493
|
+
throw new HttpError(400, 'Indiquez une date de publication');
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
await saveRevision({ entityType: 'page', entityId: id, label: before.title, snapshot: before, authorEmail: req.admin?.email });
|
|
497
|
+
const updated = await updateSnapshot((snap) => {
|
|
498
|
+
const idx = snap.pages.findIndex((p) => p.id === id);
|
|
499
|
+
const next = { ...snap.pages[idx], ...patch, updatedAt: new Date().toISOString() };
|
|
500
|
+
if (next.status === 'published' && !next.publishedAt) next.publishedAt = next.updatedAt;
|
|
501
|
+
snap.pages[idx] = next;
|
|
502
|
+
});
|
|
503
|
+
const page = updated.pages.find((p) => p.id === id)!;
|
|
504
|
+
res.locals.audit = { target: page.title, detail: before.status !== page.status ? { status: { from: before.status, to: page.status } } : undefined };
|
|
505
|
+
res.json({ ...page, seoScore: analyzePageSeo(page).score });
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
router.delete('/pages/:id', requirePerm('pages.delete'), async (req, res) => {
|
|
509
|
+
let title = '';
|
|
510
|
+
await updateSnapshot((s) => {
|
|
511
|
+
const page = s.pages.find((p) => p.id === req.params.id);
|
|
512
|
+
if (!page) throw new HttpError(404, 'Page introuvable');
|
|
513
|
+
if (page.path === '/') throw new HttpError(400, "La page d'accueil ne peut pas être supprimée");
|
|
514
|
+
title = page.title;
|
|
515
|
+
s.pages = s.pages.filter((p) => p.id !== req.params.id);
|
|
516
|
+
});
|
|
517
|
+
res.locals.audit = { target: title };
|
|
518
|
+
res.json({ ok: true });
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
router.get('/pages/:id/revisions', requireAuth(), async (req, res) => {
|
|
522
|
+
const revs = await listRevisions('page', req.params.id);
|
|
523
|
+
res.json(revs.map(({ snapshot, ...r }) => ({ ...r, title: snapshot.title })));
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
router.post('/pages/:id/revisions/:revId/restore', requirePerm('pages.edit'), async (req: AuthedRequest, res) => {
|
|
527
|
+
const rev = await getRevision(req.params.revId);
|
|
528
|
+
if (!rev || rev.entityType !== 'page' || rev.entityId !== req.params.id) throw new HttpError(404, 'Révision introuvable');
|
|
529
|
+
const current = (await loadSnapshot()).pages.find((p) => p.id === req.params.id);
|
|
530
|
+
if (current) assertCanTouchStatus(req, 'pages.publish', current, (rev.snapshot as CmsPage).status);
|
|
531
|
+
res.locals.audit = { target: current?.title };
|
|
532
|
+
if (current) await saveRevision({ entityType: 'page', entityId: current.id, label: current.title, snapshot: current, authorEmail: req.admin?.email });
|
|
533
|
+
const updated = await updateSnapshot((s) => {
|
|
534
|
+
const idx = s.pages.findIndex((p) => p.id === req.params.id);
|
|
535
|
+
if (idx === -1) throw new HttpError(404, 'Page introuvable');
|
|
536
|
+
s.pages[idx] = { ...(rev.snapshot as CmsPage), updatedAt: new Date().toISOString() };
|
|
537
|
+
});
|
|
538
|
+
res.json(updated.pages.find((p) => p.id === req.params.id));
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
/* ---------- Articles ---------- */
|
|
542
|
+
|
|
543
|
+
router.get('/posts', requireAuth(), async (_req, res) => {
|
|
544
|
+
const s = await loadSnapshot();
|
|
545
|
+
res.json(s.posts.map((p) => ({ ...p, seoScore: analyzePostSeo(p).score })));
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
router.post('/posts', requirePerm('posts.edit'), async (req: AuthedRequest, res) => {
|
|
549
|
+
const body = req.body as Partial<BlogPost>;
|
|
550
|
+
const title = body.title?.trim() || 'Nouvel article';
|
|
551
|
+
const s = await loadSnapshot();
|
|
552
|
+
let slug = slugify(body.slug || title);
|
|
553
|
+
let n = 2;
|
|
554
|
+
while (s.posts.some((p) => p.slug === slug)) slug = `${slugify(body.slug || title)}-${n++}`;
|
|
555
|
+
const t = new Date().toISOString();
|
|
556
|
+
const post: BlogPost = {
|
|
557
|
+
id: crypto.randomUUID(),
|
|
558
|
+
slug,
|
|
559
|
+
title,
|
|
560
|
+
excerpt: body.excerpt || '',
|
|
561
|
+
coverImage: body.coverImage,
|
|
562
|
+
blocks: body.blocks || [],
|
|
563
|
+
seo: { ...defaultSeoForPath(`/blog/${slug}/`, title), slug, schemaType: 'Article' },
|
|
564
|
+
status: 'draft',
|
|
565
|
+
author: req.admin?.name,
|
|
566
|
+
tags: body.tags || [],
|
|
567
|
+
createdAt: t,
|
|
568
|
+
updatedAt: t,
|
|
569
|
+
};
|
|
570
|
+
await updateSnapshot((snap) => {
|
|
571
|
+
snap.posts.unshift(post);
|
|
572
|
+
});
|
|
573
|
+
res.locals.audit = { target: post.title };
|
|
574
|
+
res.status(201).json(post);
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
router.put('/posts/:id', requirePerm('posts.edit', 'seo.edit'), async (req: AuthedRequest, res) => {
|
|
578
|
+
const id = req.params.id;
|
|
579
|
+
const s = await loadSnapshot();
|
|
580
|
+
const before = s.posts.find((p) => p.id === id);
|
|
581
|
+
if (!before) throw new HttpError(404, 'Article introuvable');
|
|
582
|
+
const body = req.body as Partial<BlogPost>;
|
|
583
|
+
const contentEditable = hasPerm(req, 'posts.edit') && (hasPerm(req, 'posts.publish') || before.status === 'draft');
|
|
584
|
+
let patch: Partial<BlogPost>;
|
|
585
|
+
if (contentEditable) {
|
|
586
|
+
patch = pick<BlogPost>(body, ['title', 'slug', 'excerpt', 'coverImage', 'blocks', 'seo', 'status', 'publishedAt', 'scheduledAt', 'tags', 'author']);
|
|
587
|
+
const statusChange = patch.status !== undefined && patch.status !== before.status;
|
|
588
|
+
const dateChange = !!patch.publishedAt && patch.publishedAt !== before.publishedAt;
|
|
589
|
+
const scheduleChange = !!patch.scheduledAt && patch.scheduledAt !== before.scheduledAt;
|
|
590
|
+
if (statusChange || dateChange || scheduleChange) {
|
|
591
|
+
assertCanTouchStatus(req, 'posts.publish', before, statusChange ? patch.status : scheduleChange ? 'scheduled' : 'published');
|
|
592
|
+
}
|
|
593
|
+
} else if (hasPerm(req, 'seo.edit')) {
|
|
594
|
+
patch = { seo: body.seo };
|
|
595
|
+
} else {
|
|
596
|
+
assertCanTouchStatus(req, 'posts.publish', before);
|
|
597
|
+
patch = {};
|
|
598
|
+
}
|
|
599
|
+
if (!patch.seo) delete patch.seo;
|
|
600
|
+
if (patch.slug) {
|
|
601
|
+
patch.slug = slugify(patch.slug);
|
|
602
|
+
if (s.posts.some((p) => p.id !== id && p.slug === patch.slug)) throw new HttpError(409, 'Ce slug est déjà utilisé');
|
|
603
|
+
}
|
|
604
|
+
await saveRevision({ entityType: 'post', entityId: id, label: before.title, snapshot: before, authorEmail: req.admin?.email });
|
|
605
|
+
const updated = await updateSnapshot((snap) => {
|
|
606
|
+
const idx = snap.posts.findIndex((p) => p.id === id);
|
|
607
|
+
const next = { ...snap.posts[idx], ...patch, updatedAt: new Date().toISOString() };
|
|
608
|
+
if (next.status === 'published' && !next.publishedAt) next.publishedAt = next.updatedAt;
|
|
609
|
+
if (next.status === 'scheduled' && !(next.scheduledAt || before.scheduledAt)) {
|
|
610
|
+
throw new HttpError(400, 'Date de publication planifiée requise pour un article planifié');
|
|
611
|
+
}
|
|
612
|
+
snap.posts[idx] = next;
|
|
613
|
+
});
|
|
614
|
+
const post = updated.posts.find((p) => p.id === id)!;
|
|
615
|
+
res.locals.audit = { target: post.title, detail: before.status !== post.status ? { status: { from: before.status, to: post.status } } : undefined };
|
|
616
|
+
res.json({ ...post, seoScore: analyzePostSeo(post).score });
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
router.delete('/posts/:id', requirePerm('posts.delete'), async (req, res) => {
|
|
620
|
+
let title = '';
|
|
621
|
+
await updateSnapshot((s) => {
|
|
622
|
+
const post = s.posts.find((p) => p.id === req.params.id);
|
|
623
|
+
if (!post) throw new HttpError(404, 'Article introuvable');
|
|
624
|
+
title = post.title;
|
|
625
|
+
s.posts = s.posts.filter((p) => p.id !== req.params.id);
|
|
626
|
+
});
|
|
627
|
+
res.locals.audit = { target: title };
|
|
628
|
+
res.json({ ok: true });
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
router.get('/posts/:id/revisions', requireAuth(), async (req, res) => {
|
|
632
|
+
const revs = await listRevisions('post', req.params.id);
|
|
633
|
+
res.json(revs.map(({ snapshot, ...r }) => ({ ...r, title: snapshot.title })));
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
router.post('/posts/:id/revisions/:revId/restore', requirePerm('posts.edit'), async (req: AuthedRequest, res) => {
|
|
637
|
+
const rev = await getRevision(req.params.revId);
|
|
638
|
+
if (!rev || rev.entityType !== 'post' || rev.entityId !== req.params.id) throw new HttpError(404, 'Révision introuvable');
|
|
639
|
+
const current = (await loadSnapshot()).posts.find((p) => p.id === req.params.id);
|
|
640
|
+
if (current) assertCanTouchStatus(req, 'posts.publish', current, (rev.snapshot as BlogPost).status);
|
|
641
|
+
// Snapshot de l’état courant avant écrasement (comme pour les pages).
|
|
642
|
+
if (current) await saveRevision({ entityType: 'post', entityId: current.id, label: current.title, snapshot: current, authorEmail: req.admin?.email });
|
|
643
|
+
res.locals.audit = { target: current?.title };
|
|
644
|
+
const updated = await updateSnapshot((s) => {
|
|
645
|
+
const idx = s.posts.findIndex((p) => p.id === req.params.id);
|
|
646
|
+
if (idx === -1) throw new HttpError(404, 'Article introuvable');
|
|
647
|
+
s.posts[idx] = { ...(rev.snapshot as BlogPost), updatedAt: new Date().toISOString() };
|
|
648
|
+
});
|
|
649
|
+
res.json(updated.posts.find((p) => p.id === req.params.id));
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
/* ---------- SEO ---------- */
|
|
653
|
+
|
|
654
|
+
router.get('/seo/overview', requireAuth(), async (_req, res) => {
|
|
655
|
+
const s = await loadSnapshot();
|
|
656
|
+
res.json([
|
|
657
|
+
...s.pages.map((p) => ({ kind: 'page' as const, id: p.id, title: p.title, url: p.path, status: p.status, seo: p.seo, analysis: analyzePageSeo(p) })),
|
|
658
|
+
...s.posts.map((p) => ({ kind: 'post' as const, id: p.id, title: p.title, url: `/blog/${p.slug}/`, status: p.status, seo: p.seo, analysis: analyzePostSeo(p) })),
|
|
659
|
+
]);
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
/* ---------- Formulaires ---------- */
|
|
663
|
+
|
|
664
|
+
router.get('/forms', requirePerm('forms.view', 'forms.manage'), async (req: AuthedRequest, res) => {
|
|
665
|
+
const s = await loadSnapshot();
|
|
666
|
+
res.json({ forms: s.forms, submissions: hasPerm(req, 'forms.view') ? s.formSubmissions : [] });
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
router.put('/forms/:id', requirePerm('forms.manage'), async (req, res) => {
|
|
670
|
+
const body = req.body as CmsSnapshot['forms'][number];
|
|
671
|
+
const names = new Set<string>();
|
|
672
|
+
for (const f of body.fields || []) {
|
|
673
|
+
if (!/^[a-zA-Z][a-zA-Z0-9_]*$/.test(f.name)) throw new HttpError(400, `Identifiant de champ invalide : « ${f.name} »`);
|
|
674
|
+
if (names.has(f.name)) throw new HttpError(400, `Champ en double : ${f.name}`);
|
|
675
|
+
names.add(f.name);
|
|
676
|
+
}
|
|
677
|
+
for (const e of body.recipientEmails || []) {
|
|
678
|
+
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)) throw new HttpError(400, `E-mail destinataire invalide : ${e}`);
|
|
679
|
+
}
|
|
680
|
+
await updateSnapshot((s) => {
|
|
681
|
+
const idx = s.forms.findIndex((f) => f.id === req.params.id);
|
|
682
|
+
if (idx === -1) throw new HttpError(404, 'Formulaire introuvable');
|
|
683
|
+
s.forms[idx] = {
|
|
684
|
+
...s.forms[idx],
|
|
685
|
+
...pick<CmsSnapshot['forms'][number]>(body, ['name', 'recipientEmails', 'successPath', 'fields', 'enabled']),
|
|
686
|
+
};
|
|
687
|
+
});
|
|
688
|
+
res.json({ ok: true });
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
router.patch('/submissions/:id', requirePerm('forms.view'), async (req, res) => {
|
|
692
|
+
res.locals.audit = false;
|
|
693
|
+
await updateSnapshot((s) => {
|
|
694
|
+
const sub = s.formSubmissions.find((x) => x.id === req.params.id);
|
|
695
|
+
if (!sub) throw new HttpError(404, 'Message introuvable');
|
|
696
|
+
if (typeof req.body.read === 'boolean') sub.read = req.body.read;
|
|
697
|
+
});
|
|
698
|
+
res.json({ ok: true });
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
router.delete('/submissions/:id', requirePerm('forms.manage'), async (req, res) => {
|
|
702
|
+
await updateSnapshot((s) => {
|
|
703
|
+
s.formSubmissions = s.formSubmissions.filter((x) => x.id !== req.params.id);
|
|
704
|
+
});
|
|
705
|
+
res.json({ ok: true });
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
/* ---------- Statistiques ---------- */
|
|
709
|
+
|
|
710
|
+
router.get('/analytics', requirePerm('analytics.view'), async (req, res) => {
|
|
711
|
+
const days = Math.min(Math.max(Number(req.query.days) || 30, 1), 365);
|
|
712
|
+
const s = await loadSnapshot();
|
|
713
|
+
res.json(await summarizeAnalytics(days, new URL(s.settings.publicUrl).hostname));
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
/* ---------- Médias ---------- */
|
|
717
|
+
|
|
718
|
+
router.get('/media', requireAuth(), async (_req, res) => {
|
|
719
|
+
res.json((await loadSnapshot()).media);
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
router.get('/media/limits', requireAuth(), async (_req, res) => {
|
|
723
|
+
const u = (await loadSnapshot()).system.uploads;
|
|
724
|
+
res.json({ ...u, label: allowedLabel(u) });
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
router.post('/media/upload', requirePerm('media.upload'), async (req, res) => {
|
|
728
|
+
const { filename, dataBase64, mimeType, alt } = req.body as { filename?: string; dataBase64?: string; mimeType?: string; alt?: string };
|
|
729
|
+
if (!filename || !dataBase64 || !mimeType) throw new HttpError(400, 'Fichier requis');
|
|
730
|
+
const limits = (await loadSnapshot()).system.uploads;
|
|
731
|
+
if (!allowedMime(limits, mimeType)) throw new HttpError(415, `Format non autorisé (formats acceptés : ${allowedLabel(limits)})`);
|
|
732
|
+
const buf = Buffer.from(dataBase64, 'base64');
|
|
733
|
+
if (buf.length > limits.maxSizeMb * 1024 * 1024) throw new HttpError(413, `Fichier trop lourd (${limits.maxSizeMb} Mo max)`);
|
|
734
|
+
const { UPLOADS_DIR } = getDataPaths();
|
|
735
|
+
await fs.mkdir(UPLOADS_DIR, { recursive: true });
|
|
736
|
+
const ext = path.extname(filename).toLowerCase().replace(/[^.a-z0-9]/g, '');
|
|
737
|
+
const base = slugify(path.basename(filename, path.extname(filename))).slice(0, 60) || 'fichier';
|
|
738
|
+
const safeName = `${base}-${crypto.randomBytes(4).toString('hex')}${ext}`;
|
|
739
|
+
await fs.writeFile(path.join(UPLOADS_DIR, safeName), buf);
|
|
740
|
+
const asset = {
|
|
741
|
+
id: crypto.randomUUID(),
|
|
742
|
+
filename: safeName,
|
|
743
|
+
url: `/uploads/${safeName}`,
|
|
744
|
+
mimeType,
|
|
745
|
+
sizeBytes: buf.length,
|
|
746
|
+
alt: alt || '',
|
|
747
|
+
createdAt: new Date().toISOString(),
|
|
748
|
+
};
|
|
749
|
+
await updateSnapshot((s) => {
|
|
750
|
+
s.media.unshift(asset);
|
|
751
|
+
});
|
|
752
|
+
res.locals.audit = { target: safeName };
|
|
753
|
+
res.status(201).json(asset);
|
|
754
|
+
});
|
|
755
|
+
|
|
756
|
+
router.patch('/media/:id', requirePerm('media.upload'), async (req, res) => {
|
|
757
|
+
await updateSnapshot((s) => {
|
|
758
|
+
const m = s.media.find((x) => x.id === req.params.id);
|
|
759
|
+
if (!m) throw new HttpError(404, 'Média introuvable');
|
|
760
|
+
if (typeof req.body.alt === 'string') m.alt = req.body.alt;
|
|
761
|
+
});
|
|
762
|
+
res.json({ ok: true });
|
|
763
|
+
});
|
|
764
|
+
|
|
765
|
+
router.delete('/media/:id', requirePerm('media.delete'), async (req, res) => {
|
|
766
|
+
const s = await loadSnapshot();
|
|
767
|
+
const asset = s.media.find((x) => x.id === req.params.id);
|
|
768
|
+
if (!asset) throw new HttpError(404, 'Média introuvable');
|
|
769
|
+
await updateSnapshot((snap) => {
|
|
770
|
+
snap.media = snap.media.filter((x) => x.id !== asset.id);
|
|
771
|
+
});
|
|
772
|
+
await fs.unlink(path.join(getDataPaths().UPLOADS_DIR, path.basename(asset.filename))).catch(() => undefined);
|
|
773
|
+
res.locals.audit = { target: asset.filename };
|
|
774
|
+
res.json({ ok: true });
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
/* ---------- Newsletter ---------- */
|
|
778
|
+
|
|
779
|
+
router.get('/subscribers', requirePerm('newsletter.manage'), async (_req, res) => {
|
|
780
|
+
res.json((await loadSnapshot()).subscribers.map(({ confirmToken, ...rest }) => rest));
|
|
781
|
+
});
|
|
782
|
+
|
|
783
|
+
router.patch('/subscribers/:id', requirePerm('newsletter.manage'), async (req, res) => {
|
|
784
|
+
const status = req.body.status;
|
|
785
|
+
if (!['pending', 'active', 'unsubscribed'].includes(status)) throw new HttpError(400, 'Statut invalide');
|
|
786
|
+
let email = '';
|
|
787
|
+
await updateSnapshot((s) => {
|
|
788
|
+
const sub = s.subscribers.find((x) => x.id === req.params.id);
|
|
789
|
+
if (!sub) throw new HttpError(404, 'Abonné introuvable');
|
|
790
|
+
sub.status = status;
|
|
791
|
+
email = sub.email;
|
|
792
|
+
});
|
|
793
|
+
res.locals.audit = { target: email, detail: { status } };
|
|
794
|
+
res.json({ ok: true });
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
router.delete('/subscribers/:id', requirePerm('newsletter.manage'), async (req, res) => {
|
|
798
|
+
let email = '';
|
|
799
|
+
await updateSnapshot((s) => {
|
|
800
|
+
email = s.subscribers.find((x) => x.id === req.params.id)?.email ?? '';
|
|
801
|
+
s.subscribers = s.subscribers.filter((x) => x.id !== req.params.id);
|
|
802
|
+
});
|
|
803
|
+
res.locals.audit = { target: email || req.params.id };
|
|
804
|
+
res.json({ ok: true });
|
|
805
|
+
});
|
|
806
|
+
|
|
807
|
+
return router;
|
|
808
|
+
}
|