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,295 @@
|
|
|
1
|
+
# E-commerce Template — White-Label
|
|
2
|
+
|
|
3
|
+
Template completo de e-commerce pronto para produção: backend Express/TypeScript com Prisma + PostgreSQL + Redis, frontend React/Vite, pagamentos via Stripe (cartão, PIX, boleto), upload de imagens via S3/MinIO, e sistema de temas white-label totalmente personalizável.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Pré-requisitos
|
|
8
|
+
|
|
9
|
+
| Ferramenta | Versão mínima |
|
|
10
|
+
|---|---|
|
|
11
|
+
| Node.js | 20 LTS |
|
|
12
|
+
| npm | 10+ |
|
|
13
|
+
| Docker + Docker Compose | v2+ |
|
|
14
|
+
| Stripe CLI *(opcional, para webhooks locais)* | qualquer |
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Setup inicial (< 10 minutos)
|
|
19
|
+
|
|
20
|
+
### 1. Clone e instale dependências
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
git clone <seu-repo>
|
|
24
|
+
cd ecommerce
|
|
25
|
+
npm install
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 2. Configure as variáveis de ambiente
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
cp apps/api/.env.example apps/api/.env
|
|
32
|
+
cp apps/web/.env.example apps/web/.env
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Edite `apps/api/.env` com suas chaves do Stripe e demais configurações.
|
|
36
|
+
Para desenvolvimento local, os valores padrão já funcionam com o `docker-compose`.
|
|
37
|
+
|
|
38
|
+
### 3. Suba os serviços locais (Postgres, Redis, MinIO, Mailpit)
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
docker-compose up -d
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Isso sobe:
|
|
45
|
+
- **Postgres** na porta `5435`
|
|
46
|
+
- **Redis** na porta `6379`
|
|
47
|
+
- **MinIO** (S3 local) nas portas `9000` (API) e `9001` (console web)
|
|
48
|
+
- **Mailpit** (captura de emails) nas portas `1025` (SMTP) e `8025` (UI web)
|
|
49
|
+
|
|
50
|
+
### 4. Execute as migrations do banco
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm run db:migrate
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 5. (Opcional) Popule o banco com dados de teste
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm run db:seed
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 6. Inicie o projeto em modo desenvolvimento
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# Terminal 1 — API
|
|
66
|
+
npm run dev:api
|
|
67
|
+
|
|
68
|
+
# Terminal 2 — Frontend
|
|
69
|
+
npm run dev:web
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
- API: http://localhost:3000
|
|
73
|
+
- Frontend: http://localhost:5173
|
|
74
|
+
- Mailpit (emails): http://localhost:8025
|
|
75
|
+
- MinIO console: http://localhost:9001 (usuário: `minioadmin` / senha: `minioadmin`)
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Comandos disponíveis
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Desenvolvimento
|
|
83
|
+
npm run dev:api # Inicia API em watch mode (ts-node-dev)
|
|
84
|
+
npm run dev:web # Inicia frontend Vite em HMR
|
|
85
|
+
|
|
86
|
+
# Testes
|
|
87
|
+
npm run test:api # Testes unitários + integração da API (Jest)
|
|
88
|
+
npm run test:web # Testes do frontend (Jest + RTL)
|
|
89
|
+
npm run test # Todos os testes
|
|
90
|
+
|
|
91
|
+
# Build
|
|
92
|
+
npm run build # Compila API (tsc) + frontend (Vite)
|
|
93
|
+
|
|
94
|
+
# Banco de dados
|
|
95
|
+
npm run db:migrate # Aplica migrations pendentes (prisma migrate dev)
|
|
96
|
+
npm run db:seed # Popula com dados iniciais
|
|
97
|
+
npm run db:studio # Abre Prisma Studio (GUI do banco)
|
|
98
|
+
npm run db:reset # Reseta o banco e re-aplica migrations (⚠️ destrutivo)
|
|
99
|
+
|
|
100
|
+
# Qualidade
|
|
101
|
+
npm run lint # ESLint em todos os workspaces
|
|
102
|
+
npm run format # Prettier em todos os arquivos
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Estrutura do projeto
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
ecommerce/
|
|
111
|
+
├── apps/
|
|
112
|
+
│ ├── api/ # Backend Express + TypeScript
|
|
113
|
+
│ │ ├── src/
|
|
114
|
+
│ │ │ ├── modules/ # Módulos de domínio
|
|
115
|
+
│ │ │ │ ├── auth/ # JWT, login, registro, reset de senha
|
|
116
|
+
│ │ │ │ ├── catalog/ # Produtos, categorias, imagens
|
|
117
|
+
│ │ │ │ ├── cart/ # Carrinho (Redis)
|
|
118
|
+
│ │ │ │ ├── checkout/ # Criação de pedido + PaymentIntent Stripe
|
|
119
|
+
│ │ │ │ ├── orders/ # Histórico e detalhes de pedidos
|
|
120
|
+
│ │ │ │ ├── coupon/ # Cupons de desconto
|
|
121
|
+
│ │ │ │ ├── webhook/ # Stripe webhook handler
|
|
122
|
+
│ │ │ │ └── admin/ # Dashboard, usuários, relatórios
|
|
123
|
+
│ │ │ ├── shared/ # Middlewares, erros, utils
|
|
124
|
+
│ │ │ └── config/ # Env, DB (Prisma), Redis, S3, Email
|
|
125
|
+
│ │ └── prisma/
|
|
126
|
+
│ │ ├── schema.prisma # Schema de banco (fonte da verdade)
|
|
127
|
+
│ │ └── migrations/ # Histórico de migrations
|
|
128
|
+
│ └── web/ # Frontend React 18 + Vite
|
|
129
|
+
│ └── src/
|
|
130
|
+
│ ├── modules/ # Feature modules espelhando o backend
|
|
131
|
+
│ │ ├── auth/ # Login, registro, esqueci a senha
|
|
132
|
+
│ │ ├── catalog/ # Listagem e detalhe de produtos
|
|
133
|
+
│ │ ├── cart/ # Carrinho de compras
|
|
134
|
+
│ │ ├── checkout/ # Fluxo de pagamento (Stripe Elements)
|
|
135
|
+
│ │ ├── orders/ # Histórico de pedidos
|
|
136
|
+
│ │ ├── admin/ # Painel administrativo
|
|
137
|
+
│ │ └── legal/ # Termos de serviço e privacidade
|
|
138
|
+
│ └── shared/
|
|
139
|
+
│ ├── components/ # Layout, ErrorBoundary, guards
|
|
140
|
+
│ ├── config/ # siteConfig.ts ← WHITE-LABEL
|
|
141
|
+
│ ├── hooks/ # usePageTitle, etc.
|
|
142
|
+
│ └── theme/ # ThemeProvider ← COR PRIMÁRIA
|
|
143
|
+
├── scripts/
|
|
144
|
+
│ └── customize.sh # Script interativo de personalização
|
|
145
|
+
├── docker-compose.yml
|
|
146
|
+
├── Dockerfile # Multi-stage build da API
|
|
147
|
+
└── package.json # NPM Workspaces root
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Personalização white-label
|
|
153
|
+
|
|
154
|
+
### Método rápido — script interativo
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
bash scripts/customize.sh
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
O script pergunta nome da loja, CNPJ, email de suporte e cor primária, e edita automaticamente os arquivos certos.
|
|
161
|
+
|
|
162
|
+
### Método manual
|
|
163
|
+
|
|
164
|
+
**Identidade da loja** — edite `apps/web/src/shared/config/siteConfig.ts`:
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
export const siteConfig = {
|
|
168
|
+
name: 'Minha Loja', // Nome exibido no header e emails
|
|
169
|
+
tagline: 'Slogan aqui',
|
|
170
|
+
logo: '🛒', // Emoji, texto ou caminho de imagem
|
|
171
|
+
url: 'https://minhaloja.com.br',
|
|
172
|
+
supportEmail: 'suporte@minhaloja.com.br',
|
|
173
|
+
privacyEmail: 'privacidade@minhaloja.com.br',
|
|
174
|
+
legal: {
|
|
175
|
+
companyName: 'Minha Loja LTDA',
|
|
176
|
+
cnpj: '00.000.000/0001-00',
|
|
177
|
+
address: 'Rua Exemplo, 123 — São Paulo, SP',
|
|
178
|
+
termsEffectiveDate: '1º de janeiro de 2025',
|
|
179
|
+
},
|
|
180
|
+
// ...
|
|
181
|
+
};
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**Cor primária e tema** — edite `apps/web/src/shared/theme/tokens.ts`:
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
export const defaultTheme: ThemeConfig = {
|
|
188
|
+
storeName: 'Minha Loja',
|
|
189
|
+
colors: {
|
|
190
|
+
primary: '#6366F1', // ← Troque pela sua cor
|
|
191
|
+
// ...
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Todas as variáveis CSS (`--color-primary`, `--color-secondary`, etc.) são derivadas automaticamente pelo `ThemeProvider` e aplicadas via CSS custom properties em toda a aplicação.
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## Configuração do Stripe
|
|
201
|
+
|
|
202
|
+
### 1. Crie uma conta e obtenha as chaves de teste
|
|
203
|
+
|
|
204
|
+
Acesse https://dashboard.stripe.com/test/apikeys e copie:
|
|
205
|
+
- `sk_test_...` → `STRIPE_SECRET_KEY` em `apps/api/.env`
|
|
206
|
+
- `pk_test_...` → `VITE_STRIPE_PUBLIC_KEY` em `apps/web/.env`
|
|
207
|
+
|
|
208
|
+
### 2. Configure o webhook local (para receber eventos em dev)
|
|
209
|
+
|
|
210
|
+
Instale o [Stripe CLI](https://stripe.com/docs/stripe-cli) e execute:
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
stripe listen --forward-to localhost:3000/api/checkout/webhook
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Copie o `whsec_...` exibido no terminal para `STRIPE_WEBHOOK_SECRET` em `apps/api/.env`.
|
|
217
|
+
|
|
218
|
+
### 3. Métodos de pagamento habilitados
|
|
219
|
+
|
|
220
|
+
Por padrão o template suporta **cartão de crédito**, **PIX** e **boleto bancário**.
|
|
221
|
+
Para habilitar PIX e boleto, ative-os no [Dashboard Stripe](https://dashboard.stripe.com/settings/payment_methods) (requer conta verificada com CNPJ para produção).
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## Configuração de email
|
|
226
|
+
|
|
227
|
+
### Desenvolvimento
|
|
228
|
+
|
|
229
|
+
Em desenvolvimento, se `SMTP_HOST` não for definido, a API usa **[Ethereal](https://ethereal.email/)** — um SMTP faker que exibe os emails em `http://localhost:8025` (via Mailpit no docker-compose).
|
|
230
|
+
|
|
231
|
+
Alternativamente, deixe o compose subir o **Mailpit** (já configurado) e aponte:
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
SMTP_HOST=localhost
|
|
235
|
+
SMTP_PORT=1025
|
|
236
|
+
SMTP_USER= # vazio
|
|
237
|
+
SMTP_PASS= # vazio
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Produção
|
|
241
|
+
|
|
242
|
+
Configure com seu provedor SMTP (SendGrid, Resend, AWS SES, etc.):
|
|
243
|
+
|
|
244
|
+
```
|
|
245
|
+
SMTP_HOST=smtp.sendgrid.net
|
|
246
|
+
SMTP_PORT=587
|
|
247
|
+
SMTP_USER=apikey
|
|
248
|
+
SMTP_PASS=SG.xxx
|
|
249
|
+
EMAIL_FROM=noreply@minhaloja.com.br
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## Variáveis de ambiente
|
|
255
|
+
|
|
256
|
+
Todas as variáveis estão documentadas nos arquivos `.env.example`:
|
|
257
|
+
|
|
258
|
+
- `apps/api/.env.example` — banco, Redis, JWT, Stripe, SMTP, S3
|
|
259
|
+
- `apps/web/.env.example` — URL da API, chave pública do Stripe
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## Deploy
|
|
264
|
+
|
|
265
|
+
O `Dockerfile` na raiz realiza um build multi-stage:
|
|
266
|
+
|
|
267
|
+
1. **builder** — compila TypeScript e gera o Prisma Client
|
|
268
|
+
2. **runner** — imagem final com apenas dependências de produção (~200 MB)
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
# Build da imagem
|
|
272
|
+
docker build -t ecommerce-api .
|
|
273
|
+
|
|
274
|
+
# Run (passe as variáveis de ambiente necessárias)
|
|
275
|
+
docker run -e DATABASE_URL=... -e JWT_SECRET=... -p 3000:3000 ecommerce-api
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
O `docker-compose.yml` inclui o serviço `api` que faz o build automaticamente e executa `prisma migrate deploy` na inicialização.
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## Testes
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
npm run test:api # 208 testes — unitários + integração (Supertest + Jest)
|
|
286
|
+
npm run test:web # 73 testes — RTL + MSW mocking
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
Os testes de integração da API sobem um banco PostgreSQL real via Testcontainers (Docker necessário).
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
## Licença
|
|
294
|
+
|
|
295
|
+
MIT
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# apps/api/.env — fonte de verdade para desenvolvimento local
|
|
3
|
+
# Copie: cp apps/api/.env.example apps/api/.env
|
|
4
|
+
# Gere os segredos JWT com:
|
|
5
|
+
# node -e "console.log(require('crypto').randomBytes(48).toString('hex'))"
|
|
6
|
+
# =============================================================================
|
|
7
|
+
|
|
8
|
+
# ─── Database ────────────────────────────────────────────────────────────────
|
|
9
|
+
# docker-compose expõe o Postgres na porta 5435 (evita conflito com instâncias locais)
|
|
10
|
+
DATABASE_URL=postgresql://ecommerce:ecommerce@localhost:5435/ecommerce_dev
|
|
11
|
+
TEST_DATABASE_URL=postgresql://ecommerce:ecommerce@localhost:5435/ecommerce_test
|
|
12
|
+
|
|
13
|
+
# ─── Redis ────────────────────────────────────────────────────────────────────
|
|
14
|
+
REDIS_URL=redis://localhost:6379
|
|
15
|
+
|
|
16
|
+
# ─── JWT ─────────────────────────────────────────────────────────────────────
|
|
17
|
+
JWT_SECRET=troque-por-segredo-aleatorio-de-pelo-menos-48-chars
|
|
18
|
+
JWT_REFRESH_SECRET=troque-por-outro-segredo-aleatorio-de-pelo-menos-48-chars
|
|
19
|
+
JWT_RESET_SECRET=troque-por-mais-um-segredo-aleatorio-de-pelo-menos-48-chars
|
|
20
|
+
JWT_EXPIRES_IN=15m
|
|
21
|
+
JWT_REFRESH_EXPIRES_IN=7d
|
|
22
|
+
|
|
23
|
+
# ─── Stripe ───────────────────────────────────────────────────────────────────
|
|
24
|
+
# Chaves de teste: https://dashboard.stripe.com/test/apikeys
|
|
25
|
+
STRIPE_SECRET_KEY=sk_test_SUBSTITUA_PELA_SUA_CHAVE
|
|
26
|
+
# Webhook: stripe listen --forward-to localhost:3000/api/checkout/webhook
|
|
27
|
+
STRIPE_WEBHOOK_SECRET=whsec_SUBSTITUA_PELO_SEU_WEBHOOK_SECRET
|
|
28
|
+
|
|
29
|
+
# ─── Email ────────────────────────────────────────────────────────────────────
|
|
30
|
+
# Em dev, o sistema usa Ethereal automaticamente — não é preciso configurar nada.
|
|
31
|
+
# Para usar o Mailpit local (docker compose up mailpit), descomente abaixo:
|
|
32
|
+
# SMTP_HOST=localhost
|
|
33
|
+
# SMTP_PORT=1025
|
|
34
|
+
# SMTP_USER=
|
|
35
|
+
# SMTP_PASS=
|
|
36
|
+
# EMAIL_FROM=noreply@minhaloja.com.br
|
|
37
|
+
#
|
|
38
|
+
# Em produção (NODE_ENV=production), preencha com seu provedor real:
|
|
39
|
+
# SMTP_HOST=smtp.seudominio.com
|
|
40
|
+
# SMTP_PORT=587
|
|
41
|
+
# SMTP_USER=usuario@seudominio.com
|
|
42
|
+
# SMTP_PASS=sua-senha-smtp
|
|
43
|
+
# EMAIL_FROM=noreply@seudominio.com.br
|
|
44
|
+
|
|
45
|
+
# ─── Storage S3 / MinIO ───────────────────────────────────────────────────────
|
|
46
|
+
# Dev: MinIO via docker-compose (porta 9000). Console web: http://localhost:9001
|
|
47
|
+
# Produção: remova S3_ENDPOINT e use credenciais AWS reais.
|
|
48
|
+
S3_ENDPOINT=http://localhost:9000
|
|
49
|
+
S3_BUCKET=products
|
|
50
|
+
S3_REGION=us-east-1
|
|
51
|
+
AWS_ACCESS_KEY_ID=minioadmin
|
|
52
|
+
AWS_SECRET_ACCESS_KEY=minioadmin
|
|
53
|
+
|
|
54
|
+
# ─── App ──────────────────────────────────────────────────────────────────────
|
|
55
|
+
NODE_ENV=development
|
|
56
|
+
PORT=3000
|
|
57
|
+
CORS_ORIGIN=http://localhost:5174
|
|
58
|
+
FRONTEND_URL=http://localhost:5174
|
|
59
|
+
BASE_URL=http://localhost:3000
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Config } from 'jest';
|
|
2
|
+
|
|
3
|
+
const config: Config = {
|
|
4
|
+
preset: 'ts-jest',
|
|
5
|
+
testEnvironment: 'node',
|
|
6
|
+
rootDir: '.',
|
|
7
|
+
testMatch: ['<rootDir>/src/**/__tests__/**/*.test.ts'],
|
|
8
|
+
moduleNameMapper: {
|
|
9
|
+
'^@/(.*)$': '<rootDir>/src/$1',
|
|
10
|
+
},
|
|
11
|
+
transform: {
|
|
12
|
+
'^.+\\.ts$': [
|
|
13
|
+
'ts-jest',
|
|
14
|
+
{
|
|
15
|
+
tsconfig: {
|
|
16
|
+
module: 'commonjs',
|
|
17
|
+
moduleResolution: 'node',
|
|
18
|
+
esModuleInterop: true,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
coverageDirectory: 'coverage',
|
|
24
|
+
collectCoverageFrom: [
|
|
25
|
+
'src/**/*.ts',
|
|
26
|
+
'!src/**/*.d.ts',
|
|
27
|
+
'!src/server.ts',
|
|
28
|
+
],
|
|
29
|
+
coverageThreshold: {
|
|
30
|
+
global: {
|
|
31
|
+
branches: 80,
|
|
32
|
+
functions: 80,
|
|
33
|
+
lines: 80,
|
|
34
|
+
statements: 80,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
clearMocks: true,
|
|
38
|
+
restoreMocks: true,
|
|
39
|
+
setupFiles: ['<rootDir>/src/__tests__/setup.env.ts'],
|
|
40
|
+
// Exclude DB integration tests — run those with `npm run test:db`
|
|
41
|
+
// Exclude Ethereal email test — requires live network to smtp.ethereal.email
|
|
42
|
+
testPathIgnorePatterns: [
|
|
43
|
+
'/node_modules/',
|
|
44
|
+
'\.prisma\.repository\.test\.ts$',
|
|
45
|
+
'\.redis\.test\.ts$',
|
|
46
|
+
'ethereal\.email\.integration\.test\.ts$',
|
|
47
|
+
],
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default config;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Config } from 'jest';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Jest configuration for database integration tests.
|
|
5
|
+
* Requires PostgreSQL running (docker-compose up postgres).
|
|
6
|
+
*
|
|
7
|
+
* Run with: npm run test:db
|
|
8
|
+
*/
|
|
9
|
+
const config: Config = {
|
|
10
|
+
preset: 'ts-jest',
|
|
11
|
+
testEnvironment: 'node',
|
|
12
|
+
rootDir: '.',
|
|
13
|
+
// Match Prisma repository and Redis integration tests
|
|
14
|
+
testMatch: [
|
|
15
|
+
'<rootDir>/src/**/__tests__/**/*.prisma.repository.test.ts',
|
|
16
|
+
'<rootDir>/src/**/__tests__/**/*.redis.test.ts',
|
|
17
|
+
],
|
|
18
|
+
moduleNameMapper: {
|
|
19
|
+
'^@/(.*)$': '<rootDir>/src/$1',
|
|
20
|
+
},
|
|
21
|
+
transform: {
|
|
22
|
+
'^.+\\.ts$': [
|
|
23
|
+
'ts-jest',
|
|
24
|
+
{
|
|
25
|
+
tsconfig: {
|
|
26
|
+
module: 'commonjs',
|
|
27
|
+
moduleResolution: 'node',
|
|
28
|
+
esModuleInterop: true,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
// Runs once before all test workers: creates test DB + applies migrations
|
|
34
|
+
globalSetup: '<rootDir>/src/__tests__/globalSetup.ts',
|
|
35
|
+
// Runs once after all test workers finish: closes Redis connection
|
|
36
|
+
globalTeardown: '<rootDir>/src/__tests__/globalTeardown.ts',
|
|
37
|
+
// Runs in each worker: sets DATABASE_URL before any import
|
|
38
|
+
setupFiles: ['<rootDir>/src/__tests__/setup.db.ts'],
|
|
39
|
+
// Integration tests can be slower
|
|
40
|
+
testTimeout: 30_000,
|
|
41
|
+
clearMocks: true,
|
|
42
|
+
restoreMocks: true,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default config;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ecommerce/api",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"main": "dist/server.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"postinstall": "prisma generate",
|
|
8
|
+
"dev": "tsx watch src/server.ts",
|
|
9
|
+
"build": "tsc -p tsconfig.json",
|
|
10
|
+
"start": "node dist/server.js",
|
|
11
|
+
"test": "jest",
|
|
12
|
+
"test:coverage": "jest --coverage",
|
|
13
|
+
"test:db": "jest --config=jest.integration.config.ts",
|
|
14
|
+
"db:migrate": "prisma migrate dev",
|
|
15
|
+
"db:seed": "prisma db seed",
|
|
16
|
+
"db:studio": "prisma studio",
|
|
17
|
+
"db:generate": "prisma generate",
|
|
18
|
+
"db:reset": "prisma migrate reset --force"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@aws-sdk/client-s3": "^3.1004.0",
|
|
22
|
+
"@prisma/client": "^6.4.1",
|
|
23
|
+
"bcryptjs": "^2.4.3",
|
|
24
|
+
"cookie-parser": "^1.4.7",
|
|
25
|
+
"cors": "^2.8.5",
|
|
26
|
+
"dotenv": "^16.4.7",
|
|
27
|
+
"express": "^4.21.2",
|
|
28
|
+
"express-rate-limit": "^8.3.0",
|
|
29
|
+
"helmet": "^8.1.0",
|
|
30
|
+
"ioredis": "^5.4.2",
|
|
31
|
+
"jsonwebtoken": "^9.0.2",
|
|
32
|
+
"multer": "^2.1.1",
|
|
33
|
+
"nodemailer": "^8.0.1",
|
|
34
|
+
"stripe": "^17.7.0",
|
|
35
|
+
"zod": "^3.24.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/bcryptjs": "^2.4.6",
|
|
39
|
+
"@types/cookie-parser": "^1.4.8",
|
|
40
|
+
"@types/cors": "^2.8.17",
|
|
41
|
+
"@types/express": "^4.17.21",
|
|
42
|
+
"@types/jest": "^29.5.14",
|
|
43
|
+
"@types/jsonwebtoken": "^9.0.8",
|
|
44
|
+
"@types/multer": "^2.1.0",
|
|
45
|
+
"@types/node": "^22.13.4",
|
|
46
|
+
"@types/nodemailer": "^7.0.11",
|
|
47
|
+
"@types/supertest": "^6.0.2",
|
|
48
|
+
"jest": "^29.7.0",
|
|
49
|
+
"prisma": "^6.4.1",
|
|
50
|
+
"supertest": "^7.0.0",
|
|
51
|
+
"ts-jest": "^29.2.6",
|
|
52
|
+
"ts-node": "^10.9.2",
|
|
53
|
+
"tsx": "^4.19.2",
|
|
54
|
+
"typescript": "^5.7.3"
|
|
55
|
+
},
|
|
56
|
+
"prisma": {
|
|
57
|
+
"seed": "tsx prisma/seed.ts"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
-- CreateEnum
|
|
2
|
+
CREATE TYPE "Role" AS ENUM ('CUSTOMER', 'ADMIN');
|
|
3
|
+
|
|
4
|
+
-- CreateEnum
|
|
5
|
+
CREATE TYPE "ProductStatus" AS ENUM ('ACTIVE', 'INACTIVE', 'DELETED');
|
|
6
|
+
|
|
7
|
+
-- CreateEnum
|
|
8
|
+
CREATE TYPE "DiscountType" AS ENUM ('percent', 'fixed');
|
|
9
|
+
|
|
10
|
+
-- CreateEnum
|
|
11
|
+
CREATE TYPE "OrderStatus" AS ENUM ('PENDING', 'PAID', 'FAILED', 'SHIPPED', 'DELIVERED', 'CANCELLED');
|
|
12
|
+
|
|
13
|
+
-- CreateTable
|
|
14
|
+
CREATE TABLE "users" (
|
|
15
|
+
"id" TEXT NOT NULL,
|
|
16
|
+
"name" TEXT NOT NULL,
|
|
17
|
+
"email" TEXT NOT NULL,
|
|
18
|
+
"passwordHash" TEXT NOT NULL,
|
|
19
|
+
"role" "Role" NOT NULL DEFAULT 'CUSTOMER',
|
|
20
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
21
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
22
|
+
|
|
23
|
+
CONSTRAINT "users_pkey" PRIMARY KEY ("id")
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
-- CreateTable
|
|
27
|
+
CREATE TABLE "password_reset_tokens" (
|
|
28
|
+
"id" TEXT NOT NULL,
|
|
29
|
+
"token" TEXT NOT NULL,
|
|
30
|
+
"userId" TEXT NOT NULL,
|
|
31
|
+
"expiresAt" TIMESTAMP(3) NOT NULL,
|
|
32
|
+
"usedAt" TIMESTAMP(3),
|
|
33
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
34
|
+
|
|
35
|
+
CONSTRAINT "password_reset_tokens_pkey" PRIMARY KEY ("id")
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
-- CreateTable
|
|
39
|
+
CREATE TABLE "categories" (
|
|
40
|
+
"id" TEXT NOT NULL,
|
|
41
|
+
"name" TEXT NOT NULL,
|
|
42
|
+
"slug" TEXT NOT NULL,
|
|
43
|
+
"description" TEXT,
|
|
44
|
+
"parentId" TEXT,
|
|
45
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
46
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
47
|
+
|
|
48
|
+
CONSTRAINT "categories_pkey" PRIMARY KEY ("id")
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
-- CreateTable
|
|
52
|
+
CREATE TABLE "products" (
|
|
53
|
+
"id" TEXT NOT NULL,
|
|
54
|
+
"name" TEXT NOT NULL,
|
|
55
|
+
"slug" TEXT NOT NULL,
|
|
56
|
+
"description" TEXT,
|
|
57
|
+
"price" DECIMAL(10,2) NOT NULL,
|
|
58
|
+
"status" "ProductStatus" NOT NULL DEFAULT 'ACTIVE',
|
|
59
|
+
"categoryId" TEXT NOT NULL,
|
|
60
|
+
"images" TEXT[],
|
|
61
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
62
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
63
|
+
|
|
64
|
+
CONSTRAINT "products_pkey" PRIMARY KEY ("id")
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
-- CreateTable
|
|
68
|
+
CREATE TABLE "product_variants" (
|
|
69
|
+
"id" TEXT NOT NULL,
|
|
70
|
+
"sku" TEXT NOT NULL,
|
|
71
|
+
"size" TEXT,
|
|
72
|
+
"color" TEXT,
|
|
73
|
+
"stock" INTEGER NOT NULL DEFAULT 0,
|
|
74
|
+
"price" DECIMAL(10,2),
|
|
75
|
+
"productId" TEXT NOT NULL,
|
|
76
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
77
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
78
|
+
|
|
79
|
+
CONSTRAINT "product_variants_pkey" PRIMARY KEY ("id")
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
-- CreateTable
|
|
83
|
+
CREATE TABLE "coupons" (
|
|
84
|
+
"id" TEXT NOT NULL,
|
|
85
|
+
"code" TEXT NOT NULL,
|
|
86
|
+
"discountType" "DiscountType" NOT NULL,
|
|
87
|
+
"discountValue" DECIMAL(10,2) NOT NULL,
|
|
88
|
+
"minOrderValue" DECIMAL(10,2) NOT NULL DEFAULT 0,
|
|
89
|
+
"usageLimit" INTEGER,
|
|
90
|
+
"usageCount" INTEGER NOT NULL DEFAULT 0,
|
|
91
|
+
"expiresAt" TIMESTAMP(3),
|
|
92
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
93
|
+
|
|
94
|
+
CONSTRAINT "coupons_pkey" PRIMARY KEY ("id")
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
-- CreateTable
|
|
98
|
+
CREATE TABLE "orders" (
|
|
99
|
+
"id" TEXT NOT NULL,
|
|
100
|
+
"userId" TEXT NOT NULL,
|
|
101
|
+
"status" "OrderStatus" NOT NULL DEFAULT 'PENDING',
|
|
102
|
+
"subtotal" DECIMAL(10,2) NOT NULL,
|
|
103
|
+
"discount" DECIMAL(10,2) NOT NULL DEFAULT 0,
|
|
104
|
+
"shippingCost" DECIMAL(10,2) NOT NULL DEFAULT 0,
|
|
105
|
+
"tax" DECIMAL(10,2) NOT NULL DEFAULT 0,
|
|
106
|
+
"total" DECIMAL(10,2) NOT NULL,
|
|
107
|
+
"couponCode" TEXT,
|
|
108
|
+
"paymentIntentId" TEXT,
|
|
109
|
+
"trackingCode" TEXT,
|
|
110
|
+
"shippingAddress" JSONB,
|
|
111
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
112
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
113
|
+
|
|
114
|
+
CONSTRAINT "orders_pkey" PRIMARY KEY ("id")
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
-- CreateTable
|
|
118
|
+
CREATE TABLE "order_items" (
|
|
119
|
+
"id" TEXT NOT NULL,
|
|
120
|
+
"orderId" TEXT NOT NULL,
|
|
121
|
+
"variantId" TEXT NOT NULL,
|
|
122
|
+
"productId" TEXT NOT NULL,
|
|
123
|
+
"name" TEXT NOT NULL,
|
|
124
|
+
"sku" TEXT NOT NULL,
|
|
125
|
+
"price" DECIMAL(10,2) NOT NULL,
|
|
126
|
+
"qty" INTEGER NOT NULL,
|
|
127
|
+
"image" TEXT,
|
|
128
|
+
|
|
129
|
+
CONSTRAINT "order_items_pkey" PRIMARY KEY ("id")
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
-- CreateIndex
|
|
133
|
+
CREATE UNIQUE INDEX "users_email_key" ON "users"("email");
|
|
134
|
+
|
|
135
|
+
-- CreateIndex
|
|
136
|
+
CREATE UNIQUE INDEX "password_reset_tokens_token_key" ON "password_reset_tokens"("token");
|
|
137
|
+
|
|
138
|
+
-- CreateIndex
|
|
139
|
+
CREATE UNIQUE INDEX "categories_slug_key" ON "categories"("slug");
|
|
140
|
+
|
|
141
|
+
-- CreateIndex
|
|
142
|
+
CREATE UNIQUE INDEX "products_slug_key" ON "products"("slug");
|
|
143
|
+
|
|
144
|
+
-- CreateIndex
|
|
145
|
+
CREATE INDEX "products_categoryId_idx" ON "products"("categoryId");
|
|
146
|
+
|
|
147
|
+
-- CreateIndex
|
|
148
|
+
CREATE INDEX "products_status_idx" ON "products"("status");
|
|
149
|
+
|
|
150
|
+
-- CreateIndex
|
|
151
|
+
CREATE UNIQUE INDEX "product_variants_sku_key" ON "product_variants"("sku");
|
|
152
|
+
|
|
153
|
+
-- CreateIndex
|
|
154
|
+
CREATE INDEX "product_variants_productId_idx" ON "product_variants"("productId");
|
|
155
|
+
|
|
156
|
+
-- CreateIndex
|
|
157
|
+
CREATE UNIQUE INDEX "coupons_code_key" ON "coupons"("code");
|
|
158
|
+
|
|
159
|
+
-- CreateIndex
|
|
160
|
+
CREATE UNIQUE INDEX "orders_paymentIntentId_key" ON "orders"("paymentIntentId");
|
|
161
|
+
|
|
162
|
+
-- CreateIndex
|
|
163
|
+
CREATE INDEX "orders_userId_idx" ON "orders"("userId");
|
|
164
|
+
|
|
165
|
+
-- CreateIndex
|
|
166
|
+
CREATE INDEX "orders_status_idx" ON "orders"("status");
|
|
167
|
+
|
|
168
|
+
-- CreateIndex
|
|
169
|
+
CREATE INDEX "order_items_orderId_idx" ON "order_items"("orderId");
|
|
170
|
+
|
|
171
|
+
-- AddForeignKey
|
|
172
|
+
ALTER TABLE "password_reset_tokens" ADD CONSTRAINT "password_reset_tokens_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
173
|
+
|
|
174
|
+
-- AddForeignKey
|
|
175
|
+
ALTER TABLE "categories" ADD CONSTRAINT "categories_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "categories"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
176
|
+
|
|
177
|
+
-- AddForeignKey
|
|
178
|
+
ALTER TABLE "products" ADD CONSTRAINT "products_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "categories"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
179
|
+
|
|
180
|
+
-- AddForeignKey
|
|
181
|
+
ALTER TABLE "product_variants" ADD CONSTRAINT "product_variants_productId_fkey" FOREIGN KEY ("productId") REFERENCES "products"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
182
|
+
|
|
183
|
+
-- AddForeignKey
|
|
184
|
+
ALTER TABLE "order_items" ADD CONSTRAINT "order_items_orderId_fkey" FOREIGN KEY ("orderId") REFERENCES "orders"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|