kybernus 3.1.0 → 3.2.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/dist/cli/commands/ecommerce.d.ts +3 -0
- package/dist/cli/commands/ecommerce.d.ts.map +1 -0
- package/dist/cli/commands/ecommerce.js +164 -0
- package/dist/cli/commands/ecommerce.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/templates/ecommerce/.env.example +10 -0
- package/templates/ecommerce/.github/workflows/ci.yml +102 -0
- package/templates/ecommerce/.github/workflows/deploy.yml +31 -0
- package/templates/ecommerce/.prettierrc +9 -0
- package/templates/ecommerce/Dockerfile +54 -0
- package/templates/ecommerce/README.md +295 -0
- package/templates/ecommerce/apps/api/.env.example +59 -0
- package/templates/ecommerce/apps/api/jest.config.ts +50 -0
- package/templates/ecommerce/apps/api/jest.integration.config.ts +45 -0
- package/templates/ecommerce/apps/api/package.json +59 -0
- package/templates/ecommerce/apps/api/prisma/migrations/20260306000137_init/migration.sql +184 -0
- package/templates/ecommerce/apps/api/prisma/migrations/migration_lock.toml +3 -0
- package/templates/ecommerce/apps/api/prisma/schema.prisma +181 -0
- package/templates/ecommerce/apps/api/prisma/seed.ts +159 -0
- package/templates/ecommerce/apps/api/src/__tests__/app.test.ts +39 -0
- package/templates/ecommerce/apps/api/src/__tests__/globalSetup.ts +34 -0
- package/templates/ecommerce/apps/api/src/__tests__/globalTeardown.ts +16 -0
- package/templates/ecommerce/apps/api/src/__tests__/setup.db.ts +18 -0
- package/templates/ecommerce/apps/api/src/__tests__/setup.env.ts +14 -0
- package/templates/ecommerce/apps/api/src/app.ts +133 -0
- package/templates/ecommerce/apps/api/src/application/admin/admin-user.service.ts +24 -0
- package/templates/ecommerce/apps/api/src/application/admin/dashboard.service.ts +102 -0
- package/templates/ecommerce/apps/api/src/application/auth/auth.service.ts +185 -0
- package/templates/ecommerce/apps/api/src/application/cart/cart.service.ts +151 -0
- package/templates/ecommerce/apps/api/src/application/cart/coupon.service.ts +51 -0
- package/templates/ecommerce/apps/api/src/application/catalog/catalog.service.ts +168 -0
- package/templates/ecommerce/apps/api/src/application/checkout/checkout.service.ts +114 -0
- package/templates/ecommerce/apps/api/src/application/orders/order.service.ts +93 -0
- package/templates/ecommerce/apps/api/src/application/ports/email.port.ts +3 -0
- package/templates/ecommerce/apps/api/src/application/ports/payment.port.ts +24 -0
- package/templates/ecommerce/apps/api/src/application/ports/shipping.port.ts +9 -0
- package/templates/ecommerce/apps/api/src/application/ports/storage.port.ts +3 -0
- package/templates/ecommerce/apps/api/src/application/ports/token-blacklist.port.ts +4 -0
- package/templates/ecommerce/apps/api/src/application/ports/token.port.ts +18 -0
- package/templates/ecommerce/apps/api/src/application/profile/profile.service.ts +76 -0
- package/templates/ecommerce/apps/api/src/domain/auth/user.entity.ts +109 -0
- package/templates/ecommerce/apps/api/src/domain/auth/user.repository.ts +11 -0
- package/templates/ecommerce/apps/api/src/domain/cart/cart.entity.ts +136 -0
- package/templates/ecommerce/apps/api/src/domain/cart/cart.repository.ts +8 -0
- package/templates/ecommerce/apps/api/src/domain/cart/coupon.entity.ts +58 -0
- package/templates/ecommerce/apps/api/src/domain/cart/coupon.repository.ts +10 -0
- package/templates/ecommerce/apps/api/src/domain/catalog/category.entity.ts +51 -0
- package/templates/ecommerce/apps/api/src/domain/catalog/category.repository.ts +10 -0
- package/templates/ecommerce/apps/api/src/domain/catalog/product.entity.ts +130 -0
- package/templates/ecommerce/apps/api/src/domain/catalog/product.repository.ts +28 -0
- package/templates/ecommerce/apps/api/src/domain/checkout/order.entity.ts +121 -0
- package/templates/ecommerce/apps/api/src/domain/checkout/order.repository.ts +11 -0
- package/templates/ecommerce/apps/api/src/domain/shared/AppError.ts +12 -0
- package/templates/ecommerce/apps/api/src/infrastructure/cache/redis.ts +16 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/admin.registry.ts +13 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/auth.registry.ts +34 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/cart.registry.ts +49 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/catalog.registry.ts +24 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/checkout.registry.ts +47 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/orders.registry.ts +6 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/profile.registry.ts +4 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/cart.memory.repository.ts +33 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/category.memory.repository.ts +41 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/coupon.memory.repository.ts +55 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/order.memory.repository.ts +75 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/product.memory.repository.ts +100 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/user.memory.repository.ts +54 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/prisma/auth/user.prisma.repository.ts +83 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/prisma/catalog/category.prisma.repository.ts +69 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/prisma/catalog/product.prisma.repository.ts +185 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/prisma/checkout/order.prisma.repository.ts +149 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/prisma-client.ts +17 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/email/email.registry.ts +18 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/email/ethereal.email.service.ts +38 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/email/noop.email.service.ts +12 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/email/smtp.email.service.ts +36 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/payment/stripe-webhook.handler.ts +83 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/payment/stripe.adapter.ts +39 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/shipping/mock.shipping.service.ts +17 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/storage/in-memory.storage.service.ts +11 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/storage/local-disk.storage.service.ts +27 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/storage/s3.storage.service.ts +52 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/storage/storage.registry.ts +19 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/token/redis.token.blacklist.ts +23 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/token/token.blacklist.ts +30 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/token/token.service.ts +136 -0
- package/templates/ecommerce/apps/api/src/modules/admin/__tests__/admin.routes.integration.test.ts +250 -0
- package/templates/ecommerce/apps/api/src/modules/admin/admin.controller.ts +116 -0
- package/templates/ecommerce/apps/api/src/modules/admin/admin.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/admin/admin.routes.ts +21 -0
- package/templates/ecommerce/apps/api/src/modules/admin/admin.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/admin/admin.user.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/auth.logout.redis.test.ts +104 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/auth.routes.integration.test.ts +211 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/auth.service.unit.test.ts +260 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/email.service.unit.test.ts +94 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/token.blacklist.redis.test.ts +65 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/user.entity.unit.test.ts +79 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/user.prisma.repository.test.ts +138 -0
- package/templates/ecommerce/apps/api/src/modules/auth/auth.controller.ts +148 -0
- package/templates/ecommerce/apps/api/src/modules/auth/auth.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/auth/auth.routes.ts +17 -0
- package/templates/ecommerce/apps/api/src/modules/auth/auth.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/auth/redis.token.blacklist.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/auth/token.blacklist.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/auth/token.service.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/auth/user.entity.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/auth/user.prisma.repository.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/auth/user.repository.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/cart/__tests__/cart.entity.unit.test.ts +144 -0
- package/templates/ecommerce/apps/api/src/modules/cart/__tests__/cart.routes.integration.test.ts +242 -0
- package/templates/ecommerce/apps/api/src/modules/cart/__tests__/cart.service.unit.test.ts +151 -0
- package/templates/ecommerce/apps/api/src/modules/cart/__tests__/coupon.admin.integration.test.ts +136 -0
- package/templates/ecommerce/apps/api/src/modules/cart/cart.controller.ts +94 -0
- package/templates/ecommerce/apps/api/src/modules/cart/cart.entity.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/cart/cart.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/cart/cart.repository.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/cart/cart.routes.ts +17 -0
- package/templates/ecommerce/apps/api/src/modules/cart/cart.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/cart/coupon.entity.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/cart/coupon.repository.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/cart/coupon.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/cart/shipping.service.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/__tests__/catalog.routes.integration.test.ts +275 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/__tests__/catalog.service.unit.test.ts +223 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/__tests__/product.image.integration.test.ts +130 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/__tests__/product.prisma.repository.test.ts +174 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/catalog.controller.ts +176 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/catalog.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/catalog.routes.ts +38 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/catalog.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/category.entity.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/category.prisma.repository.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/category.repository.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/product.entity.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/product.prisma.repository.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/product.repository.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/__tests__/checkout.routes.integration.test.ts +163 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/__tests__/checkout.service.unit.test.ts +191 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/__tests__/order.prisma.repository.test.ts +150 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/checkout.controller.ts +59 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/checkout.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/checkout.routes.ts +18 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/checkout.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/order.entity.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/order.prisma.repository.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/order.repository.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/tax.service.ts +9 -0
- package/templates/ecommerce/apps/api/src/modules/orders/__tests__/order.entity.unit.test.ts +68 -0
- package/templates/ecommerce/apps/api/src/modules/orders/__tests__/order.routes.integration.test.ts +254 -0
- package/templates/ecommerce/apps/api/src/modules/orders/__tests__/order.service.email.unit.test.ts +142 -0
- package/templates/ecommerce/apps/api/src/modules/orders/order.controller.ts +96 -0
- package/templates/ecommerce/apps/api/src/modules/orders/order.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/orders/order.routes.ts +17 -0
- package/templates/ecommerce/apps/api/src/modules/orders/order.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/payment/__tests__/stripe-webhook.unit.test.ts +330 -0
- package/templates/ecommerce/apps/api/src/modules/payment/__tests__/stripe.adapter.unit.test.ts +84 -0
- package/templates/ecommerce/apps/api/src/modules/payment/adapters/stripe.adapter.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/payment/payment.port.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/payment/stripe-webhook.handler.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/profile/__tests__/profile.routes.integration.test.ts +180 -0
- package/templates/ecommerce/apps/api/src/modules/profile/__tests__/profile.service.unit.test.ts +187 -0
- package/templates/ecommerce/apps/api/src/modules/profile/profile.controller.ts +92 -0
- package/templates/ecommerce/apps/api/src/modules/profile/profile.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/profile/profile.routes.ts +14 -0
- package/templates/ecommerce/apps/api/src/modules/profile/profile.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/presentation/middlewares/authenticate.ts +37 -0
- package/templates/ecommerce/apps/api/src/presentation/middlewares/authorize.ts +23 -0
- package/templates/ecommerce/apps/api/src/presentation/middlewares/errorHandler.ts +48 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/admin/admin.controller.ts +116 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/admin/admin.routes.ts +21 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/auth/auth.controller.ts +147 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/auth/auth.routes.ts +17 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/cart/cart.controller.ts +94 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/cart/cart.routes.ts +17 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/catalog/catalog.controller.ts +176 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/catalog/catalog.routes.ts +38 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/checkout/checkout.controller.ts +59 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/checkout/checkout.routes.ts +18 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/orders/order.controller.ts +96 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/orders/order.routes.ts +17 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/profile/profile.controller.ts +92 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/profile/profile.routes.ts +14 -0
- package/templates/ecommerce/apps/api/src/presentation/validators/uuidParam.ts +20 -0
- package/templates/ecommerce/apps/api/src/server.ts +47 -0
- package/templates/ecommerce/apps/api/src/shared/__tests__/uuid.validation.test.ts +111 -0
- package/templates/ecommerce/apps/api/src/shared/errors/AppError.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/email/EtherealEmailService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/email/IEmailService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/email/NoopEmailService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/email/SmtpEmailService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/email/__tests__/ethereal.email.integration.test.ts +32 -0
- package/templates/ecommerce/apps/api/src/shared/infra/email/email.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/prisma.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/redis.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/storage/IStorageService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/storage/InMemoryStorageService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/storage/LocalDiskStorageService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/storage/S3StorageService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/storage/__tests__/s3.storage.unit.test.ts +73 -0
- package/templates/ecommerce/apps/api/src/shared/infra/storage/storage.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/middlewares/authenticate.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/middlewares/authorize.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/middlewares/errorHandler.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/validators/uuidParam.ts +1 -0
- package/templates/ecommerce/apps/api/tsconfig.json +15 -0
- package/templates/ecommerce/apps/web/.env.example +8 -0
- package/templates/ecommerce/apps/web/index.html +19 -0
- package/templates/ecommerce/apps/web/jest.config.ts +45 -0
- package/templates/ecommerce/apps/web/package.json +38 -0
- package/templates/ecommerce/apps/web/src/App.tsx +133 -0
- package/templates/ecommerce/apps/web/src/__mocks__/fileMock.ts +1 -0
- package/templates/ecommerce/apps/web/src/__mocks__/styleMock.ts +1 -0
- package/templates/ecommerce/apps/web/src/index.css +159 -0
- package/templates/ecommerce/apps/web/src/main.tsx +13 -0
- package/templates/ecommerce/apps/web/src/modules/admin/__tests__/CouponsAdminPage.test.tsx +134 -0
- package/templates/ecommerce/apps/web/src/modules/admin/__tests__/DashboardPage.test.tsx +65 -0
- package/templates/ecommerce/apps/web/src/modules/admin/__tests__/OrdersAdminPage.test.tsx +79 -0
- package/templates/ecommerce/apps/web/src/modules/admin/__tests__/ProductsAdminPage.test.tsx +84 -0
- package/templates/ecommerce/apps/web/src/modules/admin/__tests__/UsersAdminPage.test.tsx +85 -0
- package/templates/ecommerce/apps/web/src/modules/admin/pages/CouponsAdminPage.tsx +179 -0
- package/templates/ecommerce/apps/web/src/modules/admin/pages/DashboardPage.tsx +58 -0
- package/templates/ecommerce/apps/web/src/modules/admin/pages/OrdersAdminPage.tsx +178 -0
- package/templates/ecommerce/apps/web/src/modules/admin/pages/ProductsAdminPage.tsx +444 -0
- package/templates/ecommerce/apps/web/src/modules/admin/pages/UsersAdminPage.tsx +87 -0
- package/templates/ecommerce/apps/web/src/modules/auth/LoginForm.tsx +91 -0
- package/templates/ecommerce/apps/web/src/modules/auth/RegisterForm.tsx +109 -0
- package/templates/ecommerce/apps/web/src/modules/auth/__tests__/ForgotPasswordPage.test.tsx +42 -0
- package/templates/ecommerce/apps/web/src/modules/auth/__tests__/LoginForm.test.tsx +76 -0
- package/templates/ecommerce/apps/web/src/modules/auth/__tests__/RegisterForm.test.tsx +62 -0
- package/templates/ecommerce/apps/web/src/modules/auth/__tests__/ResetPasswordPage.test.tsx +66 -0
- package/templates/ecommerce/apps/web/src/modules/auth/pages/ForgotPasswordPage.tsx +100 -0
- package/templates/ecommerce/apps/web/src/modules/auth/pages/LoginPage.tsx +39 -0
- package/templates/ecommerce/apps/web/src/modules/auth/pages/RegisterPage.tsx +39 -0
- package/templates/ecommerce/apps/web/src/modules/auth/pages/ResetPasswordPage.tsx +110 -0
- package/templates/ecommerce/apps/web/src/modules/auth/useAuthStore.ts +141 -0
- package/templates/ecommerce/apps/web/src/modules/cart/__tests__/CartPage.test.tsx +111 -0
- package/templates/ecommerce/apps/web/src/modules/cart/pages/CartPage.tsx +313 -0
- package/templates/ecommerce/apps/web/src/modules/catalog/__tests__/ProductCard.test.tsx +59 -0
- package/templates/ecommerce/apps/web/src/modules/catalog/__tests__/ProductFilters.test.tsx +56 -0
- package/templates/ecommerce/apps/web/src/modules/catalog/components/ProductCard.tsx +78 -0
- package/templates/ecommerce/apps/web/src/modules/catalog/components/ProductFilters.tsx +104 -0
- package/templates/ecommerce/apps/web/src/modules/catalog/pages/ProductDetailPage.tsx +179 -0
- package/templates/ecommerce/apps/web/src/modules/catalog/pages/ProductListPage.tsx +100 -0
- package/templates/ecommerce/apps/web/src/modules/checkout/__tests__/CheckoutPage.test.tsx +159 -0
- package/templates/ecommerce/apps/web/src/modules/checkout/__tests__/StripePaymentForm.test.tsx +79 -0
- package/templates/ecommerce/apps/web/src/modules/checkout/components/StripePaymentForm.tsx +55 -0
- package/templates/ecommerce/apps/web/src/modules/checkout/hooks/useCheckout.ts +56 -0
- package/templates/ecommerce/apps/web/src/modules/checkout/pages/CheckoutPage.tsx +344 -0
- package/templates/ecommerce/apps/web/src/modules/checkout/pages/CheckoutSuccessPage.tsx +12 -0
- package/templates/ecommerce/apps/web/src/modules/legal/pages/PrivacyPolicyPage.tsx +207 -0
- package/templates/ecommerce/apps/web/src/modules/legal/pages/TermsOfServicePage.tsx +175 -0
- package/templates/ecommerce/apps/web/src/modules/orders/__tests__/OrderDetailPage.test.tsx +75 -0
- package/templates/ecommerce/apps/web/src/modules/orders/__tests__/OrderHistoryPage.test.tsx +87 -0
- package/templates/ecommerce/apps/web/src/modules/orders/pages/OrderDetailPage.tsx +73 -0
- package/templates/ecommerce/apps/web/src/modules/orders/pages/OrderHistoryPage.tsx +97 -0
- package/templates/ecommerce/apps/web/src/modules/profile/__tests__/ProfilePage.test.tsx +150 -0
- package/templates/ecommerce/apps/web/src/modules/profile/pages/ProfilePage.tsx +275 -0
- package/templates/ecommerce/apps/web/src/setupTests.ts +10 -0
- package/templates/ecommerce/apps/web/src/shared/components/CookieConsent.tsx +108 -0
- package/templates/ecommerce/apps/web/src/shared/components/ErrorBoundary.tsx +112 -0
- package/templates/ecommerce/apps/web/src/shared/components/Layout.tsx +143 -0
- package/templates/ecommerce/apps/web/src/shared/components/ProtectedRoute.tsx +21 -0
- package/templates/ecommerce/apps/web/src/shared/config/siteConfig.ts +57 -0
- package/templates/ecommerce/apps/web/src/shared/hooks/usePageTitle.ts +16 -0
- package/templates/ecommerce/apps/web/src/shared/lib/apiFetch.ts +16 -0
- package/templates/ecommerce/apps/web/src/shared/pages/NotFoundPage.tsx +42 -0
- package/templates/ecommerce/apps/web/src/shared/theme/ThemeProvider.tsx +45 -0
- package/templates/ecommerce/apps/web/src/shared/theme/__tests__/ThemeProvider.test.tsx +78 -0
- package/templates/ecommerce/apps/web/src/shared/theme/createTheme.ts +58 -0
- package/templates/ecommerce/apps/web/src/shared/theme/tokens.ts +81 -0
- package/templates/ecommerce/apps/web/src/vite-env.d.ts +1 -0
- package/templates/ecommerce/apps/web/tsconfig.jest.json +12 -0
- package/templates/ecommerce/apps/web/tsconfig.json +25 -0
- package/templates/ecommerce/apps/web/tsconfig.node.json +11 -0
- package/templates/ecommerce/apps/web/vite.config.ts +30 -0
- package/templates/ecommerce/docker-compose.yml +85 -0
- package/templates/ecommerce/package-lock.json +11255 -0
- package/templates/ecommerce/package.json +27 -0
- package/templates/ecommerce/packages/shared-types/package.json +13 -0
- package/templates/ecommerce/packages/shared-types/src/index.ts +3 -0
- package/templates/ecommerce/packages/shared-types/src/theme.ts +44 -0
- package/templates/ecommerce/packages/shared-types/tsconfig.json +11 -0
- package/templates/ecommerce/scripts/customize.sh +201 -0
- package/templates/ecommerce/tsconfig.json +14 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Component, type ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
interface Props {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
fallback?: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface State {
|
|
9
|
+
hasError: boolean;
|
|
10
|
+
error: Error | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class ErrorBoundary extends Component<Props, State> {
|
|
14
|
+
constructor(props: Props) {
|
|
15
|
+
super(props);
|
|
16
|
+
this.state = { hasError: false, error: null };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static getDerivedStateFromError(error: Error): State {
|
|
20
|
+
return { hasError: true, error };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
componentDidCatch(error: Error, info: { componentStack: string }) {
|
|
24
|
+
console.error('[ErrorBoundary] Unhandled render error:', error, info.componentStack);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
handleReset = () => {
|
|
28
|
+
this.setState({ hasError: false, error: null });
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
render() {
|
|
32
|
+
if (this.state.hasError) {
|
|
33
|
+
if (this.props.fallback) return this.props.fallback;
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<main
|
|
37
|
+
style={{
|
|
38
|
+
textAlign: 'center',
|
|
39
|
+
padding: '5rem 2rem',
|
|
40
|
+
display: 'flex',
|
|
41
|
+
flexDirection: 'column',
|
|
42
|
+
alignItems: 'center',
|
|
43
|
+
gap: '1rem',
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
<p style={{ fontSize: '3rem', lineHeight: 1 }}>⚠️</p>
|
|
47
|
+
<h1 style={{ fontSize: '1.4rem', fontWeight: 700, color: '#111827' }}>
|
|
48
|
+
Algo deu errado
|
|
49
|
+
</h1>
|
|
50
|
+
<p style={{ color: '#6b7280', maxWidth: '400px', fontSize: '0.9rem' }}>
|
|
51
|
+
Ocorreu um erro inesperado. Tente recarregar a página ou voltar ao início.
|
|
52
|
+
</p>
|
|
53
|
+
<div style={{ display: 'flex', gap: '0.75rem', marginTop: '0.5rem' }}>
|
|
54
|
+
<button
|
|
55
|
+
type="button"
|
|
56
|
+
onClick={this.handleReset}
|
|
57
|
+
style={{
|
|
58
|
+
background: 'var(--color-primary)',
|
|
59
|
+
color: '#fff',
|
|
60
|
+
border: 'none',
|
|
61
|
+
padding: '0.6rem 1.5rem',
|
|
62
|
+
borderRadius: '6px',
|
|
63
|
+
fontWeight: 600,
|
|
64
|
+
fontSize: '0.9rem',
|
|
65
|
+
cursor: 'pointer',
|
|
66
|
+
}}
|
|
67
|
+
>
|
|
68
|
+
Tentar novamente
|
|
69
|
+
</button>
|
|
70
|
+
<a
|
|
71
|
+
href="/"
|
|
72
|
+
style={{
|
|
73
|
+
background: 'transparent',
|
|
74
|
+
border: '1px solid #d1d5db',
|
|
75
|
+
color: '#374151',
|
|
76
|
+
padding: '0.6rem 1.5rem',
|
|
77
|
+
borderRadius: '6px',
|
|
78
|
+
fontWeight: 600,
|
|
79
|
+
fontSize: '0.9rem',
|
|
80
|
+
textDecoration: 'none',
|
|
81
|
+
}}
|
|
82
|
+
>
|
|
83
|
+
Ir para o início
|
|
84
|
+
</a>
|
|
85
|
+
</div>
|
|
86
|
+
{import.meta.env.DEV && this.state.error && (
|
|
87
|
+
<pre
|
|
88
|
+
style={{
|
|
89
|
+
marginTop: '1.5rem',
|
|
90
|
+
textAlign: 'left',
|
|
91
|
+
background: '#fef2f2',
|
|
92
|
+
border: '1px solid #fecaca',
|
|
93
|
+
borderRadius: '6px',
|
|
94
|
+
padding: '1rem',
|
|
95
|
+
fontSize: '0.75rem',
|
|
96
|
+
color: '#991b1b',
|
|
97
|
+
maxWidth: '600px',
|
|
98
|
+
overflow: 'auto',
|
|
99
|
+
whiteSpace: 'pre-wrap',
|
|
100
|
+
wordBreak: 'break-word',
|
|
101
|
+
}}
|
|
102
|
+
>
|
|
103
|
+
{this.state.error.message}
|
|
104
|
+
</pre>
|
|
105
|
+
)}
|
|
106
|
+
</main>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return this.props.children;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Link, Outlet, useNavigate } from 'react-router-dom';
|
|
2
|
+
import { useAuthStore } from '../../modules/auth/useAuthStore';
|
|
3
|
+
import { CookieConsent } from './CookieConsent';
|
|
4
|
+
import { siteConfig } from '../config/siteConfig';
|
|
5
|
+
|
|
6
|
+
const link: React.CSSProperties = {
|
|
7
|
+
color: 'white',
|
|
8
|
+
textDecoration: 'none',
|
|
9
|
+
padding: '0.3rem 0.6rem',
|
|
10
|
+
borderRadius: '4px',
|
|
11
|
+
fontSize: '0.95rem',
|
|
12
|
+
whiteSpace: 'nowrap',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function Layout() {
|
|
16
|
+
const { user, accessToken, logout } = useAuthStore();
|
|
17
|
+
const navigate = useNavigate();
|
|
18
|
+
|
|
19
|
+
async function handleLogout() {
|
|
20
|
+
await logout();
|
|
21
|
+
navigate('/login');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<div style={{ minHeight: '100vh', display: 'flex', flexDirection: 'column', fontFamily: 'var(--font-family)' }}>
|
|
26
|
+
<nav
|
|
27
|
+
className="site-nav"
|
|
28
|
+
style={{
|
|
29
|
+
display: 'flex',
|
|
30
|
+
alignItems: 'center',
|
|
31
|
+
gap: '1rem',
|
|
32
|
+
background: 'var(--color-primary)',
|
|
33
|
+
boxShadow: '0 2px 6px rgba(0,0,0,0.18)',
|
|
34
|
+
flexWrap: 'wrap',
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
<Link to="/" style={{ ...link, fontWeight: 700, fontSize: '1.15rem', marginRight: '0.5rem' }}>
|
|
38
|
+
{siteConfig.logo} {siteConfig.name}
|
|
39
|
+
</Link>
|
|
40
|
+
|
|
41
|
+
<Link to="/" style={link}>
|
|
42
|
+
Produtos
|
|
43
|
+
</Link>
|
|
44
|
+
|
|
45
|
+
{accessToken && (
|
|
46
|
+
<>
|
|
47
|
+
<Link to="/profile" style={link}>
|
|
48
|
+
Meu Perfil
|
|
49
|
+
</Link>
|
|
50
|
+
<Link to="/orders" style={link}>
|
|
51
|
+
Meus Pedidos
|
|
52
|
+
</Link>
|
|
53
|
+
<Link to="/checkout" style={link}>
|
|
54
|
+
Checkout
|
|
55
|
+
</Link>
|
|
56
|
+
</>
|
|
57
|
+
)}
|
|
58
|
+
|
|
59
|
+
{user?.role === 'ADMIN' && (
|
|
60
|
+
<Link to="/admin" style={{ ...link, background: 'rgba(255,255,255,0.15)' }}>
|
|
61
|
+
Admin ⚙
|
|
62
|
+
</Link>
|
|
63
|
+
)}
|
|
64
|
+
|
|
65
|
+
<div style={{ flex: 1 }} />
|
|
66
|
+
|
|
67
|
+
{accessToken ? (
|
|
68
|
+
<>
|
|
69
|
+
<span style={{ color: 'rgba(255,255,255,0.85)', fontSize: '0.875rem' }}>
|
|
70
|
+
{user?.name ?? user?.email ?? ''}
|
|
71
|
+
</span>
|
|
72
|
+
<button
|
|
73
|
+
type="button"
|
|
74
|
+
onClick={handleLogout}
|
|
75
|
+
style={{
|
|
76
|
+
background: 'rgba(255,255,255,0.18)',
|
|
77
|
+
border: '1px solid rgba(255,255,255,0.4)',
|
|
78
|
+
color: 'white',
|
|
79
|
+
cursor: 'pointer',
|
|
80
|
+
padding: '0.35rem 0.85rem',
|
|
81
|
+
borderRadius: '4px',
|
|
82
|
+
fontSize: '0.875rem',
|
|
83
|
+
fontFamily: 'var(--font-family)',
|
|
84
|
+
}}
|
|
85
|
+
>
|
|
86
|
+
Sair
|
|
87
|
+
</button>
|
|
88
|
+
</>
|
|
89
|
+
) : (
|
|
90
|
+
<>
|
|
91
|
+
<Link to="/login" style={link}>
|
|
92
|
+
Entrar
|
|
93
|
+
</Link>
|
|
94
|
+
<Link
|
|
95
|
+
to="/register"
|
|
96
|
+
style={{
|
|
97
|
+
...link,
|
|
98
|
+
background: 'rgba(255,255,255,0.18)',
|
|
99
|
+
border: '1px solid rgba(255,255,255,0.4)',
|
|
100
|
+
}}
|
|
101
|
+
>
|
|
102
|
+
Cadastrar
|
|
103
|
+
</Link>
|
|
104
|
+
</>
|
|
105
|
+
)}
|
|
106
|
+
</nav>
|
|
107
|
+
|
|
108
|
+
<main
|
|
109
|
+
className="site-main"
|
|
110
|
+
style={{
|
|
111
|
+
flex: 1,
|
|
112
|
+
maxWidth: '1200px',
|
|
113
|
+
width: '100%',
|
|
114
|
+
margin: '0 auto',
|
|
115
|
+
boxSizing: 'border-box',
|
|
116
|
+
}}
|
|
117
|
+
>
|
|
118
|
+
<Outlet />
|
|
119
|
+
</main>
|
|
120
|
+
|
|
121
|
+
<footer
|
|
122
|
+
style={{
|
|
123
|
+
textAlign: 'center',
|
|
124
|
+
padding: '1.25rem 1rem',
|
|
125
|
+
fontSize: '0.8rem',
|
|
126
|
+
color: 'var(--color-text-muted)',
|
|
127
|
+
borderTop: '1px solid #e5e7eb',
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
<div style={{ marginBottom: '0.5rem', display: 'flex', justifyContent: 'center', gap: '1.25rem', flexWrap: 'wrap' }}>
|
|
131
|
+
<Link to="/terms" style={{ color: 'inherit', textDecoration: 'underline' }}>Termos de Serviço</Link>
|
|
132
|
+
<Link to="/privacy" style={{ color: 'inherit', textDecoration: 'underline' }}>Política de Privacidade</Link>
|
|
133
|
+
{siteConfig.supportEmail && (
|
|
134
|
+
<a href={`mailto:${siteConfig.supportEmail}`} style={{ color: 'inherit', textDecoration: 'underline' }}>Suporte</a>
|
|
135
|
+
)}
|
|
136
|
+
</div>
|
|
137
|
+
{siteConfig.name} © {new Date().getFullYear()} — {siteConfig.legal.companyName}
|
|
138
|
+
</footer>
|
|
139
|
+
|
|
140
|
+
<CookieConsent />
|
|
141
|
+
</div>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Navigate } from 'react-router-dom';
|
|
2
|
+
import { useAuthStore } from '../../modules/auth/useAuthStore';
|
|
3
|
+
|
|
4
|
+
interface ProtectedRouteProps {
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
requiredRole?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function ProtectedRoute({ children, requiredRole }: ProtectedRouteProps) {
|
|
10
|
+
const { accessToken, user } = useAuthStore();
|
|
11
|
+
|
|
12
|
+
if (!accessToken) {
|
|
13
|
+
return <Navigate to="/login" replace />;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (requiredRole && user?.role !== requiredRole) {
|
|
17
|
+
return <Navigate to="/" replace />;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return <>{children}</>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
3
|
+
* Site Configuration — White-Label
|
|
4
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
5
|
+
* Centralizes every store-specific detail so that a new tenant only needs to
|
|
6
|
+
* edit this file. Theme colors live in apps/web/src/index.css (CSS variables).
|
|
7
|
+
*
|
|
8
|
+
* HOW TO CUSTOMIZE:
|
|
9
|
+
* 1. Change the values below to match your brand.
|
|
10
|
+
* 2. Replace `logo` with an <img> path or emoji; see Layout.tsx.
|
|
11
|
+
* 3. Fill in `legal.*` — Brazilian law requires CNPJ + address on invoices.
|
|
12
|
+
* 4. Update `privacyEmail` with the actual DPO / privacy contact.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export const siteConfig = {
|
|
16
|
+
// ── Brand ──────────────────────────────────────────────────────────────────
|
|
17
|
+
name: 'Minha Loja',
|
|
18
|
+
tagline: 'Os melhores produtos para você',
|
|
19
|
+
|
|
20
|
+
/** Emoji, text, or relative URL to an image (e.g. "/logo.png") */
|
|
21
|
+
logo: '🛒',
|
|
22
|
+
|
|
23
|
+
/** Canonical URL — used in legal pages and meta tags */
|
|
24
|
+
url: 'https://minhaloja.com.br',
|
|
25
|
+
|
|
26
|
+
// ── Contact ────────────────────────────────────────────────────────────────
|
|
27
|
+
supportEmail: 'suporte@minhaloja.com.br',
|
|
28
|
+
|
|
29
|
+
/** Data Protection Officer — required by LGPD art. 5, XVIII */
|
|
30
|
+
privacyEmail: 'privacidade@minhaloja.com.br',
|
|
31
|
+
|
|
32
|
+
// ── Legal (required for Brazilian e-commerce — Lei 7.962/2013) ─────────────
|
|
33
|
+
legal: {
|
|
34
|
+
companyName: 'Minha Loja LTDA',
|
|
35
|
+
cnpj: '00.000.000/0001-00',
|
|
36
|
+
address: 'Rua Exemplo, 123 — São Paulo, SP, CEP 01000-000',
|
|
37
|
+
|
|
38
|
+
/** Date the current Terms of Service / Privacy Policy became effective */
|
|
39
|
+
termsEffectiveDate: '1º de janeiro de 2025',
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
// ── Social ─────────────────────────────────────────────────────────────────
|
|
43
|
+
social: {
|
|
44
|
+
instagram: '',
|
|
45
|
+
twitter: '',
|
|
46
|
+
facebook: '',
|
|
47
|
+
whatsapp: '',
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
// ── Cookie consent ─────────────────────────────────────────────────────────
|
|
51
|
+
cookies: {
|
|
52
|
+
/** localStorage key used to store the user's consent decision */
|
|
53
|
+
storageKey: 'cookieConsent',
|
|
54
|
+
},
|
|
55
|
+
} as const;
|
|
56
|
+
|
|
57
|
+
export type SiteConfig = typeof siteConfig;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { siteConfig } from '../config/siteConfig';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sets document.title to "<title> | <siteConfig.name>" while the component is
|
|
6
|
+
* mounted, then restores the base site name on unmount.
|
|
7
|
+
*/
|
|
8
|
+
export function usePageTitle(title: string) {
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const prev = document.title;
|
|
11
|
+
document.title = title ? `${title} | ${siteConfig.name}` : siteConfig.name;
|
|
12
|
+
return () => {
|
|
13
|
+
document.title = prev;
|
|
14
|
+
};
|
|
15
|
+
}, [title]);
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useAuthStore } from '../../modules/auth/useAuthStore';
|
|
2
|
+
|
|
3
|
+
export async function apiFetch<T>(url: string, opts: RequestInit = {}): Promise<T> {
|
|
4
|
+
const token = useAuthStore.getState().accessToken;
|
|
5
|
+
const res = await fetch(url, {
|
|
6
|
+
...opts,
|
|
7
|
+
credentials: 'include', // always send httpOnly cookies (e.g. refreshToken)
|
|
8
|
+
headers: {
|
|
9
|
+
'Content-Type': 'application/json',
|
|
10
|
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
11
|
+
...(opts.headers as Record<string, string> | undefined),
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
15
|
+
return res.json() as Promise<T>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Link } from 'react-router-dom';
|
|
2
|
+
import { siteConfig } from '../config/siteConfig';
|
|
3
|
+
|
|
4
|
+
export function NotFoundPage() {
|
|
5
|
+
return (
|
|
6
|
+
<main
|
|
7
|
+
style={{
|
|
8
|
+
textAlign: 'center',
|
|
9
|
+
padding: '5rem 2rem',
|
|
10
|
+
display: 'flex',
|
|
11
|
+
flexDirection: 'column',
|
|
12
|
+
alignItems: 'center',
|
|
13
|
+
gap: '1rem',
|
|
14
|
+
}}
|
|
15
|
+
>
|
|
16
|
+
<p style={{ fontSize: '6rem', lineHeight: 1, fontWeight: 800, color: '#e5e7eb' }}>
|
|
17
|
+
404
|
|
18
|
+
</p>
|
|
19
|
+
<h1 style={{ fontSize: '1.5rem', fontWeight: 700, color: '#111827' }}>
|
|
20
|
+
Página não encontrada
|
|
21
|
+
</h1>
|
|
22
|
+
<p style={{ color: '#6b7280', maxWidth: '360px' }}>
|
|
23
|
+
O endereço que você tentou acessar não existe ou foi removido.
|
|
24
|
+
</p>
|
|
25
|
+
<Link
|
|
26
|
+
to="/"
|
|
27
|
+
style={{
|
|
28
|
+
marginTop: '0.5rem',
|
|
29
|
+
background: 'var(--color-primary)',
|
|
30
|
+
color: '#fff',
|
|
31
|
+
textDecoration: 'none',
|
|
32
|
+
padding: '0.6rem 1.5rem',
|
|
33
|
+
borderRadius: '6px',
|
|
34
|
+
fontWeight: 600,
|
|
35
|
+
fontSize: '0.9rem',
|
|
36
|
+
}}
|
|
37
|
+
>
|
|
38
|
+
Voltar para {siteConfig.name}
|
|
39
|
+
</Link>
|
|
40
|
+
</main>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createContext, useContext, useMemo, type ReactNode } from 'react';
|
|
2
|
+
import { type ThemeConfig } from './tokens';
|
|
3
|
+
import { createTheme, themeToCSSVars } from './createTheme';
|
|
4
|
+
|
|
5
|
+
type DeepPartial<T> = {
|
|
6
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// ── Context ───────────────────────────────────────────────────────────────────
|
|
10
|
+
interface ThemeContextValue {
|
|
11
|
+
theme: ThemeConfig;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const ThemeContext = createContext<ThemeContextValue | null>(null);
|
|
15
|
+
|
|
16
|
+
// ── Provider ──────────────────────────────────────────────────────────────────
|
|
17
|
+
interface ThemeProviderProps {
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
/**
|
|
20
|
+
* Partial theme overrides for white-label customisation.
|
|
21
|
+
* Only the keys you provide will differ from the default theme.
|
|
22
|
+
* Example: <ThemeProvider customTheme={{ colors: { primary: '#FF0000' } }}>
|
|
23
|
+
*/
|
|
24
|
+
customTheme?: DeepPartial<ThemeConfig>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function ThemeProvider({ children, customTheme }: ThemeProviderProps) {
|
|
28
|
+
const theme = useMemo(() => createTheme(customTheme), [customTheme]);
|
|
29
|
+
const cssVars = useMemo(() => themeToCSSVars(theme), [theme]);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<ThemeContext.Provider value={{ theme }}>
|
|
33
|
+
{/* The wrapper div injects all design tokens as CSS custom properties
|
|
34
|
+
so every descendant can use var(--color-primary) etc. */}
|
|
35
|
+
<div style={{ ...(cssVars as React.CSSProperties), background: 'var(--color-background)', color: 'var(--color-text)', fontFamily: 'var(--font-family)', minHeight: '100%' }}>{children}</div>
|
|
36
|
+
</ThemeContext.Provider>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// ── Consumer hook ─────────────────────────────────────────────────────────────
|
|
41
|
+
export function useTheme(): ThemeConfig {
|
|
42
|
+
const ctx = useContext(ThemeContext);
|
|
43
|
+
if (!ctx) throw new Error('useTheme must be used within a ThemeProvider');
|
|
44
|
+
return ctx.theme;
|
|
45
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { ThemeProvider, useTheme } from '../ThemeProvider';
|
|
3
|
+
|
|
4
|
+
// ── Helper component that exposes theme values via data-* attrs ─────────────
|
|
5
|
+
const ThemeConsumer = () => {
|
|
6
|
+
const theme = useTheme();
|
|
7
|
+
return (
|
|
8
|
+
<div
|
|
9
|
+
data-testid="consumer"
|
|
10
|
+
data-primary={theme.colors.primary}
|
|
11
|
+
data-store-name={theme.storeName}
|
|
12
|
+
>
|
|
13
|
+
consumer
|
|
14
|
+
</div>
|
|
15
|
+
);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// ── Tests ───────────────────────────────────────────────────────────────────
|
|
19
|
+
describe('ThemeProvider', () => {
|
|
20
|
+
it('deve renderizar filhos com o tema padrão', () => {
|
|
21
|
+
render(
|
|
22
|
+
<ThemeProvider>
|
|
23
|
+
<div>child content</div>
|
|
24
|
+
</ThemeProvider>,
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
expect(screen.getByText('child content')).toBeInTheDocument();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('deve sobrescrever cor primária via prop customTheme', () => {
|
|
31
|
+
render(
|
|
32
|
+
<ThemeProvider customTheme={{ colors: { primary: '#FF0000' } }}>
|
|
33
|
+
<ThemeConsumer />
|
|
34
|
+
</ThemeProvider>,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
expect(screen.getByTestId('consumer')).toHaveAttribute('data-primary', '#FF0000');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('deve manter demais tokens intactos ao sobrescrever apenas primary', () => {
|
|
41
|
+
render(
|
|
42
|
+
<ThemeProvider customTheme={{ colors: { primary: '#FF0000' } }}>
|
|
43
|
+
<ThemeConsumer />
|
|
44
|
+
</ThemeProvider>,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
// storeName não foi alterado — mantém o default
|
|
48
|
+
expect(screen.getByTestId('consumer')).toHaveAttribute('data-store-name', 'My Store');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('deve expor tokens CSS custom properties no DOM via inline style', () => {
|
|
52
|
+
const { container } = render(
|
|
53
|
+
<ThemeProvider>
|
|
54
|
+
<div>content</div>
|
|
55
|
+
</ThemeProvider>,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// ThemeProvider envolve os filhos num <div> com CSS vars aplicadas
|
|
59
|
+
const wrapper = container.firstChild as HTMLElement;
|
|
60
|
+
expect(wrapper.style.getPropertyValue('--color-primary')).not.toBe('');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('deve lançar erro ao usar useTheme fora do ThemeProvider', () => {
|
|
64
|
+
// Suppress the expected console.error from React during this test
|
|
65
|
+
const consoleError = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
66
|
+
|
|
67
|
+
const BareConsumer = () => {
|
|
68
|
+
useTheme(); // deve lançar
|
|
69
|
+
return <div />;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
expect(() => render(<BareConsumer />)).toThrow(
|
|
73
|
+
'useTheme must be used within a ThemeProvider',
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
consoleError.mockRestore();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ThemeConfig, defaultTheme } from './tokens';
|
|
2
|
+
|
|
3
|
+
type DeepPartial<T> = {
|
|
4
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Merges user overrides with the default theme.
|
|
9
|
+
* Only the top-level and second-level keys are merged (deep enough for the
|
|
10
|
+
* current data shape; extend if nesting grows).
|
|
11
|
+
*/
|
|
12
|
+
export function createTheme(overrides: DeepPartial<ThemeConfig> = {}): ThemeConfig {
|
|
13
|
+
return {
|
|
14
|
+
...defaultTheme,
|
|
15
|
+
...overrides,
|
|
16
|
+
colors: { ...defaultTheme.colors, ...overrides.colors },
|
|
17
|
+
typography: {
|
|
18
|
+
...defaultTheme.typography,
|
|
19
|
+
...overrides.typography,
|
|
20
|
+
fontSize: {
|
|
21
|
+
...defaultTheme.typography.fontSize,
|
|
22
|
+
...overrides.typography?.fontSize,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
borderRadius: { ...defaultTheme.borderRadius, ...overrides.borderRadius },
|
|
26
|
+
logo: { ...defaultTheme.logo, ...overrides.logo },
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Converts a ThemeConfig into a flat map of CSS custom properties.
|
|
32
|
+
* The result can be spread onto an element's inline style to expose
|
|
33
|
+
* the full design token set to all descendant components via var().
|
|
34
|
+
*/
|
|
35
|
+
export function themeToCSSVars(theme: ThemeConfig): Record<string, string> {
|
|
36
|
+
return {
|
|
37
|
+
'--color-primary': theme.colors.primary,
|
|
38
|
+
'--color-secondary': theme.colors.secondary,
|
|
39
|
+
'--color-accent': theme.colors.accent,
|
|
40
|
+
'--color-background': theme.colors.background,
|
|
41
|
+
'--color-surface': theme.colors.surface,
|
|
42
|
+
'--color-error': theme.colors.error,
|
|
43
|
+
'--color-text': theme.colors.text,
|
|
44
|
+
'--color-text-muted': theme.colors.textMuted,
|
|
45
|
+
'--font-family': theme.typography.fontFamily,
|
|
46
|
+
'--font-size-xs': theme.typography.fontSize.xs,
|
|
47
|
+
'--font-size-sm': theme.typography.fontSize.sm,
|
|
48
|
+
'--font-size-base': theme.typography.fontSize.base,
|
|
49
|
+
'--font-size-lg': theme.typography.fontSize.lg,
|
|
50
|
+
'--font-size-xl': theme.typography.fontSize.xl,
|
|
51
|
+
'--font-size-2xl': theme.typography.fontSize['2xl'],
|
|
52
|
+
'--font-size-3xl': theme.typography.fontSize['3xl'],
|
|
53
|
+
'--border-radius-sm': theme.borderRadius.sm,
|
|
54
|
+
'--border-radius-md': theme.borderRadius.md,
|
|
55
|
+
'--border-radius-lg': theme.borderRadius.lg,
|
|
56
|
+
'--border-radius-full': theme.borderRadius.full,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export interface ThemeColors {
|
|
2
|
+
primary: string;
|
|
3
|
+
secondary: string;
|
|
4
|
+
accent: string;
|
|
5
|
+
background: string;
|
|
6
|
+
surface: string;
|
|
7
|
+
error: string;
|
|
8
|
+
text: string;
|
|
9
|
+
textMuted: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ThemeTypography {
|
|
13
|
+
fontFamily: string;
|
|
14
|
+
fontSize: {
|
|
15
|
+
xs: string;
|
|
16
|
+
sm: string;
|
|
17
|
+
base: string;
|
|
18
|
+
lg: string;
|
|
19
|
+
xl: string;
|
|
20
|
+
'2xl': string;
|
|
21
|
+
'3xl': string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ThemeBorderRadius {
|
|
26
|
+
sm: string;
|
|
27
|
+
md: string;
|
|
28
|
+
lg: string;
|
|
29
|
+
full: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ThemeLogo {
|
|
33
|
+
src: string;
|
|
34
|
+
alt: string;
|
|
35
|
+
width: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ThemeConfig {
|
|
39
|
+
storeName: string;
|
|
40
|
+
colors: ThemeColors;
|
|
41
|
+
typography: ThemeTypography;
|
|
42
|
+
borderRadius: ThemeBorderRadius;
|
|
43
|
+
logo: ThemeLogo;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const defaultTheme: ThemeConfig = {
|
|
47
|
+
storeName: 'My Store',
|
|
48
|
+
colors: {
|
|
49
|
+
primary: '#6366F1',
|
|
50
|
+
secondary: '#8B5CF6',
|
|
51
|
+
accent: '#F59E0B',
|
|
52
|
+
background: '#F9FAFB',
|
|
53
|
+
surface: '#FFFFFF',
|
|
54
|
+
error: '#EF4444',
|
|
55
|
+
text: '#111827',
|
|
56
|
+
textMuted: '#6B7280',
|
|
57
|
+
},
|
|
58
|
+
typography: {
|
|
59
|
+
fontFamily: "'Inter', system-ui, sans-serif",
|
|
60
|
+
fontSize: {
|
|
61
|
+
xs: '0.75rem',
|
|
62
|
+
sm: '0.875rem',
|
|
63
|
+
base: '1rem',
|
|
64
|
+
lg: '1.125rem',
|
|
65
|
+
xl: '1.25rem',
|
|
66
|
+
'2xl': '1.5rem',
|
|
67
|
+
'3xl': '1.875rem',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
borderRadius: {
|
|
71
|
+
sm: '0.25rem',
|
|
72
|
+
md: '0.375rem',
|
|
73
|
+
lg: '0.5rem',
|
|
74
|
+
full: '9999px',
|
|
75
|
+
},
|
|
76
|
+
logo: {
|
|
77
|
+
src: '/logo.svg',
|
|
78
|
+
alt: 'My Store',
|
|
79
|
+
width: 120,
|
|
80
|
+
},
|
|
81
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|