kybernus 3.0.1 → 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/README.md +1 -1
- 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
- package/templates/java-spring/clean/.gitignore.hbs +72 -0
- package/templates/java-spring/clean/docker-compose.yml.hbs +6 -3
- package/templates/java-spring/clean/src/main/java/{{packagePath}}/application/usecase/PaymentUseCase.java.hbs +21 -17
- package/templates/java-spring/clean/src/main/java/{{packagePath}}/infrastructure/persistence/entity/UserEntity.java.hbs +52 -0
- package/templates/java-spring/clean/src/main/java/{{packagePath}}/infrastructure/persistence/repository/JpaUserRepository.java.hbs +12 -0
- package/templates/java-spring/clean/src/main/java/{{packagePath}}/infrastructure/security/JwtAuthenticationFilter.java.hbs +64 -0
- package/templates/java-spring/clean/src/main/java/{{packagePath}}/infrastructure/security/SecurityConfig.java.hbs +36 -0
- package/templates/java-spring/clean/src/main/java/{{packagePath}}/infrastructure/stripe/StripeGateway.java.hbs +63 -0
- package/templates/java-spring/clean/src/main/resources/application.properties.hbs +6 -7
- package/templates/java-spring/hexagonal/.gitignore.hbs +72 -0
- package/templates/java-spring/hexagonal/docker-compose.yml.hbs +6 -3
- package/templates/java-spring/hexagonal/src/main/java/{{packagePath}}/adapters/outbound/security/JwtFilter.java.hbs +71 -0
- package/templates/java-spring/hexagonal/src/main/java/{{packagePath}}/adapters/outbound/security/SecurityConfig.java.hbs +35 -0
- package/templates/java-spring/hexagonal/src/main/java/{{packagePath}}/core/service/PaymentService.java.hbs +3 -3
- package/templates/java-spring/hexagonal/src/main/resources/application.properties.hbs +4 -4
- package/templates/java-spring/mvc/.gitignore.hbs +72 -0
- package/templates/java-spring/mvc/docker-compose.yml.hbs +6 -3
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/config/SecurityConfig.java.hbs +13 -12
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/controller/AuthController.java.hbs +9 -8
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/controller/PaymentsController.java.hbs +5 -6
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/service/StripeService.java.hbs +3 -3
- package/templates/java-spring/mvc/src/main/resources/application.yml.hbs +29 -26
- package/templates/nestjs/clean/.gitignore.hbs +42 -0
- package/templates/nestjs/clean/Dockerfile.hbs +6 -3
- package/templates/nestjs/clean/docker-compose.yml.hbs +1 -11
- package/templates/nestjs/clean/src/app.module.ts.hbs +2 -1
- package/templates/nestjs/clean/src/application/payment.service.ts.hbs +72 -72
- package/templates/nestjs/clean/src/domain/entities/user.entity.ts.hbs +2 -2
- package/templates/nestjs/clean/src/domain/repositories/user.repository.ts.hbs +2 -2
- package/templates/nestjs/clean/src/infrastructure/database/repositories/prisma.user.repository.ts.hbs +18 -18
- package/templates/nestjs/clean/src/infrastructure/http/health.controller.ts.hbs +9 -0
- package/templates/nestjs/clean/src/main.ts.hbs +1 -4
- package/templates/nestjs/clean/src/payment.module.ts.hbs +12 -12
- package/templates/nestjs/hexagonal/.gitignore.hbs +42 -0
- package/templates/nestjs/hexagonal/Dockerfile.hbs +6 -3
- package/templates/nestjs/hexagonal/docker-compose.yml.hbs +1 -11
- package/templates/nestjs/hexagonal/src/adapters/inbound/health.controller.ts.hbs +9 -0
- package/templates/nestjs/hexagonal/src/app.module.ts.hbs +2 -1
- package/templates/nestjs/hexagonal/src/core/domain/user.entity.ts.hbs +6 -6
- package/templates/nestjs/hexagonal/src/core/ports/ports.ts.hbs +4 -4
- package/templates/nestjs/hexagonal/src/main.ts.hbs +1 -4
- package/templates/nestjs/mvc/.gitignore.hbs +42 -0
- package/templates/nestjs/mvc/Dockerfile.hbs +6 -3
- package/templates/nestjs/mvc/docker-compose.yml.hbs +1 -11
- package/templates/nestjs/mvc/src/auth/auth.controller.ts.hbs +11 -1
- package/templates/nestjs/mvc/src/auth/auth.service.ts.hbs +3 -1
- package/templates/nestjs/mvc/src/controllers/health.controller.ts.hbs +6 -6
- package/templates/nestjs/mvc/src/main.ts.hbs +1 -4
- package/templates/nestjs/mvc/src/models/create-item.dto.ts.hbs +5 -2
- package/templates/nestjs/mvc/src/prisma/prisma.service.ts.hbs +1 -0
- package/templates/nextjs/mvc/.gitignore.hbs +42 -0
- package/templates/nextjs/mvc/Dockerfile.hbs +23 -8
- package/templates/nextjs/mvc/docker-compose.yml.hbs +1 -1
- package/templates/nodejs-express/clean/.gitignore.hbs +42 -0
- package/templates/nodejs-express/clean/Dockerfile.hbs +6 -1
- package/templates/nodejs-express/clean/docker-compose.yml.hbs +2 -2
- package/templates/nodejs-express/clean/package.json.hbs +69 -69
- package/templates/nodejs-express/clean/src/config.ts.hbs +11 -0
- package/templates/nodejs-express/clean/src/domain/entities/User.ts.hbs +46 -8
- package/templates/nodejs-express/hexagonal/.gitignore.hbs +42 -0
- package/templates/nodejs-express/hexagonal/Dockerfile.hbs +1 -1
- package/templates/nodejs-express/hexagonal/docker-compose.yml.hbs +2 -2
- package/templates/nodejs-express/hexagonal/package.json.hbs +69 -69
- package/templates/nodejs-express/hexagonal/src/adapters/inbound/http/PaymentController.ts.hbs +21 -38
- package/templates/nodejs-express/hexagonal/src/adapters/outbound/persistence/prisma.ts.hbs +2 -0
- package/templates/nodejs-express/hexagonal/src/config.ts.hbs +9 -0
- package/templates/nodejs-express/hexagonal/src/core/AuthService.ts.hbs +5 -5
- package/templates/nodejs-express/hexagonal/src/core/PaymentService.ts.hbs +7 -22
- package/templates/nodejs-express/hexagonal/src/core/domain/entities/User.ts.hbs +24 -4
- package/templates/nodejs-express/mvc/.gitignore.hbs +42 -0
- package/templates/nodejs-express/mvc/package.json.hbs +67 -67
- package/templates/python-fastapi/clean/.gitignore.hbs +76 -0
- package/templates/python-fastapi/clean/app/application/services/payment_service.py.hbs +3 -3
- package/templates/python-fastapi/clean/app/config.py.hbs +6 -7
- package/templates/python-fastapi/clean/app/domain/usecases/login_user.py.hbs +15 -0
- package/templates/python-fastapi/clean/app/infrastructure/http/auth_controller.py.hbs +40 -6
- package/templates/python-fastapi/clean/app/infrastructure/http/payment_controller.py.hbs +5 -4
- package/templates/python-fastapi/clean/app/infrastructure/security/jwt.py.hbs +23 -0
- package/templates/python-fastapi/clean/app/main.py.hbs +3 -0
- package/templates/python-fastapi/clean/docker-compose.yml.hbs +5 -12
- package/templates/python-fastapi/clean/requirements.txt.hbs +3 -0
- package/templates/python-fastapi/hexagonal/.gitignore.hbs +76 -0
- package/templates/python-fastapi/hexagonal/app/adapters/inbound/http_adapter.py.hbs +6 -9
- package/templates/python-fastapi/hexagonal/app/adapters/inbound/payment_http_adapter.py.hbs +4 -3
- package/templates/python-fastapi/hexagonal/app/adapters/outbound/stripe_adapter.py.hbs +30 -19
- package/templates/python-fastapi/hexagonal/app/config.py.hbs +14 -4
- package/templates/python-fastapi/hexagonal/app/core/domain/user.py.hbs +3 -1
- package/templates/python-fastapi/hexagonal/app/core/payment_service.py.hbs +28 -18
- package/templates/python-fastapi/hexagonal/app/core/ports/__init__.py.hbs +3 -0
- package/templates/python-fastapi/hexagonal/app/core/ports/user_repository.py.hbs +15 -0
- package/templates/python-fastapi/hexagonal/app/infrastructure/database/session.py.hbs +7 -0
- package/templates/python-fastapi/hexagonal/app/infrastructure/database/user_repository.py.hbs +53 -0
- package/templates/python-fastapi/hexagonal/app/infrastructure/security/__init__.py.hbs +0 -0
- package/templates/python-fastapi/hexagonal/app/infrastructure/security/adapters.py.hbs +23 -0
- package/templates/python-fastapi/hexagonal/app/infrastructure/security/jwt.py.hbs +23 -0
- package/templates/python-fastapi/hexagonal/docker-compose.yml.hbs +5 -12
- package/templates/python-fastapi/hexagonal/requirements.txt.hbs +4 -0
- package/templates/python-fastapi/mvc/.gitignore.hbs +76 -0
- package/templates/python-fastapi/mvc/app/controllers/payments.py.hbs +3 -17
- package/templates/python-fastapi/mvc/app/middleware/security.py.hbs +24 -3
- package/templates/python-fastapi/mvc/app/schemas/item.py.hbs +3 -1
- package/templates/python-fastapi/mvc/docker-compose.yml.hbs +5 -12
- package/templates/python-fastapi/mvc/requirements.txt.hbs +3 -1
- package/templates/nodejs-express/hexagonal/src/adapters/outbound/persistence/prisma.ts +0 -5
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Link } from 'react-router-dom';
|
|
2
|
+
|
|
3
|
+
interface ProductVariant {
|
|
4
|
+
stock: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface ProductCardProps {
|
|
8
|
+
product: {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
slug: string;
|
|
12
|
+
price: number;
|
|
13
|
+
images: readonly string[];
|
|
14
|
+
variants: ProductVariant[];
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function ProductCard({ product }: ProductCardProps) {
|
|
19
|
+
const { name, slug, price, images, variants } = product;
|
|
20
|
+
const outOfStock = variants.length > 0 && variants.every((v) => v.stock === 0);
|
|
21
|
+
const formattedPrice = new Intl.NumberFormat('pt-BR', {
|
|
22
|
+
style: 'currency',
|
|
23
|
+
currency: 'BRL',
|
|
24
|
+
}).format(price);
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<Link
|
|
28
|
+
to={`/products/${slug}`}
|
|
29
|
+
style={{ textDecoration: 'none', color: 'inherit', display: 'block' }}
|
|
30
|
+
>
|
|
31
|
+
<div
|
|
32
|
+
style={{
|
|
33
|
+
background: '#ffffff',
|
|
34
|
+
border: '1px solid #e5e7eb',
|
|
35
|
+
borderRadius: '0.75rem',
|
|
36
|
+
overflow: 'hidden',
|
|
37
|
+
transition: 'box-shadow 0.18s ease, transform 0.18s ease',
|
|
38
|
+
cursor: 'pointer',
|
|
39
|
+
}}
|
|
40
|
+
onMouseEnter={(e) => {
|
|
41
|
+
const el = e.currentTarget as HTMLDivElement;
|
|
42
|
+
el.style.boxShadow = '0 8px 24px rgba(0,0,0,0.10)';
|
|
43
|
+
el.style.transform = 'translateY(-2px)';
|
|
44
|
+
}}
|
|
45
|
+
onMouseLeave={(e) => {
|
|
46
|
+
const el = e.currentTarget as HTMLDivElement;
|
|
47
|
+
el.style.boxShadow = 'none';
|
|
48
|
+
el.style.transform = 'none';
|
|
49
|
+
}}
|
|
50
|
+
>
|
|
51
|
+
{images[0] ? (
|
|
52
|
+
<img
|
|
53
|
+
src={images[0]}
|
|
54
|
+
alt={name}
|
|
55
|
+
style={{ width: '100%', aspectRatio: '1', objectFit: 'cover', display: 'block' }}
|
|
56
|
+
/>
|
|
57
|
+
) : (
|
|
58
|
+
<div style={{ width: '100%', aspectRatio: '1', background: '#f3f4f6', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: '2.5rem' }}>
|
|
59
|
+
🛍️
|
|
60
|
+
</div>
|
|
61
|
+
)}
|
|
62
|
+
<div style={{ padding: '0.875rem' }}>
|
|
63
|
+
<h2 style={{ fontSize: '0.9375rem', fontWeight: 600, marginBottom: '0.375rem', color: '#111827', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
|
|
64
|
+
{name}
|
|
65
|
+
</h2>
|
|
66
|
+
<p style={{ fontSize: '1rem', fontWeight: 700, color: '#6366f1' }}>
|
|
67
|
+
{formattedPrice}
|
|
68
|
+
</p>
|
|
69
|
+
{outOfStock && (
|
|
70
|
+
<span style={{ display: 'inline-block', marginTop: '0.375rem', fontSize: '0.75rem', background: '#fee2e2', color: '#dc2626', padding: '0.15rem 0.5rem', borderRadius: '9999px', fontWeight: 500 }}>
|
|
71
|
+
Sem Estoque
|
|
72
|
+
</span>
|
|
73
|
+
)}
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
</Link>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
interface Category {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
slug: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface Filters {
|
|
10
|
+
categorySlug?: string;
|
|
11
|
+
q?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface ProductFiltersProps {
|
|
15
|
+
categories: Category[];
|
|
16
|
+
onFilterChange: (filters: Record<string, unknown>) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function ProductFilters({ categories, onFilterChange }: ProductFiltersProps) {
|
|
20
|
+
const [filters, setFilters] = useState<Filters>({});
|
|
21
|
+
const debounceRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
22
|
+
|
|
23
|
+
function handleCategoryChange(e: React.ChangeEvent<HTMLSelectElement>) {
|
|
24
|
+
const value = e.target.value;
|
|
25
|
+
const next: Filters = value ? { ...filters, categorySlug: value } : { ...filters };
|
|
26
|
+
if (!value) delete next.categorySlug;
|
|
27
|
+
setFilters(next);
|
|
28
|
+
onFilterChange(value ? { categorySlug: value } : {});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function handleSearchChange(e: React.ChangeEvent<HTMLInputElement>) {
|
|
32
|
+
const value = e.target.value;
|
|
33
|
+
const next = { ...filters, q: value };
|
|
34
|
+
setFilters(next);
|
|
35
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
36
|
+
debounceRef.current = setTimeout(() => {
|
|
37
|
+
onFilterChange(value ? { q: value } : {});
|
|
38
|
+
}, 300);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function handleClear() {
|
|
42
|
+
setFilters({});
|
|
43
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
44
|
+
onFilterChange({});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
return () => {
|
|
49
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
50
|
+
};
|
|
51
|
+
}, []);
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<div style={{ display: 'flex', gap: '0.75rem', flexWrap: 'wrap', alignItems: 'center', marginBottom: '1.5rem' }}>
|
|
55
|
+
<select
|
|
56
|
+
aria-label="Filtrar por categoria"
|
|
57
|
+
value={filters.categorySlug ?? ''}
|
|
58
|
+
onChange={handleCategoryChange}
|
|
59
|
+
style={{ width: 'auto', minWidth: '180px' }}
|
|
60
|
+
>
|
|
61
|
+
<option value="">Todas as categorias</option>
|
|
62
|
+
{categories.map((cat) => (
|
|
63
|
+
<option key={cat.id} value={cat.slug}>
|
|
64
|
+
{cat.name}
|
|
65
|
+
</option>
|
|
66
|
+
))}
|
|
67
|
+
</select>
|
|
68
|
+
<input
|
|
69
|
+
type="text"
|
|
70
|
+
aria-label="Buscar produtos"
|
|
71
|
+
value={filters.q ?? ''}
|
|
72
|
+
onChange={handleSearchChange}
|
|
73
|
+
placeholder="Buscar produtos..."
|
|
74
|
+
style={{ width: 'auto', minWidth: '220px', flex: 1 }}
|
|
75
|
+
/>
|
|
76
|
+
<button
|
|
77
|
+
type="button"
|
|
78
|
+
onClick={handleClear}
|
|
79
|
+
style={{
|
|
80
|
+
padding: '0.5625rem 1rem',
|
|
81
|
+
background: 'transparent',
|
|
82
|
+
border: '1.5px solid #d1d5db',
|
|
83
|
+
borderRadius: '0.5rem',
|
|
84
|
+
color: '#6b7280',
|
|
85
|
+
fontWeight: 500,
|
|
86
|
+
fontSize: '0.875rem',
|
|
87
|
+
whiteSpace: 'nowrap',
|
|
88
|
+
transition: 'border-color 0.15s, color 0.15s',
|
|
89
|
+
width: 'auto',
|
|
90
|
+
}}
|
|
91
|
+
onMouseEnter={(e) => {
|
|
92
|
+
(e.currentTarget as HTMLButtonElement).style.borderColor = '#6366f1';
|
|
93
|
+
(e.currentTarget as HTMLButtonElement).style.color = '#6366f1';
|
|
94
|
+
}}
|
|
95
|
+
onMouseLeave={(e) => {
|
|
96
|
+
(e.currentTarget as HTMLButtonElement).style.borderColor = '#d1d5db';
|
|
97
|
+
(e.currentTarget as HTMLButtonElement).style.color = '#6b7280';
|
|
98
|
+
}}
|
|
99
|
+
>
|
|
100
|
+
Limpar
|
|
101
|
+
</button>
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { useParams, useNavigate } from 'react-router-dom';
|
|
3
|
+
import { apiFetch } from '../../../shared/lib/apiFetch';
|
|
4
|
+
import { useAuthStore } from '../../auth/useAuthStore';
|
|
5
|
+
import { usePageTitle } from '../../../shared/hooks/usePageTitle';
|
|
6
|
+
|
|
7
|
+
interface ProductVariant {
|
|
8
|
+
id: string;
|
|
9
|
+
sku: string;
|
|
10
|
+
size: string | null;
|
|
11
|
+
color: string | null;
|
|
12
|
+
stock: number;
|
|
13
|
+
price: number | null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface Product {
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
slug: string;
|
|
20
|
+
description: string | null;
|
|
21
|
+
price: number;
|
|
22
|
+
images: string[];
|
|
23
|
+
variants: ProductVariant[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function formatBRL(value: number) {
|
|
27
|
+
return value.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type AddStatus = 'idle' | 'adding' | 'added' | 'error';
|
|
31
|
+
|
|
32
|
+
export function ProductDetailPage() {
|
|
33
|
+
const { slug } = useParams<{ slug: string }>();
|
|
34
|
+
const navigate = useNavigate();
|
|
35
|
+
const accessToken = useAuthStore((s) => s.accessToken);
|
|
36
|
+
|
|
37
|
+
const [product, setProduct] = useState<Product | null>(null);
|
|
38
|
+
usePageTitle(product?.name ?? 'Produto');
|
|
39
|
+
const [selectedVariant, setSelectedVariant] = useState<ProductVariant | null>(null);
|
|
40
|
+
const [loading, setLoading] = useState(true);
|
|
41
|
+
const [error, setError] = useState('');
|
|
42
|
+
const [addStatus, setAddStatus] = useState<AddStatus>('idle');
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!slug) return;
|
|
46
|
+
setLoading(true);
|
|
47
|
+
apiFetch<Product>(`/api/products/${slug}`)
|
|
48
|
+
.then((p) => {
|
|
49
|
+
setProduct(p);
|
|
50
|
+
const inStock = p.variants.find((v) => v.stock > 0);
|
|
51
|
+
setSelectedVariant(inStock ?? p.variants[0] ?? null);
|
|
52
|
+
})
|
|
53
|
+
.catch(() => setError('Produto não encontrado'))
|
|
54
|
+
.finally(() => setLoading(false));
|
|
55
|
+
}, [slug]);
|
|
56
|
+
|
|
57
|
+
async function handleAddToCart() {
|
|
58
|
+
if (!accessToken) {
|
|
59
|
+
navigate('/login');
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (!selectedVariant) return;
|
|
63
|
+
setAddStatus('adding');
|
|
64
|
+
try {
|
|
65
|
+
await apiFetch('/api/cart/items', {
|
|
66
|
+
method: 'POST',
|
|
67
|
+
body: JSON.stringify({ variantId: selectedVariant.id, qty: 1 }),
|
|
68
|
+
});
|
|
69
|
+
setAddStatus('added');
|
|
70
|
+
setTimeout(() => setAddStatus('idle'), 2500);
|
|
71
|
+
} catch {
|
|
72
|
+
setAddStatus('error');
|
|
73
|
+
setTimeout(() => setAddStatus('idle'), 2500);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (loading) return <p style={{ marginTop: '2rem', color: 'var(--color-text-muted)' }}>Carregando...</p>;
|
|
78
|
+
if (error || !product) return <p role="alert" style={{ color: '#ef4444' }}>{error || 'Produto não encontrado'}</p>;
|
|
79
|
+
|
|
80
|
+
const inStock = selectedVariant ? selectedVariant.stock > 0 : product.variants.some((v) => v.stock > 0);
|
|
81
|
+
const addLabel =
|
|
82
|
+
addStatus === 'adding' ? 'Adicionando...' :
|
|
83
|
+
addStatus === 'added' ? '✓ Adicionado!' :
|
|
84
|
+
addStatus === 'error' ? 'Erro — tente novamente' :
|
|
85
|
+
'Adicionar ao carrinho';
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div style={{ maxWidth: 860 }}>
|
|
89
|
+
<button
|
|
90
|
+
type="button"
|
|
91
|
+
onClick={() => navigate(-1)}
|
|
92
|
+
style={{ background: 'none', border: 'none', cursor: 'pointer', color: 'var(--color-primary)', marginBottom: '1.5rem', padding: 0, fontSize: '0.95rem' }}
|
|
93
|
+
>
|
|
94
|
+
← Voltar
|
|
95
|
+
</button>
|
|
96
|
+
|
|
97
|
+
<div style={{ display: 'grid', gridTemplateColumns: product.images.length ? '1fr 1fr' : '1fr', gap: '2.5rem', alignItems: 'start' }}>
|
|
98
|
+
{product.images.length > 0 && (
|
|
99
|
+
<img
|
|
100
|
+
src={product.images[0]}
|
|
101
|
+
alt={product.name}
|
|
102
|
+
style={{ width: '100%', borderRadius: '10px', objectFit: 'cover', aspectRatio: '1' }}
|
|
103
|
+
/>
|
|
104
|
+
)}
|
|
105
|
+
|
|
106
|
+
<div>
|
|
107
|
+
<h1 style={{ marginBottom: '0.5rem', fontFamily: 'var(--font-family)', fontSize: '1.75rem' }}>
|
|
108
|
+
{product.name}
|
|
109
|
+
</h1>
|
|
110
|
+
<p style={{ fontSize: '2rem', fontWeight: 700, color: 'var(--color-primary)', marginBottom: '1rem' }}>
|
|
111
|
+
{formatBRL(product.price)}
|
|
112
|
+
</p>
|
|
113
|
+
|
|
114
|
+
{product.description && (
|
|
115
|
+
<p style={{ color: 'var(--color-text-muted)', marginBottom: '1.5rem', lineHeight: 1.65 }}>
|
|
116
|
+
{product.description}
|
|
117
|
+
</p>
|
|
118
|
+
)}
|
|
119
|
+
|
|
120
|
+
{product.variants.length > 1 && (
|
|
121
|
+
<div style={{ marginBottom: '1.5rem' }}>
|
|
122
|
+
<p style={{ fontWeight: 600, marginBottom: '0.5rem', fontSize: '0.9rem' }}>Variação</p>
|
|
123
|
+
<div style={{ display: 'flex', gap: '0.5rem', flexWrap: 'wrap' }}>
|
|
124
|
+
{product.variants.map((v) => {
|
|
125
|
+
const isSelected = selectedVariant?.id === v.id;
|
|
126
|
+
return (
|
|
127
|
+
<button
|
|
128
|
+
key={v.id}
|
|
129
|
+
type="button"
|
|
130
|
+
disabled={v.stock === 0}
|
|
131
|
+
onClick={() => setSelectedVariant(v)}
|
|
132
|
+
style={{
|
|
133
|
+
padding: '0.4rem 0.9rem',
|
|
134
|
+
border: `2px solid ${isSelected ? 'var(--color-primary)' : '#d1d5db'}`,
|
|
135
|
+
borderRadius: '5px',
|
|
136
|
+
cursor: v.stock === 0 ? 'not-allowed' : 'pointer',
|
|
137
|
+
opacity: v.stock === 0 ? 0.45 : 1,
|
|
138
|
+
background: isSelected ? 'var(--color-primary)' : 'white',
|
|
139
|
+
color: isSelected ? 'white' : 'inherit',
|
|
140
|
+
fontFamily: 'var(--font-family)',
|
|
141
|
+
}}
|
|
142
|
+
>
|
|
143
|
+
{v.size ?? v.color ?? v.sku}
|
|
144
|
+
</button>
|
|
145
|
+
);
|
|
146
|
+
})}
|
|
147
|
+
</div>
|
|
148
|
+
</div>
|
|
149
|
+
)}
|
|
150
|
+
|
|
151
|
+
{!inStock && (
|
|
152
|
+
<p style={{ color: '#ef4444', marginBottom: '1rem', fontWeight: 600 }}>Produto sem estoque</p>
|
|
153
|
+
)}
|
|
154
|
+
|
|
155
|
+
<button
|
|
156
|
+
type="button"
|
|
157
|
+
disabled={!inStock || addStatus === 'adding'}
|
|
158
|
+
onClick={handleAddToCart}
|
|
159
|
+
style={{
|
|
160
|
+
width: '100%',
|
|
161
|
+
padding: '0.85rem 1.5rem',
|
|
162
|
+
background: inStock ? 'var(--color-primary)' : '#9ca3af',
|
|
163
|
+
color: 'white',
|
|
164
|
+
border: 'none',
|
|
165
|
+
borderRadius: '7px',
|
|
166
|
+
fontSize: '1rem',
|
|
167
|
+
fontWeight: 600,
|
|
168
|
+
cursor: inStock ? 'pointer' : 'not-allowed',
|
|
169
|
+
fontFamily: 'var(--font-family)',
|
|
170
|
+
transition: 'opacity 0.15s',
|
|
171
|
+
}}
|
|
172
|
+
>
|
|
173
|
+
{addLabel}
|
|
174
|
+
</button>
|
|
175
|
+
</div>
|
|
176
|
+
</div>
|
|
177
|
+
</div>
|
|
178
|
+
);
|
|
179
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { useEffect, useState, useCallback } from 'react';
|
|
2
|
+
import { apiFetch } from '../../../shared/lib/apiFetch';
|
|
3
|
+
import { ProductCard } from '../components/ProductCard';
|
|
4
|
+
import { ProductFilters } from '../components/ProductFilters';
|
|
5
|
+
import { usePageTitle } from '../../../shared/hooks/usePageTitle';
|
|
6
|
+
|
|
7
|
+
interface Category {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
slug: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface ProductVariant {
|
|
14
|
+
id: string;
|
|
15
|
+
sku: string;
|
|
16
|
+
stock: number;
|
|
17
|
+
price: number | null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface Product {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
slug: string;
|
|
24
|
+
price: number;
|
|
25
|
+
images: string[];
|
|
26
|
+
variants: ProductVariant[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface ProductsResponse {
|
|
30
|
+
items: Product[];
|
|
31
|
+
nextCursor: string | null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function ProductListPage() {
|
|
35
|
+
usePageTitle('Produtos');
|
|
36
|
+
const [products, setProducts] = useState<Product[]>([]);
|
|
37
|
+
const [categories, setCategories] = useState<Category[]>([]);
|
|
38
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
39
|
+
const [error, setError] = useState('');
|
|
40
|
+
const [filters, setFilters] = useState<Record<string, unknown>>({});
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
apiFetch<{ data: Category[] }>('/api/categories')
|
|
44
|
+
.then((res) => setCategories(res.data))
|
|
45
|
+
.catch(() => {});
|
|
46
|
+
}, []);
|
|
47
|
+
|
|
48
|
+
const fetchProducts = useCallback(() => {
|
|
49
|
+
setIsLoading(true);
|
|
50
|
+
const params = new URLSearchParams();
|
|
51
|
+
if (filters['categorySlug']) params.set('categorySlug', String(filters['categorySlug']));
|
|
52
|
+
if (filters['q']) params.set('q', String(filters['q']));
|
|
53
|
+
const qs = params.toString();
|
|
54
|
+
apiFetch<ProductsResponse>(`/api/products${qs ? `?${qs}` : ''}`)
|
|
55
|
+
.then((res) => {
|
|
56
|
+
setProducts(res.items);
|
|
57
|
+
setError('');
|
|
58
|
+
})
|
|
59
|
+
.catch(() => setError('Erro ao carregar produtos'))
|
|
60
|
+
.finally(() => setIsLoading(false));
|
|
61
|
+
}, [filters]);
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
fetchProducts();
|
|
65
|
+
}, [fetchProducts]);
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div>
|
|
69
|
+
<h1 style={{ marginBottom: '1rem', fontFamily: 'var(--font-family)' }}>Produtos</h1>
|
|
70
|
+
<ProductFilters categories={categories} onFilterChange={setFilters} />
|
|
71
|
+
|
|
72
|
+
{isLoading && (
|
|
73
|
+
<p style={{ marginTop: '2rem', color: 'var(--color-text-muted)' }}>Carregando...</p>
|
|
74
|
+
)}
|
|
75
|
+
{error && (
|
|
76
|
+
<p role="alert" style={{ marginTop: '2rem', color: '#ef4444' }}>
|
|
77
|
+
{error}
|
|
78
|
+
</p>
|
|
79
|
+
)}
|
|
80
|
+
{!isLoading && !error && products.length === 0 && (
|
|
81
|
+
<p style={{ marginTop: '2rem', color: 'var(--color-text-muted)' }}>
|
|
82
|
+
Nenhum produto encontrado.
|
|
83
|
+
</p>
|
|
84
|
+
)}
|
|
85
|
+
|
|
86
|
+
<div
|
|
87
|
+
style={{
|
|
88
|
+
display: 'grid',
|
|
89
|
+
gridTemplateColumns: 'repeat(auto-fill, minmax(220px, 1fr))',
|
|
90
|
+
gap: '1.25rem',
|
|
91
|
+
marginTop: '1.5rem',
|
|
92
|
+
}}
|
|
93
|
+
>
|
|
94
|
+
{products.map((p) => (
|
|
95
|
+
<ProductCard key={p.id} product={p} />
|
|
96
|
+
))}
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CheckoutPage — Frontend Tests
|
|
3
|
+
* Stripe Elements are fully mocked.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
jest.mock('@stripe/react-stripe-js', () => ({
|
|
7
|
+
Elements: ({ children }: { children: React.ReactNode }) => <>{children}</>,
|
|
8
|
+
PaymentElement: () => <div data-testid="payment-element">PaymentElement mock</div>,
|
|
9
|
+
useStripe: () => mockStripe,
|
|
10
|
+
useElements: () => mockElements,
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
jest.mock('@stripe/stripe-js', () => ({
|
|
14
|
+
loadStripe: jest.fn().mockResolvedValue({}),
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
import React from 'react';
|
|
18
|
+
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
19
|
+
import userEvent from '@testing-library/user-event';
|
|
20
|
+
import { MemoryRouter, Routes, Route } from 'react-router-dom';
|
|
21
|
+
import { CheckoutPage } from '../pages/CheckoutPage';
|
|
22
|
+
|
|
23
|
+
const mockConfirmPayment = jest.fn();
|
|
24
|
+
const mockStripe = {
|
|
25
|
+
confirmPayment: mockConfirmPayment,
|
|
26
|
+
};
|
|
27
|
+
const mockElements = {};
|
|
28
|
+
|
|
29
|
+
// Cart summary fixture
|
|
30
|
+
const mockCart = {
|
|
31
|
+
items: [{ variantId: 'v1', productId: 'p1', name: 'Camiseta', sku: 'CAM-P', price: 99.9, qty: 2, image: null }],
|
|
32
|
+
subtotal: 199.8,
|
|
33
|
+
discount: 0,
|
|
34
|
+
total: 218.3,
|
|
35
|
+
couponCode: null,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
jest.mock('../hooks/useCheckout', () => ({
|
|
39
|
+
useCheckout: () => ({
|
|
40
|
+
cart: mockCart,
|
|
41
|
+
checkout: mockCheckout,
|
|
42
|
+
isLoading: false,
|
|
43
|
+
error: null,
|
|
44
|
+
}),
|
|
45
|
+
}));
|
|
46
|
+
|
|
47
|
+
const mockCheckout = jest.fn();
|
|
48
|
+
|
|
49
|
+
function renderPage() {
|
|
50
|
+
return render(
|
|
51
|
+
<MemoryRouter initialEntries={['/checkout']}>
|
|
52
|
+
<Routes>
|
|
53
|
+
<Route path="/checkout" element={<CheckoutPage />} />
|
|
54
|
+
<Route path="/checkout/success" element={<div>Sucesso!</div>} />
|
|
55
|
+
</Routes>
|
|
56
|
+
</MemoryRouter>,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function advanceToPayment(user: ReturnType<typeof userEvent.setup>) {
|
|
61
|
+
fireEvent.change(screen.getByLabelText(/rua|endere[çc]o/i), { target: { value: 'Rua das Flores, 100' } });
|
|
62
|
+
fireEvent.change(screen.getByLabelText(/cep/i), { target: { value: '01310-100' } });
|
|
63
|
+
await user.click(screen.getByRole('button', { name: /pr[oó]ximo|avan[çc]ar|continuar/i }));
|
|
64
|
+
await waitFor(() => screen.getByText(/frete/i));
|
|
65
|
+
await user.click(screen.getByRole('button', { name: /pr[oó]ximo|avan[çc]ar|continuar/i }));
|
|
66
|
+
await waitFor(() => screen.getByTestId('payment-element'));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
describe('CheckoutPage', () => {
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
jest.clearAllMocks();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('deve exibir resumo do carrinho', () => {
|
|
75
|
+
renderPage();
|
|
76
|
+
expect(screen.getByText('Camiseta')).toBeInTheDocument();
|
|
77
|
+
expect(screen.getByText(/R\$\s*199[,.]?8/)).toBeInTheDocument();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('deve progredir pelo stepper: Endereço → Frete → Pagamento', async () => {
|
|
81
|
+
renderPage();
|
|
82
|
+
const user = userEvent.setup();
|
|
83
|
+
|
|
84
|
+
// Should start on Endereço step
|
|
85
|
+
expect(screen.getByText(/endere[çc]o/i)).toBeInTheDocument();
|
|
86
|
+
|
|
87
|
+
// Fill address and advance
|
|
88
|
+
fireEvent.change(screen.getByLabelText(/rua|endere[çc]o/i), { target: { value: 'Rua das Flores, 100' } });
|
|
89
|
+
fireEvent.change(screen.getByLabelText(/cep/i), { target: { value: '01310-100' } });
|
|
90
|
+
await user.click(screen.getByRole('button', { name: /pr[oó]ximo|avan[çc]ar|continuar/i }));
|
|
91
|
+
|
|
92
|
+
// Frete step
|
|
93
|
+
await waitFor(() => expect(screen.getByText(/frete/i)).toBeInTheDocument());
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('deve renderizar o PaymentElement no step de Pagamento', async () => {
|
|
97
|
+
mockCheckout.mockResolvedValue({ orderId: 'ord-0', clientSecret: 'pi_secret_0' });
|
|
98
|
+
renderPage();
|
|
99
|
+
const user = userEvent.setup();
|
|
100
|
+
await advanceToPayment(user);
|
|
101
|
+
expect(screen.getByTestId('payment-element')).toBeInTheDocument();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('deve redirecionar para /checkout/success após pagamento confirmado', async () => {
|
|
105
|
+
mockCheckout.mockResolvedValue({ orderId: 'ord-1', clientSecret: 'pi_secret_1' });
|
|
106
|
+
mockConfirmPayment.mockResolvedValue({ error: undefined });
|
|
107
|
+
|
|
108
|
+
renderPage();
|
|
109
|
+
const user = userEvent.setup();
|
|
110
|
+
await advanceToPayment(user);
|
|
111
|
+
|
|
112
|
+
// Submit payment
|
|
113
|
+
await user.click(screen.getByRole('button', { name: /confirmar pagamento/i }));
|
|
114
|
+
|
|
115
|
+
await waitFor(() => expect(screen.getByText('Sucesso!')).toBeInTheDocument());
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('deve exibir erro se Stripe retornar erro de pagamento', async () => {
|
|
119
|
+
mockCheckout.mockResolvedValue({ orderId: 'ord-2', clientSecret: 'pi_secret_2' });
|
|
120
|
+
mockConfirmPayment.mockResolvedValue({
|
|
121
|
+
error: { code: 'card_declined', message: 'Cartão recusado.' },
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
renderPage();
|
|
125
|
+
const user = userEvent.setup();
|
|
126
|
+
await advanceToPayment(user);
|
|
127
|
+
await user.click(screen.getByRole('button', { name: /confirmar pagamento/i }));
|
|
128
|
+
|
|
129
|
+
await waitFor(() => expect(screen.getByText(/cart[aã]o recusado/i)).toBeInTheDocument());
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('deve exibir BoletoWaiting quando Stripe retornar boleto_display_details', async () => {
|
|
133
|
+
mockCheckout.mockResolvedValue({ orderId: 'ord-3', clientSecret: 'pi_secret_3' });
|
|
134
|
+
mockConfirmPayment.mockResolvedValue({
|
|
135
|
+
error: undefined,
|
|
136
|
+
paymentIntent: {
|
|
137
|
+
status: 'requires_action',
|
|
138
|
+
next_action: {
|
|
139
|
+
type: 'boleto_display_details',
|
|
140
|
+
boleto_display_details: {
|
|
141
|
+
expires_after: Math.floor(Date.now() / 1000) + 3 * 24 * 3600,
|
|
142
|
+
hosted_voucher_url: 'https://payments.stripe.com/boleto/voucher',
|
|
143
|
+
number: '23793.38128 60007.827136 96000.063305 4 94190000050000',
|
|
144
|
+
pdf: 'https://payments.stripe.com/boleto/pdf',
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
renderPage();
|
|
151
|
+
const user = userEvent.setup();
|
|
152
|
+
await advanceToPayment(user);
|
|
153
|
+
await user.click(screen.getByRole('button', { name: /confirmar pagamento/i }));
|
|
154
|
+
|
|
155
|
+
await waitFor(() => expect(screen.getByText(/boleto gerado/i)).toBeInTheDocument());
|
|
156
|
+
expect(screen.getByText(/3 dias úteis/i)).toBeInTheDocument();
|
|
157
|
+
expect(screen.getByRole('link', { name: /ver.*imprimir boleto/i })).toBeInTheDocument();
|
|
158
|
+
});
|
|
159
|
+
});
|