create-snapify-app 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +33 -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 +100 -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,313 @@
|
|
|
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 { loadSnapshot, updateSnapshot } from '../cms/store';
|
|
9
|
+
import type { Request } from 'express';
|
|
10
|
+
import type { AnalyticsEvent, CmsSnapshot } from '../cms/types';
|
|
11
|
+
import { sendMail } from '../mail';
|
|
12
|
+
import { resolveGeoFromIp } from '../geoip';
|
|
13
|
+
import { appendAnalyticsEvent } from '../cms/analyticsStore';
|
|
14
|
+
import { asyncRouter, HttpError } from '../http';
|
|
15
|
+
import { publicModules, publicRecaptchaConfig, publicTheme, verifyRecaptchaToken } from '../modules/manager';
|
|
16
|
+
import { hit, rateLimitError } from '../security/rateLimit';
|
|
17
|
+
import { clientIp, ipMatches } from '../security/ip';
|
|
18
|
+
|
|
19
|
+
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
20
|
+
|
|
21
|
+
function escapeHtml(v: unknown): string {
|
|
22
|
+
return String(v ?? '')
|
|
23
|
+
.replace(/&/g, '&')
|
|
24
|
+
.replace(/</g, '<')
|
|
25
|
+
.replace(/>/g, '>')
|
|
26
|
+
.replace(/"/g, '"');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const PREVIEW_COOKIE = 'snapify_preview';
|
|
30
|
+
|
|
31
|
+
function readCookie(header: string | undefined, name: string): string | undefined {
|
|
32
|
+
const m = (header || '').split(/;\s*/).find((c) => c.startsWith(`${name}=`));
|
|
33
|
+
return m ? decodeURIComponent(m.slice(name.length + 1)) : undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Visiteur autorisé à voir le site pendant la maintenance (IP autorisée ou lien de prévisualisation). */
|
|
37
|
+
function bypassesMaintenance(req: Request, m: CmsSnapshot['settings']['maintenance']): boolean {
|
|
38
|
+
if ((m.allowedIps || []).some((rule) => ipMatches(clientIp(req), rule))) return true;
|
|
39
|
+
const cookie = readCookie(req.headers.cookie, PREVIEW_COOKIE);
|
|
40
|
+
return !!m.bypassSecret && !!cookie && cookie.length === m.bypassSecret.length && crypto.timingSafeEqual(Buffer.from(cookie), Buffer.from(m.bypassSecret));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface MaintenanceNotice {
|
|
44
|
+
title: string;
|
|
45
|
+
message: string;
|
|
46
|
+
logo: string;
|
|
47
|
+
siteName: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Page de maintenance à montrer à ce visiteur, ou `null` s'il doit voir le site. */
|
|
51
|
+
export async function maintenanceFor(req: Request): Promise<MaintenanceNotice | null> {
|
|
52
|
+
const s = await loadSnapshot();
|
|
53
|
+
const m = s.settings.maintenance;
|
|
54
|
+
if (!m.enabled || bypassesMaintenance(req, m)) return null;
|
|
55
|
+
return { title: m.title, message: m.message, logo: s.branding.logoDarkUrl || '', siteName: s.branding.siteName || '' };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Annonce la maintenance dès le HTML (statut 503 pour les robots) : la page s'affiche
|
|
60
|
+
* sans attendre l'API et sans dépendre d'une configuration mise en cache.
|
|
61
|
+
*/
|
|
62
|
+
export async function injectMaintenance(req: Request, html: string): Promise<{ html: string; notice: MaintenanceNotice | null }> {
|
|
63
|
+
const notice = await maintenanceFor(req).catch(() => null);
|
|
64
|
+
if (!notice) return { html, notice };
|
|
65
|
+
const json = JSON.stringify(notice).replace(/</g, '\\u003c');
|
|
66
|
+
return { html: html.replace('</head>', ` <script type="application/json" id="snapify-maintenance">${json}</script>\n </head>`), notice };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function createPublicCmsRouter() {
|
|
70
|
+
const router = asyncRouter();
|
|
71
|
+
|
|
72
|
+
router.get('/maintenance-preview', async (req, res) => {
|
|
73
|
+
const s = await loadSnapshot();
|
|
74
|
+
const key = String(req.query.key || '');
|
|
75
|
+
const secret = s.settings.maintenance.bypassSecret;
|
|
76
|
+
if (secret && key.length === secret.length && crypto.timingSafeEqual(Buffer.from(key), Buffer.from(secret))) {
|
|
77
|
+
res.cookie(PREVIEW_COOKIE, secret, { httpOnly: true, sameSite: 'lax', secure: req.secure, maxAge: 7 * 86400000, path: '/' });
|
|
78
|
+
}
|
|
79
|
+
res.redirect('/');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
router.get('/maintenance-status', async (req, res) => {
|
|
83
|
+
res.set('Cache-Control', 'no-store');
|
|
84
|
+
const notice = await maintenanceFor(req);
|
|
85
|
+
res.json(notice ? { enabled: true, ...notice } : { enabled: false });
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
router.get('/site-config', async (req, res) => {
|
|
89
|
+
const s = await loadSnapshot();
|
|
90
|
+
const m = s.settings.maintenance;
|
|
91
|
+
const maintenanceOn = m.enabled && !bypassesMaintenance(req, m);
|
|
92
|
+
res.set('Cache-Control', m.enabled ? 'private, no-store' : `public, max-age=${s.system.performance.publicCacheSeconds}`);
|
|
93
|
+
res.json({
|
|
94
|
+
general: s.general,
|
|
95
|
+
branding: s.branding,
|
|
96
|
+
menus: s.menus,
|
|
97
|
+
widgetAreas: s.widgetAreas,
|
|
98
|
+
floatingButtons: s.floatingButtons.filter((b) => b.enabled),
|
|
99
|
+
modules: await publicModules(),
|
|
100
|
+
theme: await publicTheme(),
|
|
101
|
+
settings: {
|
|
102
|
+
publicUrl: s.settings.publicUrl,
|
|
103
|
+
maintenance: { enabled: maintenanceOn, title: m.title, message: m.message },
|
|
104
|
+
cookieBannerEnabled: s.settings.cookieBannerEnabled,
|
|
105
|
+
analyticsEnabled: s.settings.analyticsEnabled,
|
|
106
|
+
seo: {
|
|
107
|
+
titleSeparator: s.settings.seo.titleSeparator,
|
|
108
|
+
titleSuffix: s.settings.seo.titleSuffix,
|
|
109
|
+
defaultOgImage: s.settings.seo.defaultOgImage,
|
|
110
|
+
googleVerification: s.settings.seo.googleVerification,
|
|
111
|
+
bingVerification: s.settings.seo.bingVerification,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
redirects: s.redirects,
|
|
115
|
+
newsletterEnabled: s.newsletter.enabled,
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
router.get('/pages/by-path', async (req, res) => {
|
|
120
|
+
const raw = String(req.query.path || '/');
|
|
121
|
+
const normalized = raw.endsWith('/') ? raw : `${raw}/`;
|
|
122
|
+
const s = await loadSnapshot();
|
|
123
|
+
const page = s.pages.find((p) => p.path === normalized && p.status === 'published');
|
|
124
|
+
if (!page) throw new HttpError(404, 'Page non trouvée');
|
|
125
|
+
res.json(page);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
/** Fiches des réalisations publiées (pages au modèle « project »). */
|
|
129
|
+
router.get('/projects', async (_req, res) => {
|
|
130
|
+
const s = await loadSnapshot();
|
|
131
|
+
res.set('Cache-Control', `public, max-age=${s.system.performance.publicCacheSeconds}`);
|
|
132
|
+
res.json(
|
|
133
|
+
s.pages
|
|
134
|
+
.filter((p) => p.template === 'project' && p.status === 'published' && p.project)
|
|
135
|
+
.map((p) => ({ id: p.id, path: p.path, title: p.title, ...p.project! }))
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
router.get('/posts', async (_req, res) => {
|
|
140
|
+
const s = await loadSnapshot();
|
|
141
|
+
res.json(
|
|
142
|
+
s.posts
|
|
143
|
+
.filter((p) => p.status === 'published')
|
|
144
|
+
.map(({ blocks, ...meta }) => meta)
|
|
145
|
+
);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
router.get('/posts/:slug', async (req, res) => {
|
|
149
|
+
const s = await loadSnapshot();
|
|
150
|
+
const post = s.posts.find((p) => p.slug === req.params.slug && p.status === 'published');
|
|
151
|
+
if (!post) throw new HttpError(404, 'Article non trouvé');
|
|
152
|
+
res.json(post);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
router.get('/forms/:id', async (req, res) => {
|
|
156
|
+
const s = await loadSnapshot();
|
|
157
|
+
const form = s.forms.find((f) => f.id === req.params.id && f.enabled);
|
|
158
|
+
if (!form) throw new HttpError(404, 'Formulaire introuvable');
|
|
159
|
+
const { recipientEmails, ...publicForm } = form;
|
|
160
|
+
const recaptcha = publicRecaptchaConfig();
|
|
161
|
+
res.json(recaptcha ? { ...publicForm, recaptcha } : publicForm);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
router.post('/forms/:id/submit', async (req, res) => {
|
|
165
|
+
const s = await loadSnapshot();
|
|
166
|
+
const form = s.forms.find((f) => f.id === req.params.id && f.enabled);
|
|
167
|
+
if (!form) throw new HttpError(404, 'Formulaire introuvable');
|
|
168
|
+
|
|
169
|
+
const body = (req.body || {}) as Record<string, unknown>;
|
|
170
|
+
if (form.honeypotField && body[form.honeypotField]) return res.json({ ok: true, redirect: form.successPath });
|
|
171
|
+
const quota = s.system.limits.formSubmissions;
|
|
172
|
+
const allowed = hit(`form:${clientIp(req)}`, quota.max, quota.windowMinutes * 60_000);
|
|
173
|
+
if (!allowed.ok) throw rateLimitError(res, allowed, 'Trop de demandes envoyées');
|
|
174
|
+
|
|
175
|
+
if (publicRecaptchaConfig()) {
|
|
176
|
+
const token = typeof body['g-recaptcha-response'] === 'string' ? body['g-recaptcha-response'] : typeof body.recaptchaToken === 'string' ? body.recaptchaToken : '';
|
|
177
|
+
const check = await verifyRecaptchaToken(token, clientIp(req));
|
|
178
|
+
if (!check.ok) throw new HttpError(400, check.error);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const payload: Record<string, unknown> = {};
|
|
182
|
+
const errors: Record<string, string> = {};
|
|
183
|
+
for (const field of form.fields) {
|
|
184
|
+
const v = body[field.name];
|
|
185
|
+
const empty = v === undefined || v === null || v === '' || v === false;
|
|
186
|
+
if (field.required && empty) errors[field.name] = `${field.label} est requis`;
|
|
187
|
+
else if (!empty && field.type === 'email' && !EMAIL_RE.test(String(v))) errors[field.name] = 'E-mail invalide';
|
|
188
|
+
if (!empty) payload[field.name] = typeof v === 'string' ? v.slice(0, 5000) : v;
|
|
189
|
+
}
|
|
190
|
+
// Champs historiques du formulaire React non déclarés dans le CMS : conservés mais bornés.
|
|
191
|
+
for (const [k, v] of Object.entries(body)) {
|
|
192
|
+
if (k !== form.honeypotField && !(k in payload) && typeof v === 'string' && Object.keys(payload).length < 40) {
|
|
193
|
+
payload[k] = v.slice(0, 2000);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (Object.keys(errors).length) return res.status(422).json({ error: 'Formulaire incomplet', fields: errors });
|
|
197
|
+
|
|
198
|
+
await updateSnapshot((snap) => {
|
|
199
|
+
snap.formSubmissions.unshift({
|
|
200
|
+
id: crypto.randomUUID(),
|
|
201
|
+
formId: form.id,
|
|
202
|
+
payload,
|
|
203
|
+
ip: s.system.privacy.storeSubmitterIp ? clientIp(req) : undefined,
|
|
204
|
+
userAgent: s.system.privacy.storeSubmitterIp ? String(req.headers['user-agent'] || '').slice(0, 300) : undefined,
|
|
205
|
+
createdAt: new Date().toISOString(),
|
|
206
|
+
read: false,
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
const rows = Object.entries(payload)
|
|
211
|
+
.map(([k, v]) => {
|
|
212
|
+
const label = form.fields.find((f) => f.name === k)?.label || k;
|
|
213
|
+
return `<tr><td style="padding:6px 12px;color:#64748b">${escapeHtml(label)}</td><td style="padding:6px 12px">${escapeHtml(v)}</td></tr>`;
|
|
214
|
+
})
|
|
215
|
+
.join('');
|
|
216
|
+
sendMail({
|
|
217
|
+
to: form.recipientEmails,
|
|
218
|
+
subject: `[${s.branding.siteName}] ${form.name}`,
|
|
219
|
+
html: `<h2 style="font-family:sans-serif">${escapeHtml(form.name)}</h2><table style="font-family:sans-serif;font-size:14px">${rows}</table>`,
|
|
220
|
+
kind: 'form',
|
|
221
|
+
replyTo: typeof payload.email === 'string' && EMAIL_RE.test(payload.email) ? payload.email : undefined,
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
res.json({ ok: true, redirect: form.successPath });
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
router.post('/newsletter/subscribe', async (req, res) => {
|
|
228
|
+
const email = String(req.body?.email || '').trim().toLowerCase();
|
|
229
|
+
if (!EMAIL_RE.test(email)) throw new HttpError(400, 'E-mail invalide');
|
|
230
|
+
const s = await loadSnapshot();
|
|
231
|
+
if (!s.newsletter.enabled) throw new HttpError(403, 'Newsletter désactivée');
|
|
232
|
+
const quota = s.system.limits.newsletter;
|
|
233
|
+
const allowed = hit(`newsletter:${clientIp(req)}`, quota.max, quota.windowMinutes * 60_000);
|
|
234
|
+
if (!allowed.ok) throw rateLimitError(res, allowed, 'Trop de tentatives');
|
|
235
|
+
|
|
236
|
+
const existing = s.subscribers.find((x) => x.email === email);
|
|
237
|
+
if (existing?.status === 'active') return res.json({ ok: true, pending: false });
|
|
238
|
+
|
|
239
|
+
const token = crypto.randomBytes(24).toString('hex');
|
|
240
|
+
await updateSnapshot((snap) => {
|
|
241
|
+
const sub = snap.subscribers.find((x) => x.email === email);
|
|
242
|
+
const status = snap.newsletter.doubleOptIn ? 'pending' : 'active';
|
|
243
|
+
if (sub) {
|
|
244
|
+
sub.status = status;
|
|
245
|
+
sub.confirmToken = snap.newsletter.doubleOptIn ? token : undefined;
|
|
246
|
+
} else {
|
|
247
|
+
snap.subscribers.unshift({
|
|
248
|
+
id: crypto.randomUUID(),
|
|
249
|
+
email,
|
|
250
|
+
status,
|
|
251
|
+
confirmToken: snap.newsletter.doubleOptIn ? token : undefined,
|
|
252
|
+
source: 'website',
|
|
253
|
+
createdAt: new Date().toISOString(),
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
if (s.newsletter.doubleOptIn) {
|
|
259
|
+
const base = s.settings.publicUrl.replace(/\/$/, '');
|
|
260
|
+
await sendMail({
|
|
261
|
+
to: email,
|
|
262
|
+
subject: s.newsletter.welcomeEmailSubject || `Confirmez votre inscription — ${s.branding.siteName}`,
|
|
263
|
+
html: `<p style="font-family:sans-serif">Merci pour votre inscription. Confirmez votre adresse :</p><p><a href="${base}/api/public/newsletter/confirm?token=${token}">Confirmer mon e-mail</a></p>`,
|
|
264
|
+
kind: 'newsletter',
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
res.json({ ok: true, pending: s.newsletter.doubleOptIn });
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
router.get('/newsletter/confirm', async (req, res) => {
|
|
271
|
+
const token = String(req.query.token || '');
|
|
272
|
+
const s = await loadSnapshot();
|
|
273
|
+
const sub = token ? s.subscribers.find((x) => x.confirmToken === token) : undefined;
|
|
274
|
+
const page = (title: string, text: string) =>
|
|
275
|
+
`<!doctype html><html lang="fr"><meta charset="utf-8"><meta name="viewport" content="width=device-width"><body style="font-family:system-ui;display:grid;place-items:center;min-height:100vh;margin:0;background:#F5F7FA;color:#0B1528"><div style="text-align:center;max-width:420px;padding:2rem"><h1>${title}</h1><p>${text}</p><a href="/" style="color:#00A89D">Retour au site</a></div></body></html>`;
|
|
276
|
+
if (!sub) return res.status(404).send(page('Lien invalide', 'Ce lien de confirmation est expiré ou a déjà été utilisé.'));
|
|
277
|
+
await updateSnapshot((snap) => {
|
|
278
|
+
const t = snap.subscribers.find((x) => x.id === sub.id);
|
|
279
|
+
if (t) {
|
|
280
|
+
t.status = 'active';
|
|
281
|
+
t.confirmedAt = new Date().toISOString();
|
|
282
|
+
t.confirmToken = undefined;
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
res.send(page('Inscription confirmée', 'Merci, vous recevrez désormais notre newsletter.'));
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
router.post('/analytics/event', async (req, res) => {
|
|
289
|
+
res.status(204).end();
|
|
290
|
+
const s = await loadSnapshot();
|
|
291
|
+
if (!s.settings.analyticsEnabled) return;
|
|
292
|
+
const body = (req.body || {}) as Partial<AnalyticsEvent>;
|
|
293
|
+
const p = String(body.path || '/').slice(0, 300);
|
|
294
|
+
if (p.startsWith('/administrator') || /bot|crawler|spider|headless/i.test(String(req.headers['user-agent']))) return;
|
|
295
|
+
|
|
296
|
+
const geo = resolveGeoFromIp(req.ip || '');
|
|
297
|
+
const kind = body.kind === 'leave' ? 'leave' : 'view';
|
|
298
|
+
await appendAnalyticsEvent({
|
|
299
|
+
id: crypto.randomUUID(),
|
|
300
|
+
kind,
|
|
301
|
+
sessionId: String(body.sessionId || '').slice(0, 64) || crypto.randomUUID(),
|
|
302
|
+
path: p,
|
|
303
|
+
referrer: body.referrer ? String(body.referrer).slice(0, 300) : undefined,
|
|
304
|
+
country: (req.headers['cf-ipcountry'] as string) || geo.country,
|
|
305
|
+
city: geo.city,
|
|
306
|
+
device: ['mobile', 'tablet', 'desktop'].includes(String(body.device)) ? body.device! : 'unknown',
|
|
307
|
+
durationSec: kind === 'leave' ? Math.max(0, Math.min(Number(body.durationSec) || 0, 7200)) : undefined,
|
|
308
|
+
ts: new Date().toISOString(),
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
return router;
|
|
313
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
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 type { Request, Response, NextFunction } from 'express';
|
|
8
|
+
import { loadSnapshot } from '../cms/store';
|
|
9
|
+
import { asyncRouter } from '../http';
|
|
10
|
+
import type { CmsSnapshot, SeoMeta } from '../cms/types';
|
|
11
|
+
|
|
12
|
+
const xmlEscape = (v: string) => v.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
13
|
+
const attr = (v: string) => v.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<');
|
|
14
|
+
|
|
15
|
+
export function createSeoPublicRouter() {
|
|
16
|
+
const router = asyncRouter();
|
|
17
|
+
|
|
18
|
+
router.get('/sitemap.xml', async (_req, res) => {
|
|
19
|
+
const s = await loadSnapshot();
|
|
20
|
+
const base = s.settings.publicUrl.replace(/\/$/, '');
|
|
21
|
+
const entries: { loc: string; lastmod: string; priority: string }[] = [];
|
|
22
|
+
for (const page of s.pages) {
|
|
23
|
+
if (page.status !== 'published' || page.seo.noindex) continue;
|
|
24
|
+
entries.push({ loc: `${base}${page.path}`, lastmod: page.updatedAt.slice(0, 10), priority: page.path === '/' ? '1.0' : '0.8' });
|
|
25
|
+
}
|
|
26
|
+
for (const post of s.posts) {
|
|
27
|
+
if (post.status !== 'published' || post.seo.noindex) continue;
|
|
28
|
+
entries.push({ loc: `${base}/blog/${post.slug}/`, lastmod: post.updatedAt.slice(0, 10), priority: '0.6' });
|
|
29
|
+
}
|
|
30
|
+
res.type('application/xml').send(
|
|
31
|
+
`<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${entries
|
|
32
|
+
.map((e) => ` <url><loc>${xmlEscape(e.loc)}</loc><lastmod>${e.lastmod}</lastmod><priority>${e.priority}</priority></url>`)
|
|
33
|
+
.join('\n')}\n</urlset>`
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
router.get('/robots.txt', async (_req, res) => {
|
|
38
|
+
const s = await loadSnapshot();
|
|
39
|
+
const base = s.settings.publicUrl.replace(/\/$/, '');
|
|
40
|
+
const lines = [
|
|
41
|
+
'User-agent: *',
|
|
42
|
+
s.settings.maintenance.enabled ? 'Disallow: /' : 'Allow: /',
|
|
43
|
+
'Disallow: /administrator',
|
|
44
|
+
'Disallow: /api/',
|
|
45
|
+
s.settings.robotsTxtExtra?.trim() || '',
|
|
46
|
+
s.settings.sitemapAuto ? `\nSitemap: ${base}/sitemap.xml` : '',
|
|
47
|
+
].filter(Boolean);
|
|
48
|
+
res.type('text/plain').send(lines.join('\n'));
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return router;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Redirections 301/302 réelles pour les robots et liens externes. */
|
|
55
|
+
export async function redirectMiddleware(req: Request, res: Response, next: NextFunction) {
|
|
56
|
+
if (req.method !== 'GET' || req.path.startsWith('/api/') || req.path.startsWith('/assets/')) return next();
|
|
57
|
+
try {
|
|
58
|
+
const s = await loadSnapshot();
|
|
59
|
+
const p = req.path.endsWith('/') ? req.path : `${req.path}/`;
|
|
60
|
+
const rule = s.redirects.find((r) => r.from === p);
|
|
61
|
+
if (rule) return res.redirect(rule.permanent ? 301 : 302, rule.to);
|
|
62
|
+
} catch {
|
|
63
|
+
/* les redirections ne doivent jamais bloquer le site */
|
|
64
|
+
}
|
|
65
|
+
next();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface ResolvedMeta {
|
|
69
|
+
title: string;
|
|
70
|
+
description: string;
|
|
71
|
+
canonical: string;
|
|
72
|
+
robots: string;
|
|
73
|
+
ogImage?: string;
|
|
74
|
+
ogType: string;
|
|
75
|
+
seo?: SeoMeta;
|
|
76
|
+
jsonLd: object[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function resolveMeta(s: CmsSnapshot, reqPath: string): ResolvedMeta {
|
|
80
|
+
const base = s.settings.publicUrl.replace(/\/$/, '');
|
|
81
|
+
const p = reqPath.endsWith('/') ? reqPath : `${reqPath}/`;
|
|
82
|
+
const g = s.settings.seo;
|
|
83
|
+
const suffix = g.titleSuffix ? ` ${g.titleSeparator} ${g.titleSuffix}` : '';
|
|
84
|
+
const org = {
|
|
85
|
+
'@context': 'https://schema.org',
|
|
86
|
+
'@type': 'Organization',
|
|
87
|
+
name: g.organizationName || s.general.legalName,
|
|
88
|
+
url: base,
|
|
89
|
+
logo: g.organizationLogo ? `${base}${g.organizationLogo}` : undefined,
|
|
90
|
+
telephone: s.general.phoneClean,
|
|
91
|
+
email: s.general.contactEmail,
|
|
92
|
+
sameAs: g.socialProfiles?.length ? g.socialProfiles : undefined,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const blogSlug = p.startsWith('/blog/') ? p.split('/')[2] : undefined;
|
|
96
|
+
const post = blogSlug ? s.posts.find((x) => x.slug === blogSlug && x.status === 'published') : undefined;
|
|
97
|
+
const page = post ? undefined : s.pages.find((x) => x.path === p && x.status === 'published');
|
|
98
|
+
const seo = post?.seo || page?.seo;
|
|
99
|
+
const title = seo?.seoTitle || (post?.title || page?.title ? `${post?.title || page?.title}${suffix}` : `${s.branding.siteName}${suffix}`);
|
|
100
|
+
const jsonLd: object[] = [org];
|
|
101
|
+
if (post) {
|
|
102
|
+
jsonLd.push({
|
|
103
|
+
'@context': 'https://schema.org',
|
|
104
|
+
'@type': 'Article',
|
|
105
|
+
headline: post.title,
|
|
106
|
+
description: post.seo.metaDescription || post.excerpt,
|
|
107
|
+
image: post.coverImage ? `${base}${post.coverImage}` : undefined,
|
|
108
|
+
datePublished: post.publishedAt,
|
|
109
|
+
dateModified: post.updatedAt,
|
|
110
|
+
author: { '@type': 'Person', name: post.author || g.organizationName },
|
|
111
|
+
publisher: { '@type': 'Organization', name: g.organizationName },
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const img = seo?.ogImage || post?.coverImage || g.defaultOgImage;
|
|
115
|
+
return {
|
|
116
|
+
title,
|
|
117
|
+
description: seo?.metaDescription || post?.excerpt || '',
|
|
118
|
+
canonical: seo?.canonicalUrl || `${base}${p}`,
|
|
119
|
+
robots: `${seo?.noindex || s.settings.maintenance.enabled ? 'noindex' : 'index'},${seo?.nofollow ? 'nofollow' : 'follow'}`,
|
|
120
|
+
ogImage: img ? (img.startsWith('http') ? img : `${base}${img}`) : undefined,
|
|
121
|
+
ogType: post ? 'article' : 'website',
|
|
122
|
+
seo,
|
|
123
|
+
jsonLd,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Injecte les balises SEO de la page dans le HTML de la SPA (lisible par Google sans exécuter le JS). */
|
|
128
|
+
export async function injectSeo(html: string, reqPath: string): Promise<string> {
|
|
129
|
+
try {
|
|
130
|
+
const s = await loadSnapshot();
|
|
131
|
+
const m = resolveMeta(s, reqPath);
|
|
132
|
+
const tags = [
|
|
133
|
+
`<title>${attr(m.title)}</title>`,
|
|
134
|
+
m.description ? `<meta name="description" content="${attr(m.description)}" />` : '',
|
|
135
|
+
`<link rel="canonical" href="${attr(m.canonical)}" />`,
|
|
136
|
+
`<meta name="robots" content="${m.robots}" />`,
|
|
137
|
+
`<meta property="og:title" content="${attr(m.seo?.ogTitle || m.title)}" />`,
|
|
138
|
+
m.description ? `<meta property="og:description" content="${attr(m.seo?.ogDescription || m.description)}" />` : '',
|
|
139
|
+
`<meta property="og:type" content="${m.ogType}" />`,
|
|
140
|
+
`<meta property="og:url" content="${attr(m.canonical)}" />`,
|
|
141
|
+
`<meta property="og:site_name" content="${attr(s.branding.siteName)}" />`,
|
|
142
|
+
m.ogImage ? `<meta property="og:image" content="${attr(m.ogImage)}" />` : '',
|
|
143
|
+
`<meta name="twitter:card" content="${m.seo?.twitterCard || 'summary_large_image'}" />`,
|
|
144
|
+
s.settings.seo.googleVerification ? `<meta name="google-site-verification" content="${attr(s.settings.seo.googleVerification)}" />` : '',
|
|
145
|
+
s.settings.seo.bingVerification ? `<meta name="msvalidate.01" content="${attr(s.settings.seo.bingVerification)}" />` : '',
|
|
146
|
+
...m.jsonLd.map((j) => `<script type="application/ld+json">${JSON.stringify(j).replace(/</g, '\\u003c')}</script>`),
|
|
147
|
+
]
|
|
148
|
+
.filter(Boolean)
|
|
149
|
+
.join('\n ');
|
|
150
|
+
|
|
151
|
+
return html
|
|
152
|
+
.replace(/<title>[\s\S]*?<\/title>/, '')
|
|
153
|
+
.replace(/<meta\s+(name|property)="(description|og:[^"]+|twitter:[^"]+)"[^>]*>\s*/g, '')
|
|
154
|
+
.replace('</head>', ` ${tags}\n </head>`);
|
|
155
|
+
} catch {
|
|
156
|
+
return html;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
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 type { Request } from 'express';
|
|
8
|
+
import { createToken } from '../cms/auth';
|
|
9
|
+
import { updateSnapshot } from '../cms/store';
|
|
10
|
+
import type { AdminUser, CmsSnapshot } from '../cms/types';
|
|
11
|
+
import { SUPERADMIN_ROLE } from '../cms/permissions';
|
|
12
|
+
import { pendingRequirements, permissionsOf } from '../middleware/adminAuth';
|
|
13
|
+
import { renderEmail, sendMail } from '../mail';
|
|
14
|
+
import { clientIp, describeUserAgent } from './ip';
|
|
15
|
+
import { createSession, hasUsedIp, sessionTtlMs } from './sessions';
|
|
16
|
+
|
|
17
|
+
export const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
18
|
+
|
|
19
|
+
export function publicUser(u: AdminUser) {
|
|
20
|
+
return {
|
|
21
|
+
id: u.id,
|
|
22
|
+
email: u.email,
|
|
23
|
+
name: u.name,
|
|
24
|
+
role: u.role,
|
|
25
|
+
status: u.status ?? 'active',
|
|
26
|
+
title: u.title,
|
|
27
|
+
phone: u.phone,
|
|
28
|
+
avatarUrl: u.avatarUrl,
|
|
29
|
+
totpEnabled: !!u.totpEnabled,
|
|
30
|
+
mustChangePassword: !!u.mustChangePassword,
|
|
31
|
+
passwordChangedAt: u.passwordChangedAt,
|
|
32
|
+
lastLoginAt: u.lastLoginAt,
|
|
33
|
+
lastLoginIp: u.lastLoginIp,
|
|
34
|
+
loginCount: u.loginCount ?? 0,
|
|
35
|
+
invitedBy: u.invitedBy,
|
|
36
|
+
createdAt: u.createdAt,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function meView(s: CmsSnapshot, u: AdminUser) {
|
|
41
|
+
const role = s.roles.find((r) => r.id === u.role);
|
|
42
|
+
const pending = pendingRequirements(s, u);
|
|
43
|
+
const policy = s.system.security;
|
|
44
|
+
return {
|
|
45
|
+
...publicUser(u),
|
|
46
|
+
roleName: role?.name ?? u.role,
|
|
47
|
+
isSuper: u.role === SUPERADMIN_ROLE,
|
|
48
|
+
permissions: permissionsOf(s, u),
|
|
49
|
+
recoveryCodesLeft: u.recoveryCodes?.length ?? 0,
|
|
50
|
+
mustChangePassword: pending.mustChangePassword,
|
|
51
|
+
mustSetup2fa: pending.mustSetup2fa,
|
|
52
|
+
twoFactorRequired: pending.twoFactorRequired,
|
|
53
|
+
policy: {
|
|
54
|
+
passwordMinLength: policy.passwordMinLength,
|
|
55
|
+
requireUppercase: policy.requireUppercase,
|
|
56
|
+
requireNumber: policy.requireNumber,
|
|
57
|
+
requireSymbol: policy.requireSymbol,
|
|
58
|
+
idleMinutes: policy.idleMinutes,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const superadminCount = (s: CmsSnapshot) => s.users.filter((u) => u.role === SUPERADMIN_ROLE && u.status !== 'suspended').length;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Adresse de l'administration pour les liens envoyés par e-mail. L'en-tête Host n'est repris que s'il correspond
|
|
67
|
+
* à l'URL publique ou à un poste local, pour empêcher l'empoisonnement des liens de réinitialisation.
|
|
68
|
+
*/
|
|
69
|
+
export function adminUrl(req: Request, s: CmsSnapshot, path: string): string {
|
|
70
|
+
const configured = process.env.SNAPIFY_ADMIN_URL?.replace(/\/$/, '');
|
|
71
|
+
if (configured) return `${configured}${path}`;
|
|
72
|
+
const publicUrl = new URL(s.settings.publicUrl);
|
|
73
|
+
const host = String(req.headers.host || '');
|
|
74
|
+
const hostname = host.replace(/:\d+$/, '');
|
|
75
|
+
const trusted = hostname === publicUrl.hostname || hostname === 'localhost' || hostname === '127.0.0.1';
|
|
76
|
+
const origin = trusted ? `${req.protocol}://${host}` : publicUrl.origin;
|
|
77
|
+
return `${origin}/administrator${path}`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Ouvre une session, met à jour les compteurs de connexion et prévient en cas de nouvelle adresse IP. */
|
|
81
|
+
export async function startSession(req: Request, s: CmsSnapshot, user: AdminUser, remember: boolean) {
|
|
82
|
+
const ip = clientIp(req);
|
|
83
|
+
const userAgent = String(req.headers['user-agent'] || '');
|
|
84
|
+
const knownIp = user.loginCount ? await hasUsedIp(user.id, ip) : true;
|
|
85
|
+
const session = await createSession({ userId: user.id, ip, userAgent, remember, ttlMs: sessionTtlMs(s.system.security, remember) });
|
|
86
|
+
const updated = await updateSnapshot((snap) => {
|
|
87
|
+
const u = snap.users.find((x) => x.id === user.id);
|
|
88
|
+
if (!u) return;
|
|
89
|
+
u.lastLoginAt = new Date().toISOString();
|
|
90
|
+
u.lastLoginIp = ip;
|
|
91
|
+
u.loginCount = (u.loginCount ?? 0) + 1;
|
|
92
|
+
});
|
|
93
|
+
const fresh = updated.users.find((u) => u.id === user.id)!;
|
|
94
|
+
if (!knownIp) {
|
|
95
|
+
void sendSecurityAlert(s, fresh, 'Nouvelle connexion à votre compte', [
|
|
96
|
+
`Appareil : ${describeUserAgent(userAgent)}`,
|
|
97
|
+
`Adresse IP : ${ip}`,
|
|
98
|
+
`Date : ${new Date().toLocaleString('fr-FR', { timeZone: s.general.timezone || 'Europe/Paris' })}`,
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
return { token: createToken(fresh, session.id, session.expiresAt), user: meView(updated, fresh), expiresAt: session.expiresAt.toISOString() };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export async function sendSecurityAlert(s: CmsSnapshot, user: AdminUser, title: string, lines: string[]) {
|
|
105
|
+
if (!s.system.notifications.securityAlerts) return;
|
|
106
|
+
const { html, text } = renderEmail(s, {
|
|
107
|
+
title,
|
|
108
|
+
intro: `Bonjour ${user.name}, une opération de sécurité vient d’avoir lieu sur votre compte ${s.branding.siteName}.`,
|
|
109
|
+
lines,
|
|
110
|
+
outro: 'Si vous n’êtes pas à l’origine de cette action, changez immédiatement votre mot de passe et prévenez un administrateur.',
|
|
111
|
+
});
|
|
112
|
+
await sendMail({ to: user.email, subject: `${title} — ${s.branding.siteName}`, html, text, kind: 'security' });
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Prévient les adresses de notification lors des créations / suppressions de comptes. */
|
|
116
|
+
export async function notifyAccountChange(s: CmsSnapshot, title: string, lines: string[]) {
|
|
117
|
+
const to = s.system.notifications.adminEmails;
|
|
118
|
+
if (!s.system.notifications.accountChanges || !to.length) return;
|
|
119
|
+
const { html, text } = renderEmail(s, { title, intro: `Modification des accès à l’administration de ${s.branding.siteName}.`, lines });
|
|
120
|
+
await sendMail({ to, subject: `${title} — ${s.branding.siteName}`, html, text, kind: 'notification' });
|
|
121
|
+
}
|