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,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Snapify — API espace client
|
|
3
|
+
* © 2026 NOVALABS WEB DESIGN — Tunisie
|
|
4
|
+
*/
|
|
5
|
+
import crypto from 'crypto';
|
|
6
|
+
import type { Request } from 'express';
|
|
7
|
+
import { and, desc, eq, inArray, or } from 'drizzle-orm';
|
|
8
|
+
import { asyncRouter, HttpError } from '../http';
|
|
9
|
+
import { db } from '../db/client';
|
|
10
|
+
import { clientProfiles, platformUsers, saInvoices, saPaymentEvents, saTickets } from '../db/schema';
|
|
11
|
+
import { requirePlatformUser, toPublicUser } from '../platform/auth';
|
|
12
|
+
import { formatMoney } from '../platform/money';
|
|
13
|
+
import { getClientByEmail, getClientByUserId, linkClientProfileToUser, updateClientProfile } from '../platform/clients';
|
|
14
|
+
import { listLicenseOrders } from '../platform/licenseOrders';
|
|
15
|
+
import { clientIp } from '../security/ip';
|
|
16
|
+
import { resolveGeoFromIp } from '../geoip';
|
|
17
|
+
|
|
18
|
+
function escapeHtml(s: string) {
|
|
19
|
+
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function requireClient(req: Request) {
|
|
23
|
+
const user = req.platformUser!;
|
|
24
|
+
let profile = await getClientByUserId(user.id);
|
|
25
|
+
if (!profile) {
|
|
26
|
+
const byEmail = await getClientByEmail(user.email);
|
|
27
|
+
if (byEmail) {
|
|
28
|
+
profile = (await linkClientProfileToUser(user.email, user.id)) || byEmail;
|
|
29
|
+
} else {
|
|
30
|
+
const [created] = await db
|
|
31
|
+
.insert(clientProfiles)
|
|
32
|
+
.values({
|
|
33
|
+
id: crypto.randomUUID(),
|
|
34
|
+
platformUserId: user.id,
|
|
35
|
+
email: user.email,
|
|
36
|
+
name: user.displayName,
|
|
37
|
+
status: 'lead',
|
|
38
|
+
})
|
|
39
|
+
.returning();
|
|
40
|
+
profile = created;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (!profile) throw new HttpError(404, 'Fiche client introuvable.');
|
|
44
|
+
return { user, profile };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function createClientPortalRouter() {
|
|
48
|
+
const r = asyncRouter();
|
|
49
|
+
|
|
50
|
+
r.get('/me', requirePlatformUser, async (req, res) => {
|
|
51
|
+
const { user, profile } = await requireClient(req);
|
|
52
|
+
const country = resolveGeoFromIp(clientIp(req)).country || profile.country;
|
|
53
|
+
res.json({
|
|
54
|
+
user: toPublicUser(user),
|
|
55
|
+
profile: {
|
|
56
|
+
...profile,
|
|
57
|
+
currency: profile.market === 'tn' ? 'TND' : 'EUR',
|
|
58
|
+
},
|
|
59
|
+
country,
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
r.patch('/profile', requirePlatformUser, async (req, res) => {
|
|
64
|
+
const { user, profile } = await requireClient(req);
|
|
65
|
+
const b = req.body || {};
|
|
66
|
+
const patch: Record<string, string> = {};
|
|
67
|
+
if (typeof b.name === 'string' && b.name.trim().length >= 2) patch.name = b.name.trim().slice(0, 120);
|
|
68
|
+
if (typeof b.phone === 'string') patch.phone = b.phone.trim().slice(0, 40);
|
|
69
|
+
if (typeof b.company === 'string') patch.company = b.company.trim().slice(0, 120);
|
|
70
|
+
if (typeof b.domain === 'string') {
|
|
71
|
+
patch.domain = b.domain
|
|
72
|
+
.trim()
|
|
73
|
+
.toLowerCase()
|
|
74
|
+
.replace(/^https?:\/\//, '')
|
|
75
|
+
.replace(/\/.*$/, '')
|
|
76
|
+
.slice(0, 120);
|
|
77
|
+
}
|
|
78
|
+
const updated = await updateClientProfile(profile.id, patch);
|
|
79
|
+
if (typeof b.displayName === 'string' && b.displayName.trim().length >= 2) {
|
|
80
|
+
await db
|
|
81
|
+
.update(platformUsers)
|
|
82
|
+
.set({ displayName: b.displayName.trim().slice(0, 80), updatedAt: new Date() })
|
|
83
|
+
.where(eq(platformUsers.id, user.id));
|
|
84
|
+
}
|
|
85
|
+
const [freshUser] = await db.select().from(platformUsers).where(eq(platformUsers.id, user.id)).limit(1);
|
|
86
|
+
res.json({ profile: updated, user: freshUser ? toPublicUser(freshUser) : toPublicUser(user) });
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
r.get('/requests', requirePlatformUser, async (req, res) => {
|
|
90
|
+
const { profile } = await requireClient(req);
|
|
91
|
+
const country = profile.market === 'fr' ? 'FR' : 'TN';
|
|
92
|
+
const all = await listLicenseOrders();
|
|
93
|
+
const items = all
|
|
94
|
+
.filter((o) => o.email.toLowerCase() === profile.email || profile.licenseOrderIds.includes(o.id))
|
|
95
|
+
.map((o) => ({
|
|
96
|
+
...o,
|
|
97
|
+
amountLabel: formatMoney(o.amountMillimes, country),
|
|
98
|
+
}));
|
|
99
|
+
res.json({ items });
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
r.get('/payments', requirePlatformUser, async (req, res) => {
|
|
103
|
+
const { profile } = await requireClient(req);
|
|
104
|
+
const country = profile.market === 'fr' ? 'FR' : 'TN';
|
|
105
|
+
const orders = (await listLicenseOrders()).filter(
|
|
106
|
+
(o) => o.email.toLowerCase() === profile.email || profile.licenseOrderIds.includes(o.id)
|
|
107
|
+
);
|
|
108
|
+
let events: (typeof saPaymentEvents.$inferSelect)[] = [];
|
|
109
|
+
if (orders.length) {
|
|
110
|
+
events = await db
|
|
111
|
+
.select()
|
|
112
|
+
.from(saPaymentEvents)
|
|
113
|
+
.where(and(eq(saPaymentEvents.refType, 'license'), inArray(saPaymentEvents.refId, orders.map((o) => o.id))))
|
|
114
|
+
.orderBy(desc(saPaymentEvents.createdAt))
|
|
115
|
+
.limit(100);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const synth = orders.map((o) => ({
|
|
119
|
+
id: `ord_${o.id}`,
|
|
120
|
+
provider: 'flouci',
|
|
121
|
+
kind: 'charge',
|
|
122
|
+
amountMillimes: o.amountMillimes,
|
|
123
|
+
amountLabel: formatMoney(o.amountMillimes, country),
|
|
124
|
+
status: o.status,
|
|
125
|
+
paymentId: o.paymentId || null,
|
|
126
|
+
refType: 'license',
|
|
127
|
+
refId: o.id,
|
|
128
|
+
domain: o.domain,
|
|
129
|
+
createdAt: o.paidAt || o.createdAt,
|
|
130
|
+
}));
|
|
131
|
+
|
|
132
|
+
const fromEvents = events.map((e) => ({
|
|
133
|
+
...e,
|
|
134
|
+
amountLabel: formatMoney(e.amountMillimes, country),
|
|
135
|
+
domain: orders.find((o) => o.id === e.refId)?.domain || '',
|
|
136
|
+
}));
|
|
137
|
+
|
|
138
|
+
res.json({ items: fromEvents.length ? fromEvents : synth });
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
r.get('/invoices', requirePlatformUser, async (req, res) => {
|
|
142
|
+
const { profile } = await requireClient(req);
|
|
143
|
+
const country = profile.market === 'fr' ? 'FR' : 'TN';
|
|
144
|
+
const rows = await db
|
|
145
|
+
.select()
|
|
146
|
+
.from(saInvoices)
|
|
147
|
+
.where(eq(saInvoices.customerEmail, profile.email))
|
|
148
|
+
.orderBy(desc(saInvoices.createdAt))
|
|
149
|
+
.limit(100);
|
|
150
|
+
res.json({
|
|
151
|
+
items: rows.map((inv) => ({
|
|
152
|
+
...inv,
|
|
153
|
+
amountLabel: formatMoney(inv.amountMillimes, country),
|
|
154
|
+
downloadUrl: `/api/client/invoices/${inv.id}/download`,
|
|
155
|
+
})),
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
r.get('/invoices/:id/download', requirePlatformUser, async (req, res) => {
|
|
160
|
+
const { profile } = await requireClient(req);
|
|
161
|
+
const country = profile.market === 'fr' ? 'FR' : 'TN';
|
|
162
|
+
const [inv] = await db.select().from(saInvoices).where(eq(saInvoices.id, req.params.id)).limit(1);
|
|
163
|
+
if (!inv || inv.customerEmail.toLowerCase() !== profile.email.toLowerCase()) {
|
|
164
|
+
throw new HttpError(404, 'Facture introuvable');
|
|
165
|
+
}
|
|
166
|
+
const lines = inv.lines
|
|
167
|
+
.map(
|
|
168
|
+
(l) =>
|
|
169
|
+
`<tr><td style="padding:8px;border-bottom:1px solid #e2e8f0">${escapeHtml(l.label)}</td><td style="padding:8px;border-bottom:1px solid #e2e8f0;text-align:right">${escapeHtml(formatMoney(l.amountMillimes, country))}</td></tr>`
|
|
170
|
+
)
|
|
171
|
+
.join('');
|
|
172
|
+
const html = `<!doctype html><html lang="fr"><head><meta charset="utf-8"/><title>Facture ${escapeHtml(inv.number)}</title>
|
|
173
|
+
<style>body{font-family:Inter,system-ui,sans-serif;color:#0f172a;max-width:720px;margin:40px auto;padding:0 16px}h1{font-size:22px;margin:0 0 4px}.muted{color:#64748b;font-size:13px}table{width:100%;border-collapse:collapse;margin-top:24px}.total{font-weight:700;font-size:16px}</style></head>
|
|
174
|
+
<body>
|
|
175
|
+
<div style="display:flex;justify-content:space-between;align-items:flex-start">
|
|
176
|
+
<div><h1>Facture ${escapeHtml(inv.number)}</h1><div class="muted">Snapify · NOVALABS WEB DESIGN</div></div>
|
|
177
|
+
<div class="muted" style="text-align:right">Statut : ${escapeHtml(inv.status)}<br/>${new Date(inv.createdAt).toLocaleDateString('fr-FR')}</div>
|
|
178
|
+
</div>
|
|
179
|
+
<p style="margin-top:24px"><strong>${escapeHtml(inv.customerName)}</strong><br/><span class="muted">${escapeHtml(inv.customerEmail)}</span></p>
|
|
180
|
+
<table><thead><tr><th style="text-align:left;padding:8px;border-bottom:2px solid #0f172a">Désignation</th><th style="text-align:right;padding:8px;border-bottom:2px solid #0f172a">Montant</th></tr></thead>
|
|
181
|
+
<tbody>${lines}<tr><td class="total" style="padding:12px 8px">Total</td><td class="total" style="padding:12px 8px;text-align:right">${escapeHtml(formatMoney(inv.amountMillimes, country))}</td></tr></tbody></table>
|
|
182
|
+
${inv.notes ? `<p class="muted" style="margin-top:24px">${escapeHtml(inv.notes)}</p>` : ''}
|
|
183
|
+
<p class="muted" style="margin-top:40px;font-size:12px">Document généré depuis l’espace client Snapify. ${profile.market === 'fr' ? 'NOVALABS — offre France.' : 'NOVALABS WEB DESIGN — Tunisie.'}</p>
|
|
184
|
+
<script>window.print()</script>
|
|
185
|
+
</body></html>`;
|
|
186
|
+
res.type('html').send(html);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
r.get('/tickets', requirePlatformUser, async (req, res) => {
|
|
190
|
+
const { user, profile } = await requireClient(req);
|
|
191
|
+
const rows = await db
|
|
192
|
+
.select()
|
|
193
|
+
.from(saTickets)
|
|
194
|
+
.where(or(eq(saTickets.userId, user.id), eq(saTickets.email, profile.email)))
|
|
195
|
+
.orderBy(desc(saTickets.updatedAt))
|
|
196
|
+
.limit(100);
|
|
197
|
+
res.json({ items: rows });
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
r.post('/tickets', requirePlatformUser, async (req, res) => {
|
|
201
|
+
const { user, profile } = await requireClient(req);
|
|
202
|
+
const subject = String(req.body?.subject || '').trim().slice(0, 200);
|
|
203
|
+
if (subject.length < 3) throw new HttpError(422, 'Sujet requis');
|
|
204
|
+
const kindRaw = String(req.body?.kind || 'support');
|
|
205
|
+
const kind = ['support', 'payment', 'license', 'bug'].includes(kindRaw) ? kindRaw : 'support';
|
|
206
|
+
const priority = ['low', 'normal', 'high', 'urgent'].includes(req.body?.priority) ? req.body.priority : 'normal';
|
|
207
|
+
const [row] = await db
|
|
208
|
+
.insert(saTickets)
|
|
209
|
+
.values({
|
|
210
|
+
id: crypto.randomUUID(),
|
|
211
|
+
kind: kind as 'support' | 'payment' | 'license' | 'bug',
|
|
212
|
+
priority,
|
|
213
|
+
subject,
|
|
214
|
+
body: String(req.body?.body || '').slice(0, 8000),
|
|
215
|
+
email: profile.email,
|
|
216
|
+
name: profile.name,
|
|
217
|
+
userId: user.id,
|
|
218
|
+
refType: kind === 'bug' ? 'bug' : 'client',
|
|
219
|
+
refId: profile.id,
|
|
220
|
+
})
|
|
221
|
+
.returning();
|
|
222
|
+
res.status(201).json({ ticket: row });
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
r.get('/overview', requirePlatformUser, async (req, res) => {
|
|
226
|
+
const { profile } = await requireClient(req);
|
|
227
|
+
const country = profile.market === 'fr' ? 'FR' : 'TN';
|
|
228
|
+
const orders = (await listLicenseOrders()).filter(
|
|
229
|
+
(o) => o.email.toLowerCase() === profile.email || profile.licenseOrderIds.includes(o.id)
|
|
230
|
+
);
|
|
231
|
+
const tickets = await db
|
|
232
|
+
.select()
|
|
233
|
+
.from(saTickets)
|
|
234
|
+
.where(or(eq(saTickets.userId, req.platformUser!.id), eq(saTickets.email, profile.email)))
|
|
235
|
+
.limit(50);
|
|
236
|
+
const invoices = await db.select().from(saInvoices).where(eq(saInvoices.customerEmail, profile.email)).limit(50);
|
|
237
|
+
const openTickets = tickets.filter((t) => t.status === 'open' || t.status === 'in_progress' || t.status === 'waiting').length;
|
|
238
|
+
res.json({
|
|
239
|
+
profile,
|
|
240
|
+
stats: {
|
|
241
|
+
requests: orders.length,
|
|
242
|
+
paid: orders.filter((o) => o.status === 'paid').length,
|
|
243
|
+
openTickets,
|
|
244
|
+
invoices: invoices.length,
|
|
245
|
+
},
|
|
246
|
+
recentRequests: orders.slice(0, 5).map((o) => ({ ...o, amountLabel: formatMoney(o.amountMillimes, country) })),
|
|
247
|
+
recentTickets: tickets.slice(0, 5),
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
return r;
|
|
252
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
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 fs from 'fs/promises';
|
|
8
|
+
import crypto from 'crypto';
|
|
9
|
+
import { createReadStream } from 'fs';
|
|
10
|
+
import readline from 'readline';
|
|
11
|
+
import { sql } from 'drizzle-orm';
|
|
12
|
+
import type { AnalyticsEvent, AnalyticsSummary } from './types';
|
|
13
|
+
import { db, type Tx } from '../db/client';
|
|
14
|
+
import { analyticsEvents } from '../db/schema';
|
|
15
|
+
|
|
16
|
+
export type { AnalyticsSummary } from './types';
|
|
17
|
+
|
|
18
|
+
const RETENTION_DAYS = 400;
|
|
19
|
+
const MAX_DURATION_SEC = 1800;
|
|
20
|
+
|
|
21
|
+
const toRow = (e: AnalyticsEvent): typeof analyticsEvents.$inferInsert => ({
|
|
22
|
+
id: /^[0-9a-f-]{36}$/i.test(e.id) ? e.id : crypto.randomUUID(),
|
|
23
|
+
kind: e.kind ?? (e.durationSec ? 'leave' : 'view'),
|
|
24
|
+
sessionId: e.sessionId,
|
|
25
|
+
path: e.path,
|
|
26
|
+
referrer: e.referrer ?? null,
|
|
27
|
+
country: e.country ?? null,
|
|
28
|
+
city: e.city ?? null,
|
|
29
|
+
device: e.device ?? 'unknown',
|
|
30
|
+
durationSec: typeof e.durationSec === 'number' ? Math.round(e.durationSec) : null,
|
|
31
|
+
ts: new Date(e.ts),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export async function appendAnalyticsEvent(event: AnalyticsEvent): Promise<void> {
|
|
35
|
+
try {
|
|
36
|
+
await db.insert(analyticsEvents).values(toRow(event)).onConflictDoNothing();
|
|
37
|
+
} catch (e) {
|
|
38
|
+
console.error('[analytics] écriture impossible', e);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function pruneAnalytics(days = RETENTION_DAYS): Promise<number> {
|
|
43
|
+
if (days <= 0) return 0;
|
|
44
|
+
const res = await db.execute(sql`delete from analytics_events where ts < now() - make_interval(days => ${days})`);
|
|
45
|
+
return res.rowCount ?? 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Import unique de l'ancien journal JSONL (et des événements hérités du snapshot). */
|
|
49
|
+
export async function importLegacyAnalytics(tx: Tx, file: string, legacy?: AnalyticsEvent[]): Promise<void> {
|
|
50
|
+
const rows: (typeof analyticsEvents.$inferInsert)[] = (legacy ?? []).map(toRow);
|
|
51
|
+
try {
|
|
52
|
+
const rl = readline.createInterface({ input: createReadStream(file, 'utf-8'), crlfDelay: Infinity });
|
|
53
|
+
for await (const line of rl) {
|
|
54
|
+
if (!line.trim()) continue;
|
|
55
|
+
try {
|
|
56
|
+
rows.push(toRow(JSON.parse(line) as AnalyticsEvent));
|
|
57
|
+
} catch {
|
|
58
|
+
/* ligne corrompue ignorée */
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
} catch {
|
|
62
|
+
/* pas d'ancien journal */
|
|
63
|
+
}
|
|
64
|
+
for (let i = 0; i < rows.length; i += 1000) {
|
|
65
|
+
await tx.insert(analyticsEvents).values(rows.slice(i, i + 1000)).onConflictDoNothing();
|
|
66
|
+
}
|
|
67
|
+
if (rows.length) {
|
|
68
|
+
await fs.rename(file, `${file}.imported`).catch(() => undefined);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function referrerSource(ref?: string | null): string {
|
|
73
|
+
if (!ref) return 'Accès direct';
|
|
74
|
+
try {
|
|
75
|
+
const host = new URL(ref).hostname.replace(/^www\./, '');
|
|
76
|
+
if (/google\./.test(host)) return 'Google';
|
|
77
|
+
if (/bing\./.test(host)) return 'Bing';
|
|
78
|
+
if (/linkedin\./.test(host)) return 'LinkedIn';
|
|
79
|
+
if (/facebook\.|fb\./.test(host)) return 'Facebook';
|
|
80
|
+
return host;
|
|
81
|
+
} catch {
|
|
82
|
+
return 'Autre';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const n = (v: unknown) => Number(v ?? 0);
|
|
87
|
+
|
|
88
|
+
/** Agrégats calculés par PostgreSQL : le volume d'événements n'est jamais chargé en mémoire. */
|
|
89
|
+
export async function summarizeAnalytics(days: number, ownHost?: string): Promise<AnalyticsSummary> {
|
|
90
|
+
const since = new Date(Date.now() - days * 86400000);
|
|
91
|
+
const views = sql`kind = 'view' and ts >= ${since}`;
|
|
92
|
+
|
|
93
|
+
const [totals, timeseries, topPages, countries, devices, referrers, recent] = await Promise.all([
|
|
94
|
+
db.execute(sql`
|
|
95
|
+
with s as (
|
|
96
|
+
select session_id, count(*) as n from analytics_events where ${views} group by session_id
|
|
97
|
+
)
|
|
98
|
+
select
|
|
99
|
+
(select count(*) from analytics_events where ${views}) as page_views,
|
|
100
|
+
(select count(*) from s) as sessions,
|
|
101
|
+
(select count(*) from s where n = 1) as bounced,
|
|
102
|
+
(select avg(least(duration_sec, ${MAX_DURATION_SEC})) from analytics_events
|
|
103
|
+
where kind = 'leave' and duration_sec is not null and ts >= ${since}) as avg_time,
|
|
104
|
+
(select count(distinct session_id) from analytics_events where ts >= now() - interval '5 minutes') as active_now
|
|
105
|
+
`),
|
|
106
|
+
db.execute(sql`
|
|
107
|
+
select to_char(ts at time zone 'UTC', 'YYYY-MM-DD') as day, count(*) as views, count(distinct session_id) as sessions
|
|
108
|
+
from analytics_events where ${views} group by 1
|
|
109
|
+
`),
|
|
110
|
+
db.execute(sql`
|
|
111
|
+
with v as (
|
|
112
|
+
select path, count(*) as views from analytics_events where ${views} group by path order by views desc limit 15
|
|
113
|
+
),
|
|
114
|
+
t as (
|
|
115
|
+
select path, avg(least(duration_sec, ${MAX_DURATION_SEC})) as avg_time from analytics_events
|
|
116
|
+
where kind = 'leave' and duration_sec is not null and ts >= ${since} group by path
|
|
117
|
+
)
|
|
118
|
+
select v.path, v.views, coalesce(t.avg_time, 0) as avg_time from v left join t using (path) order by v.views desc
|
|
119
|
+
`),
|
|
120
|
+
db.execute(sql`
|
|
121
|
+
select coalesce(country, '??') as country, count(*) as views from analytics_events
|
|
122
|
+
where ${views} group by 1 order by views desc
|
|
123
|
+
`),
|
|
124
|
+
db.execute(sql`
|
|
125
|
+
select device, count(*) as views from analytics_events where ${views} group by 1 order by views desc
|
|
126
|
+
`),
|
|
127
|
+
db.execute(sql`
|
|
128
|
+
select referrer, count(*) as views from analytics_events
|
|
129
|
+
where ${views} ${ownHost ? sql`and (referrer is null or position(${ownHost} in referrer) = 0)` : sql``}
|
|
130
|
+
group by referrer
|
|
131
|
+
`),
|
|
132
|
+
db.select().from(analyticsEvents).orderBy(sql`ts desc`).limit(500),
|
|
133
|
+
]);
|
|
134
|
+
|
|
135
|
+
const tot = totals.rows[0] as Record<string, unknown>;
|
|
136
|
+
const sessions = n(tot.sessions);
|
|
137
|
+
|
|
138
|
+
const byDay = new Map(timeseries.rows.map((r) => [String(r.day), r]));
|
|
139
|
+
const series: AnalyticsSummary['timeseries'] = [];
|
|
140
|
+
for (let i = days - 1; i >= 0; i--) {
|
|
141
|
+
const date = new Date(Date.now() - i * 86400000).toISOString().slice(0, 10);
|
|
142
|
+
const row = byDay.get(date);
|
|
143
|
+
series.push({ date, views: n(row?.views), sessions: n(row?.sessions) });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const sources = new Map<string, number>();
|
|
147
|
+
for (const r of referrers.rows) {
|
|
148
|
+
const key = referrerSource(r.referrer as string | null);
|
|
149
|
+
sources.set(key, (sources.get(key) || 0) + n(r.views));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
days,
|
|
154
|
+
pageViews: n(tot.page_views),
|
|
155
|
+
uniqueSessions: sessions,
|
|
156
|
+
avgTimeOnPageSec: Math.round(n(tot.avg_time)),
|
|
157
|
+
bounceRate: sessions ? Math.round((n(tot.bounced) / sessions) * 100) : 0,
|
|
158
|
+
activeNow: n(tot.active_now),
|
|
159
|
+
timeseries: series,
|
|
160
|
+
topPages: topPages.rows.map((r) => ({ path: String(r.path), views: n(r.views), avgTimeSec: Math.round(n(r.avg_time)) })),
|
|
161
|
+
countries: countries.rows.map((r) => ({ country: String(r.country), views: n(r.views) })),
|
|
162
|
+
devices: devices.rows.map((r) => ({ device: String(r.device), views: n(r.views) })),
|
|
163
|
+
referrers: [...sources.entries()]
|
|
164
|
+
.sort((a, b) => b[1] - a[1])
|
|
165
|
+
.slice(0, 10)
|
|
166
|
+
.map(([source, views]) => ({ source, views })),
|
|
167
|
+
recent: recent.map((r) => ({
|
|
168
|
+
id: r.id,
|
|
169
|
+
kind: r.kind,
|
|
170
|
+
sessionId: r.sessionId,
|
|
171
|
+
path: r.path,
|
|
172
|
+
...(r.referrer ? { referrer: r.referrer } : {}),
|
|
173
|
+
...(r.country ? { country: r.country } : {}),
|
|
174
|
+
...(r.city ? { city: r.city } : {}),
|
|
175
|
+
device: r.device,
|
|
176
|
+
...(r.durationSec != null ? { durationSec: r.durationSec } : {}),
|
|
177
|
+
ts: r.ts.toISOString(),
|
|
178
|
+
})),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
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 type { AdminUser, SystemSettings } from './types';
|
|
9
|
+
|
|
10
|
+
function jwtSecret(): string {
|
|
11
|
+
const secret = process.env.ADMIN_JWT_SECRET;
|
|
12
|
+
if (!secret && process.env.NODE_ENV === 'production') {
|
|
13
|
+
throw new Error('ADMIN_JWT_SECRET doit être défini en production');
|
|
14
|
+
}
|
|
15
|
+
return secret || 'dev-only-secret-snapify-cms';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function hashPassword(password: string, salt?: string): { hash: string; salt: string } {
|
|
19
|
+
const s = salt || crypto.randomBytes(16).toString('hex');
|
|
20
|
+
const hash = crypto.scryptSync(password, s, 64).toString('hex');
|
|
21
|
+
return { hash, salt: s };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function safeEqual(a: Buffer, b: Buffer): boolean {
|
|
25
|
+
return a.length === b.length && crypto.timingSafeEqual(a, b);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function verifyPassword(password: string, user: AdminUser): boolean {
|
|
29
|
+
const { hash } = hashPassword(password, user.salt);
|
|
30
|
+
return safeEqual(Buffer.from(hash, 'hex'), Buffer.from(user.passwordHash, 'hex'));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Empreinte factice : même coût de calcul quand le compte n'existe pas (pas d'énumération par le temps de réponse). */
|
|
34
|
+
let dummy: AdminUser | null = null;
|
|
35
|
+
export function burnPasswordCheck(password: string) {
|
|
36
|
+
if (!dummy) {
|
|
37
|
+
const { hash, salt } = hashPassword(crypto.randomUUID());
|
|
38
|
+
dummy = { id: '', email: '', name: '', role: '', passwordHash: hash, salt };
|
|
39
|
+
}
|
|
40
|
+
verifyPassword(password, dummy);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Mot de passe inutilisable (comptes invités, réinitialisés). */
|
|
44
|
+
export function unusablePassword(): { hash: string; salt: string } {
|
|
45
|
+
return hashPassword(crypto.randomBytes(32).toString('hex'));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type PasswordPolicy = Pick<SystemSettings['security'], 'passwordMinLength' | 'requireUppercase' | 'requireNumber' | 'requireSymbol'>;
|
|
49
|
+
|
|
50
|
+
export function validatePassword(password: string, policy: PasswordPolicy, user?: { email?: string; name?: string }): string | null {
|
|
51
|
+
if (password.length < policy.passwordMinLength) return `Le mot de passe doit contenir au moins ${policy.passwordMinLength} caractères.`;
|
|
52
|
+
if (password.length > 200) return 'Le mot de passe est trop long (200 caractères max).';
|
|
53
|
+
if (!/[a-zA-Z]/.test(password)) return 'Le mot de passe doit contenir au moins une lettre.';
|
|
54
|
+
if (policy.requireUppercase && (!/[A-Z]/.test(password) || !/[a-z]/.test(password))) return 'Le mot de passe doit mêler majuscules et minuscules.';
|
|
55
|
+
if (policy.requireNumber && !/\d/.test(password)) return 'Le mot de passe doit contenir au moins un chiffre.';
|
|
56
|
+
if (policy.requireSymbol && !/[^a-zA-Z0-9]/.test(password)) return 'Le mot de passe doit contenir au moins un caractère spécial.';
|
|
57
|
+
const lower = password.toLowerCase();
|
|
58
|
+
const local = user?.email?.split('@')[0]?.toLowerCase();
|
|
59
|
+
if (local && local.length >= 4 && lower.includes(local)) return 'Le mot de passe ne doit pas contenir votre adresse e-mail.';
|
|
60
|
+
if (/^(.)\1+$/.test(password) || /^(?:0123456789|1234567890|azertyuiop|qwertyuiop|password|motdepasse)/i.test(password)) {
|
|
61
|
+
return 'Ce mot de passe est trop facile à deviner.';
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Le mot de passe a-t-il dépassé la durée de validité de la politique ? */
|
|
67
|
+
export function passwordExpired(user: AdminUser, expiryDays: number): boolean {
|
|
68
|
+
if (expiryDays <= 0) return false;
|
|
69
|
+
const since = user.passwordChangedAt || user.createdAt;
|
|
70
|
+
return !!since && Date.now() - new Date(since).getTime() > expiryDays * 86400_000;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/* ---------- Jetons signés ---------- */
|
|
74
|
+
|
|
75
|
+
function sign(payload: object): string {
|
|
76
|
+
const body = Buffer.from(JSON.stringify(payload)).toString('base64url');
|
|
77
|
+
const sig = crypto.createHmac('sha256', jwtSecret()).update(body).digest('base64url');
|
|
78
|
+
return `${body}.${sig}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function unsign<T extends { exp: number }>(token: string): T | null {
|
|
82
|
+
const parts = token.split('.');
|
|
83
|
+
if (parts.length !== 2) return null;
|
|
84
|
+
const [body, sig] = parts;
|
|
85
|
+
const expected = crypto.createHmac('sha256', jwtSecret()).update(body).digest('base64url');
|
|
86
|
+
if (!safeEqual(Buffer.from(sig), Buffer.from(expected))) return null;
|
|
87
|
+
try {
|
|
88
|
+
const payload = JSON.parse(Buffer.from(body, 'base64url').toString('utf-8')) as T;
|
|
89
|
+
if (typeof payload.exp !== 'number' || payload.exp < Date.now()) return null;
|
|
90
|
+
return payload;
|
|
91
|
+
} catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface TokenPayload {
|
|
97
|
+
typ: 'session';
|
|
98
|
+
sub: string;
|
|
99
|
+
/** Identifiant de session (table admin_sessions), révocable. */
|
|
100
|
+
sid: string;
|
|
101
|
+
exp: number;
|
|
102
|
+
/** Empreinte du hash : un changement de mot de passe invalide les jetons existants. */
|
|
103
|
+
pv: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const passwordVersion = (user: AdminUser) => user.passwordHash.slice(0, 12);
|
|
107
|
+
|
|
108
|
+
export function createToken(user: AdminUser, sid: string, expiresAt: Date): string {
|
|
109
|
+
return sign({ typ: 'session', sub: user.id, sid, exp: expiresAt.getTime(), pv: passwordVersion(user) } satisfies TokenPayload);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function verifyToken(token: string): TokenPayload | null {
|
|
113
|
+
const p = unsign<TokenPayload>(token);
|
|
114
|
+
return p?.typ === 'session' && p.sid ? p : null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export const tokenMatchesUser = (payload: { pv: string }, user: AdminUser) => payload.pv === passwordVersion(user);
|
|
118
|
+
|
|
119
|
+
/** Étape intermédiaire de connexion : mot de passe validé, code 2FA attendu (5 min). */
|
|
120
|
+
export interface ChallengePayload {
|
|
121
|
+
typ: '2fa';
|
|
122
|
+
sub: string;
|
|
123
|
+
remember: boolean;
|
|
124
|
+
exp: number;
|
|
125
|
+
pv: string;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export const createChallenge = (user: AdminUser, remember: boolean) =>
|
|
129
|
+
sign({ typ: '2fa', sub: user.id, remember, exp: Date.now() + 5 * 60_000, pv: passwordVersion(user) } satisfies ChallengePayload);
|
|
130
|
+
|
|
131
|
+
export function verifyChallenge(token: string): ChallengePayload | null {
|
|
132
|
+
const p = unsign<ChallengePayload>(token);
|
|
133
|
+
return p?.typ === '2fa' ? p : null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export async function ensureDefaultAdmin(users: AdminUser[]): Promise<AdminUser[]> {
|
|
137
|
+
if (users.length > 0) return users;
|
|
138
|
+
const password = process.env.ADMIN_PASSWORD;
|
|
139
|
+
if (!password) throw new Error('ADMIN_PASSWORD requis pour créer le premier compte administrateur');
|
|
140
|
+
const { hash, salt } = hashPassword(password);
|
|
141
|
+
const now = new Date().toISOString();
|
|
142
|
+
return [
|
|
143
|
+
{
|
|
144
|
+
id: 'admin-1',
|
|
145
|
+
email: process.env.ADMIN_EMAIL || 'admin@snapify.fr',
|
|
146
|
+
passwordHash: hash,
|
|
147
|
+
salt,
|
|
148
|
+
role: 'superadmin',
|
|
149
|
+
name: 'Administrateur Snapify',
|
|
150
|
+
status: 'active',
|
|
151
|
+
passwordChangedAt: now,
|
|
152
|
+
createdAt: now,
|
|
153
|
+
},
|
|
154
|
+
];
|
|
155
|
+
}
|