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,149 @@
|
|
|
1
|
+
import type { PrismaClient, Order, OrderItem } from '@prisma/client';
|
|
2
|
+
import { OrderEntity } from '../../../../domain/checkout/order.entity';
|
|
3
|
+
import type { IOrderRepository } from '../../../../domain/checkout/order.repository';
|
|
4
|
+
import type { OrderStatus } from '../../../../domain/checkout/order.entity';
|
|
5
|
+
|
|
6
|
+
type OrderWithItems = Order & { items: OrderItem[] };
|
|
7
|
+
|
|
8
|
+
function toEntity(row: OrderWithItems): OrderEntity {
|
|
9
|
+
return OrderEntity.reconstitute({
|
|
10
|
+
id: row.id,
|
|
11
|
+
userId: row.userId,
|
|
12
|
+
status: row.status as OrderStatus,
|
|
13
|
+
items: row.items.map((i) => ({
|
|
14
|
+
id: i.id,
|
|
15
|
+
variantId: i.variantId,
|
|
16
|
+
productId: i.productId,
|
|
17
|
+
name: i.name,
|
|
18
|
+
sku: i.sku,
|
|
19
|
+
price: Number(i.price),
|
|
20
|
+
qty: i.qty,
|
|
21
|
+
image: i.image,
|
|
22
|
+
})),
|
|
23
|
+
subtotal: Number(row.subtotal),
|
|
24
|
+
discount: Number(row.discount),
|
|
25
|
+
shippingCost: Number(row.shippingCost),
|
|
26
|
+
tax: Number(row.tax),
|
|
27
|
+
total: Number(row.total),
|
|
28
|
+
couponCode: row.couponCode,
|
|
29
|
+
paymentIntentId: row.paymentIntentId,
|
|
30
|
+
trackingCode: row.trackingCode,
|
|
31
|
+
shippingAddress: row.shippingAddress as Record<string, string> | null,
|
|
32
|
+
createdAt: row.createdAt,
|
|
33
|
+
updatedAt: row.updatedAt,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const INCLUDE_ITEMS = { items: true } as const;
|
|
38
|
+
|
|
39
|
+
export class PrismaOrderRepository implements IOrderRepository {
|
|
40
|
+
constructor(private readonly db: PrismaClient) {}
|
|
41
|
+
|
|
42
|
+
async findById(id: string): Promise<OrderEntity | null> {
|
|
43
|
+
const row = await this.db.order.findUnique({
|
|
44
|
+
where: { id },
|
|
45
|
+
include: INCLUDE_ITEMS,
|
|
46
|
+
});
|
|
47
|
+
return row ? toEntity(row) : null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async findByPaymentIntentId(paymentIntentId: string): Promise<OrderEntity | null> {
|
|
51
|
+
const row = await this.db.order.findUnique({
|
|
52
|
+
where: { paymentIntentId },
|
|
53
|
+
include: INCLUDE_ITEMS,
|
|
54
|
+
});
|
|
55
|
+
return row ? toEntity(row) : null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async findByUserId(
|
|
59
|
+
userId: string,
|
|
60
|
+
opts: { cursor?: string; limit?: number } = {},
|
|
61
|
+
): Promise<{ items: OrderEntity[]; nextCursor: string | null }> {
|
|
62
|
+
const limit = opts.limit ?? 20;
|
|
63
|
+
|
|
64
|
+
const rows = await this.db.order.findMany({
|
|
65
|
+
where: { userId },
|
|
66
|
+
orderBy: { createdAt: 'desc' },
|
|
67
|
+
include: INCLUDE_ITEMS,
|
|
68
|
+
take: limit + 1,
|
|
69
|
+
...(opts.cursor ? { cursor: { id: opts.cursor }, skip: 1 } : {}),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const hasMore = rows.length > limit;
|
|
73
|
+
const items = hasMore ? rows.slice(0, limit) : rows;
|
|
74
|
+
const nextCursor = hasMore ? items[items.length - 1]!.id : null;
|
|
75
|
+
|
|
76
|
+
return { items: items.map(toEntity), nextCursor };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async findAll(
|
|
80
|
+
opts: { status?: OrderStatus; cursor?: string; limit?: number } = {},
|
|
81
|
+
): Promise<{ items: OrderEntity[]; nextCursor: string | null }> {
|
|
82
|
+
const limit = opts.limit ?? 20;
|
|
83
|
+
|
|
84
|
+
const rows = await this.db.order.findMany({
|
|
85
|
+
where: opts.status ? { status: opts.status } : undefined,
|
|
86
|
+
orderBy: { createdAt: 'desc' },
|
|
87
|
+
include: INCLUDE_ITEMS,
|
|
88
|
+
take: limit + 1,
|
|
89
|
+
...(opts.cursor ? { cursor: { id: opts.cursor }, skip: 1 } : {}),
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const hasMore = rows.length > limit;
|
|
93
|
+
const items = hasMore ? rows.slice(0, limit) : rows;
|
|
94
|
+
const nextCursor = hasMore ? items[items.length - 1]!.id : null;
|
|
95
|
+
|
|
96
|
+
return { items: items.map(toEntity), nextCursor };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async create(order: OrderEntity): Promise<OrderEntity> {
|
|
100
|
+
const row = await this.db.order.create({
|
|
101
|
+
data: {
|
|
102
|
+
id: order.id,
|
|
103
|
+
userId: order.userId,
|
|
104
|
+
status: order.status,
|
|
105
|
+
subtotal: order.subtotal,
|
|
106
|
+
discount: order.discount,
|
|
107
|
+
shippingCost: order.shippingCost,
|
|
108
|
+
tax: order.tax,
|
|
109
|
+
total: order.total,
|
|
110
|
+
couponCode: order.couponCode,
|
|
111
|
+
paymentIntentId: order.paymentIntentId,
|
|
112
|
+
trackingCode: order.trackingCode,
|
|
113
|
+
shippingAddress: order.shippingAddress ?? undefined,
|
|
114
|
+
createdAt: order.createdAt,
|
|
115
|
+
updatedAt: order.updatedAt,
|
|
116
|
+
items: {
|
|
117
|
+
createMany: {
|
|
118
|
+
data: order.items.map((i) => ({
|
|
119
|
+
id: i.id,
|
|
120
|
+
variantId: i.variantId,
|
|
121
|
+
productId: i.productId,
|
|
122
|
+
name: i.name,
|
|
123
|
+
sku: i.sku,
|
|
124
|
+
price: i.price,
|
|
125
|
+
qty: i.qty,
|
|
126
|
+
image: i.image,
|
|
127
|
+
})),
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
include: INCLUDE_ITEMS,
|
|
132
|
+
});
|
|
133
|
+
return toEntity(row);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async update(order: OrderEntity): Promise<OrderEntity> {
|
|
137
|
+
const row = await this.db.order.update({
|
|
138
|
+
where: { id: order.id },
|
|
139
|
+
data: {
|
|
140
|
+
status: order.status,
|
|
141
|
+
paymentIntentId: order.paymentIntentId,
|
|
142
|
+
trackingCode: order.trackingCode,
|
|
143
|
+
shippingAddress: order.shippingAddress ?? undefined,
|
|
144
|
+
},
|
|
145
|
+
include: INCLUDE_ITEMS,
|
|
146
|
+
});
|
|
147
|
+
return toEntity(row);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PrismaClient } from '@prisma/client';
|
|
2
|
+
|
|
3
|
+
// Prevent multiple PrismaClient instances in development / hot-reload
|
|
4
|
+
const globalForPrisma = globalThis as unknown as { prisma?: PrismaClient };
|
|
5
|
+
|
|
6
|
+
export const prisma =
|
|
7
|
+
globalForPrisma.prisma ??
|
|
8
|
+
new PrismaClient({
|
|
9
|
+
log:
|
|
10
|
+
process.env['NODE_ENV'] === 'development'
|
|
11
|
+
? ['query', 'error', 'warn']
|
|
12
|
+
: ['error'],
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
if (process.env['NODE_ENV'] !== 'production') {
|
|
16
|
+
globalForPrisma.prisma = prisma;
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IEmailService } from '../../../application/ports/email.port';
|
|
2
|
+
import { EtherealEmailService } from './ethereal.email.service';
|
|
3
|
+
import { SmtpEmailService } from './smtp.email.service';
|
|
4
|
+
import { NoopEmailService } from './noop.email.service';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Picks the email service implementation based on NODE_ENV.
|
|
8
|
+
* production → SmtpEmailService (real SMTP via env vars)
|
|
9
|
+
* test / test-inmemory → NoopEmailService (silent, no network calls)
|
|
10
|
+
* everything else → EtherealEmailService (fake SMTP, no real delivery)
|
|
11
|
+
*/
|
|
12
|
+
const env = process.env['NODE_ENV'];
|
|
13
|
+
export const emailService: IEmailService =
|
|
14
|
+
env === 'production'
|
|
15
|
+
? new SmtpEmailService()
|
|
16
|
+
: env === 'test' || env === 'test-inmemory'
|
|
17
|
+
? new NoopEmailService()
|
|
18
|
+
: new EtherealEmailService();
|
package/templates/ecommerce/apps/api/src/infrastructure/services/email/ethereal.email.service.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import nodemailer from 'nodemailer';
|
|
2
|
+
import type { IEmailService } from '../../../application/ports/email.port';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Email service that uses Ethereal (https://ethereal.email) — a fake SMTP
|
|
6
|
+
* server that captures messages without delivering them. Perfect for
|
|
7
|
+
* development and testing. Logs a preview URL to the console after each send.
|
|
8
|
+
*/
|
|
9
|
+
export class EtherealEmailService implements IEmailService {
|
|
10
|
+
private transporter: nodemailer.Transporter | null = null;
|
|
11
|
+
|
|
12
|
+
private async getTransporter(): Promise<nodemailer.Transporter> {
|
|
13
|
+
if (this.transporter) return this.transporter;
|
|
14
|
+
|
|
15
|
+
const testAccount = await nodemailer.createTestAccount();
|
|
16
|
+
this.transporter = nodemailer.createTransport({
|
|
17
|
+
host: 'smtp.ethereal.email',
|
|
18
|
+
port: 587,
|
|
19
|
+
auth: {
|
|
20
|
+
user: testAccount.user,
|
|
21
|
+
pass: testAccount.pass,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return this.transporter;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async send(to: string, subject: string, html: string): Promise<void> {
|
|
29
|
+
const transporter = await this.getTransporter();
|
|
30
|
+
const info = await transporter.sendMail({
|
|
31
|
+
from: process.env['EMAIL_FROM'] ?? 'noreply@example.com',
|
|
32
|
+
to,
|
|
33
|
+
subject,
|
|
34
|
+
html,
|
|
35
|
+
});
|
|
36
|
+
console.log(`[Ethereal Email] Preview URL: ${nodemailer.getTestMessageUrl(info)}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IEmailService } from '../../../application/ports/email.port';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* No-op email service used during tests.
|
|
5
|
+
* Silently discards all messages — no network calls, no side effects.
|
|
6
|
+
*/
|
|
7
|
+
export class NoopEmailService implements IEmailService {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9
|
+
async send(_to: string, _subject: string, _html: string): Promise<void> {
|
|
10
|
+
// intentionally empty
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import nodemailer from 'nodemailer';
|
|
2
|
+
import type { IEmailService } from '../../../application/ports/email.port';
|
|
3
|
+
import { AppError } from '../../../domain/shared/AppError';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Production email service that uses a real SMTP server configured via
|
|
7
|
+
* environment variables: SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS, EMAIL_FROM.
|
|
8
|
+
*/
|
|
9
|
+
export class SmtpEmailService implements IEmailService {
|
|
10
|
+
private readonly transporter: nodemailer.Transporter;
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
this.transporter = nodemailer.createTransport({
|
|
14
|
+
host: process.env['SMTP_HOST'],
|
|
15
|
+
port: parseInt(process.env['SMTP_PORT'] ?? '587', 10),
|
|
16
|
+
secure: process.env['SMTP_PORT'] === '465',
|
|
17
|
+
auth: {
|
|
18
|
+
user: process.env['SMTP_USER'],
|
|
19
|
+
pass: process.env['SMTP_PASS'],
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async send(to: string, subject: string, html: string): Promise<void> {
|
|
25
|
+
try {
|
|
26
|
+
await this.transporter.sendMail({
|
|
27
|
+
from: process.env['EMAIL_FROM'] ?? 'noreply@example.com',
|
|
28
|
+
to,
|
|
29
|
+
subject,
|
|
30
|
+
html,
|
|
31
|
+
});
|
|
32
|
+
} catch {
|
|
33
|
+
throw new AppError('Falha ao enviar email', 500);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
package/templates/ecommerce/apps/api/src/infrastructure/services/payment/stripe-webhook.handler.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import Stripe from 'stripe';
|
|
2
|
+
import { AppError } from '../../../domain/shared/AppError';
|
|
3
|
+
import type { IOrderRepository } from '../../../domain/checkout/order.repository';
|
|
4
|
+
import type { ICouponRepository } from '../../../domain/cart/coupon.repository';
|
|
5
|
+
import type { IEmailService } from '../../../application/ports/email.port';
|
|
6
|
+
import type { IUserRepository } from '../../../domain/auth/user.repository';
|
|
7
|
+
import { OrderEntity } from '../../../domain/checkout/order.entity';
|
|
8
|
+
|
|
9
|
+
export class StripeWebhookHandler {
|
|
10
|
+
private readonly stripe: Stripe;
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
secretKey: string,
|
|
14
|
+
private readonly webhookSecret: string,
|
|
15
|
+
private readonly orderRepo: IOrderRepository,
|
|
16
|
+
private readonly couponRepo?: ICouponRepository,
|
|
17
|
+
private readonly emailService?: IEmailService,
|
|
18
|
+
private readonly userRepo?: IUserRepository,
|
|
19
|
+
) {
|
|
20
|
+
this.stripe = new Stripe(secretKey);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async handleEvent(payload: string, signature: string): Promise<void> {
|
|
24
|
+
let event: Stripe.Event;
|
|
25
|
+
try {
|
|
26
|
+
event = this.stripe.webhooks.constructEvent(payload, signature, this.webhookSecret);
|
|
27
|
+
} catch {
|
|
28
|
+
throw new AppError('Webhook Stripe: assinatura inválida', 400);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
switch (event.type) {
|
|
32
|
+
case 'payment_intent.succeeded':
|
|
33
|
+
await this._handleSucceeded(event.data.object as Stripe.PaymentIntent);
|
|
34
|
+
break;
|
|
35
|
+
case 'payment_intent.payment_failed':
|
|
36
|
+
await this._handleFailed(event.data.object as Stripe.PaymentIntent);
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
// Unknown events are silently ignored
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private async _handleSucceeded(pi: Stripe.PaymentIntent): Promise<void> {
|
|
45
|
+
const order = await this.orderRepo.findByPaymentIntentId(pi.id);
|
|
46
|
+
if (!order) return; // Order not found — ignore
|
|
47
|
+
if (order.status === 'PAID') return; // Idempotent: already processed
|
|
48
|
+
const updated = order.pay();
|
|
49
|
+
await this.orderRepo.update(updated);
|
|
50
|
+
if (order.couponCode && this.couponRepo) {
|
|
51
|
+
await this.couponRepo.incrementUsage(order.couponCode);
|
|
52
|
+
}
|
|
53
|
+
await this._sendOrderConfirmedEmail(updated);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private async _sendOrderConfirmedEmail(order: OrderEntity): Promise<void> {
|
|
57
|
+
if (!this.emailService || !this.userRepo) return;
|
|
58
|
+
try {
|
|
59
|
+
const user = await this.userRepo.findById(order.userId);
|
|
60
|
+
if (!user) return;
|
|
61
|
+
const itemsHtml = order.items
|
|
62
|
+
.map((i) => `<li>${i.name} x${i.qty} — R$ ${(i.price * i.qty).toFixed(2)}</li>`)
|
|
63
|
+
.join('');
|
|
64
|
+
const html = `
|
|
65
|
+
<h2>Pedido confirmado!</h2>
|
|
66
|
+
<p>Olá ${user.name}, seu pedido <strong>#${order.id.slice(0, 8)}</strong> foi confirmado.</p>
|
|
67
|
+
<ul>${itemsHtml}</ul>
|
|
68
|
+
<p><strong>Total: R$ ${order.total.toFixed(2)}</strong></p>
|
|
69
|
+
<p>Prazo estimado de entrega: 5–10 dias úteis.</p>
|
|
70
|
+
`;
|
|
71
|
+
await this.emailService.send(user.email, 'Pedido confirmado 🎉', html);
|
|
72
|
+
} catch {
|
|
73
|
+
// Email failure must never break the webhook flow
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private async _handleFailed(pi: Stripe.PaymentIntent): Promise<void> {
|
|
78
|
+
const order = await this.orderRepo.findByPaymentIntentId(pi.id);
|
|
79
|
+
if (!order) return;
|
|
80
|
+
if (order.status === 'FAILED') return; // Idempotent
|
|
81
|
+
await this.orderRepo.update(order.fail());
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import Stripe from 'stripe';
|
|
2
|
+
import { IPaymentAdapter, PaymentError, PaymentIntentResult } from '../../../application/ports/payment.port';
|
|
3
|
+
|
|
4
|
+
export class StripeAdapter implements IPaymentAdapter {
|
|
5
|
+
private readonly stripe: Stripe;
|
|
6
|
+
|
|
7
|
+
constructor(secretKey: string) {
|
|
8
|
+
this.stripe = new Stripe(secretKey);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async createPaymentIntent(
|
|
12
|
+
amount: number,
|
|
13
|
+
currency: string,
|
|
14
|
+
metadata: Record<string, string>,
|
|
15
|
+
): Promise<PaymentIntentResult> {
|
|
16
|
+
try {
|
|
17
|
+
const intent = await this.stripe.paymentIntents.create({
|
|
18
|
+
amount: Math.round(amount * 100), // BRL → centavos
|
|
19
|
+
currency,
|
|
20
|
+
metadata,
|
|
21
|
+
automatic_payment_methods: { enabled: true },
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
if (!intent.client_secret) {
|
|
25
|
+
throw new PaymentError('missing_client_secret', 'Stripe não retornou client_secret');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return { id: intent.id, clientSecret: intent.client_secret };
|
|
29
|
+
} catch (err) {
|
|
30
|
+
if (err instanceof PaymentError) throw err;
|
|
31
|
+
// Wrap Stripe errors in a PaymentError so callers don't depend on Stripe types
|
|
32
|
+
const stripeErr = err as { type?: string; code?: string; message?: string };
|
|
33
|
+
throw new PaymentError(
|
|
34
|
+
stripeErr.code ?? stripeErr.type ?? 'stripe_error',
|
|
35
|
+
stripeErr.message ?? 'Erro no processamento do pagamento',
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
package/templates/ecommerce/apps/api/src/infrastructure/services/shipping/mock.shipping.service.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IShippingService, ShippingOption } from '../../../application/ports/shipping.port';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns deterministic mock options — pluggable with Correios / Melhor Envio
|
|
5
|
+
* in a real deployment by swapping the implementation.
|
|
6
|
+
*/
|
|
7
|
+
export class MockShippingService implements IShippingService {
|
|
8
|
+
async calculate(
|
|
9
|
+
_cep: string,
|
|
10
|
+
_items: Array<{ qty: number; weight?: number }>,
|
|
11
|
+
): Promise<ShippingOption[]> {
|
|
12
|
+
return [
|
|
13
|
+
{ name: 'PAC', price: 18.5, estimatedDays: 7 },
|
|
14
|
+
{ name: 'SEDEX', price: 32.0, estimatedDays: 2 },
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IStorageService } from '../../../application/ports/storage.port';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* In-memory storage — used in tests and when S3_BUCKET is not configured.
|
|
5
|
+
* Files are never persisted; returns a deterministic fake URL.
|
|
6
|
+
*/
|
|
7
|
+
export class InMemoryStorageService implements IStorageService {
|
|
8
|
+
async upload(key: string, _buffer: Buffer, _mimetype: string): Promise<string> {
|
|
9
|
+
return `http://storage.local/${key}`;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import type { IStorageService } from '../../../application/ports/storage.port';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* LocalDiskStorageService — persists uploaded files to the local filesystem
|
|
7
|
+
* under `apps/api/public/uploads/`. Used for local development when neither
|
|
8
|
+
* S3 nor MinIO is configured.
|
|
9
|
+
*
|
|
10
|
+
* Files are served by the Express static middleware at /public/uploads/<key>.
|
|
11
|
+
*/
|
|
12
|
+
export class LocalDiskStorageService implements IStorageService {
|
|
13
|
+
private readonly uploadDir: string;
|
|
14
|
+
|
|
15
|
+
constructor(uploadDir?: string) {
|
|
16
|
+
this.uploadDir =
|
|
17
|
+
uploadDir ?? path.join(__dirname, '../../../../../public/uploads');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async upload(key: string, buffer: Buffer, _mimetype: string): Promise<string> {
|
|
21
|
+
fs.mkdirSync(this.uploadDir, { recursive: true });
|
|
22
|
+
const filePath = path.join(this.uploadDir, key);
|
|
23
|
+
fs.writeFileSync(filePath, buffer);
|
|
24
|
+
const baseUrl = process.env['BASE_URL'] ?? 'http://localhost:3000';
|
|
25
|
+
return `${baseUrl}/public/uploads/${key}`;
|
|
26
|
+
}
|
|
27
|
+
}
|
package/templates/ecommerce/apps/api/src/infrastructure/services/storage/s3.storage.service.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3';
|
|
2
|
+
import type { IStorageService } from '../../../application/ports/storage.port';
|
|
3
|
+
import { AppError } from '../../../domain/shared/AppError';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* S3-compatible storage service.
|
|
7
|
+
* Points to AWS S3 in production.
|
|
8
|
+
* In dev/CI, override S3_ENDPOINT to use MinIO (http://localhost:9000).
|
|
9
|
+
*/
|
|
10
|
+
export class S3StorageService implements IStorageService {
|
|
11
|
+
private readonly client: S3Client;
|
|
12
|
+
private readonly bucket: string;
|
|
13
|
+
private readonly publicBase: string;
|
|
14
|
+
|
|
15
|
+
constructor() {
|
|
16
|
+
this.bucket = process.env['S3_BUCKET'] ?? 'products';
|
|
17
|
+
const region = process.env['S3_REGION'] ?? 'us-east-1';
|
|
18
|
+
const endpoint = process.env['S3_ENDPOINT'];
|
|
19
|
+
|
|
20
|
+
this.client = new S3Client({
|
|
21
|
+
region,
|
|
22
|
+
...(endpoint
|
|
23
|
+
? { endpoint, forcePathStyle: true }
|
|
24
|
+
: {}),
|
|
25
|
+
credentials: {
|
|
26
|
+
accessKeyId: process.env['AWS_ACCESS_KEY_ID'] ?? '',
|
|
27
|
+
secretAccessKey: process.env['AWS_SECRET_ACCESS_KEY'] ?? '',
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Public URL base: MinIO-style (endpoint/bucket) or S3 virtual-hosted
|
|
32
|
+
this.publicBase = endpoint
|
|
33
|
+
? `${endpoint}/${this.bucket}`
|
|
34
|
+
: `https://${this.bucket}.s3.${region}.amazonaws.com`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async upload(key: string, buffer: Buffer, mimetype: string): Promise<string> {
|
|
38
|
+
try {
|
|
39
|
+
await this.client.send(
|
|
40
|
+
new PutObjectCommand({
|
|
41
|
+
Bucket: this.bucket,
|
|
42
|
+
Key: key,
|
|
43
|
+
Body: buffer,
|
|
44
|
+
ContentType: mimetype,
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
return `${this.publicBase}/${key}`;
|
|
48
|
+
} catch {
|
|
49
|
+
throw new AppError('Falha ao fazer upload da imagem', 500);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IStorageService } from '../../../application/ports/storage.port';
|
|
2
|
+
import { S3StorageService } from './s3.storage.service';
|
|
3
|
+
import { InMemoryStorageService } from './in-memory.storage.service';
|
|
4
|
+
import { LocalDiskStorageService } from './local-disk.storage.service';
|
|
5
|
+
|
|
6
|
+
const env = process.env['NODE_ENV'];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Picks the storage implementation:
|
|
10
|
+
* test / test-inmemory → InMemoryStorageService (no disk I/O in tests)
|
|
11
|
+
* S3_BUCKET set → S3StorageService (real S3 or MinIO)
|
|
12
|
+
* Otherwise → LocalDiskStorageService (dev without MinIO)
|
|
13
|
+
*/
|
|
14
|
+
export const storageService: IStorageService =
|
|
15
|
+
env === 'test' || env === 'test-inmemory'
|
|
16
|
+
? new InMemoryStorageService()
|
|
17
|
+
: process.env['S3_BUCKET']
|
|
18
|
+
? new S3StorageService()
|
|
19
|
+
: new LocalDiskStorageService();
|
package/templates/ecommerce/apps/api/src/infrastructure/services/token/redis.token.blacklist.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Redis } from 'ioredis';
|
|
2
|
+
import type { ITokenBlacklist } from '../../../application/ports/token-blacklist.port';
|
|
3
|
+
|
|
4
|
+
const KEY_PREFIX = 'blacklist:';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Redis-backed token blacklist.
|
|
8
|
+
* Uses a simple SET with EX (TTL) — the key expires automatically, so no
|
|
9
|
+
* manual cleanup is needed.
|
|
10
|
+
*/
|
|
11
|
+
export class RedisTokenBlacklist implements ITokenBlacklist {
|
|
12
|
+
constructor(private readonly redis: Redis) {}
|
|
13
|
+
|
|
14
|
+
async add(jti: string, ttlSeconds: number): Promise<void> {
|
|
15
|
+
if (ttlSeconds <= 0) return; // token already expired — nothing to store
|
|
16
|
+
await this.redis.set(`${KEY_PREFIX}${jti}`, '1', 'EX', ttlSeconds);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async has(jti: string): Promise<boolean> {
|
|
20
|
+
const val = await this.redis.get(`${KEY_PREFIX}${jti}`);
|
|
21
|
+
return val !== null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ITokenBlacklist } from '../../../application/ports/token-blacklist.port';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* In-process implementation used for unit tests and dev when Redis is not
|
|
5
|
+
* available. Honors TTL via timestamp comparison.
|
|
6
|
+
*/
|
|
7
|
+
export class InMemoryTokenBlacklist implements ITokenBlacklist {
|
|
8
|
+
/** jti → expiry epoch-ms (0 = never expires) */
|
|
9
|
+
private readonly store = new Map<string, number>();
|
|
10
|
+
|
|
11
|
+
async add(jti: string, ttlSeconds: number): Promise<void> {
|
|
12
|
+
const expiry = ttlSeconds > 0 ? Date.now() + ttlSeconds * 1000 : 0;
|
|
13
|
+
this.store.set(jti, expiry);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async has(jti: string): Promise<boolean> {
|
|
17
|
+
const expiry = this.store.get(jti);
|
|
18
|
+
if (expiry === undefined) return false;
|
|
19
|
+
if (expiry !== 0 && Date.now() > expiry) {
|
|
20
|
+
this.store.delete(jti);
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Used in tests to reset state between cases. */
|
|
27
|
+
clear(): void {
|
|
28
|
+
this.store.clear();
|
|
29
|
+
}
|
|
30
|
+
}
|