create-huenei-template 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/templates.js +7 -0
- package/dist/templates/README.md +7 -1
- package/dist/templates/backend/README.md +19 -9
- package/dist/templates/backend/nestjs-api-mysql/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/agents/prisma-guardian.md +67 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/agents/test-runner.md +57 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/autoTestOnStop.ts +127 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/blockDangerous.ts +98 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/ensureTestsExist.ts +405 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/formatOnEdit.ts +70 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/protectSecrets.ts +101 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/sessionInit.ts +104 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/validatePrisma.ts +121 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks.json +46 -0
- package/dist/templates/backend/nestjs-api-mysql/README.md +26 -0
- package/dist/templates/backend/nestjs-api-mysql/eslint.config.mjs +1 -1
- package/dist/templates/backend/nestjs-api-mysql/package.json +7 -7
- package/dist/templates/backend/nestjs-api-postgres/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/agents/prisma-guardian.md +62 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/agents/security-auditor.md +71 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/agents/test-runner.md +58 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/auto-retry.ts +62 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/block-dangerous.ts +202 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/format-and-validate.ts +124 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/protect-secrets.ts +105 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/session-context.ts +130 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks.json +36 -0
- package/dist/templates/backend/nestjs-api-postgres/eslint.config.mjs +1 -1
- package/dist/templates/backend/nestjs-api-postgres/package.json +6 -6
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/code-reviewer.md +153 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/nestjs-architect.md +138 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/prisma-analyst.md +164 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/security-auditor.md +150 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/test-engineer.md +290 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/auto-format.ts +80 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/block-dangerous-commands.ts +144 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/prisma-schema-watcher.ts +64 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/protect-sensitive-files.ts +122 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/session-context.ts +105 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks.json +18 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/conventional-commits/SKILL.md +318 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/docker/SKILL.md +82 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/jest/SKILL.md +72 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/logging-best-practices/SKILL.md +127 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/prisma-database-setup/SKILL.md +186 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/quality-gates-enforcer/SKILL.md +301 -0
- package/dist/templates/backend/nestjs-api-sqlite/README.md +34 -1
- package/dist/templates/backend/nestjs-api-sqlite/eslint.config.mjs +1 -1
- package/dist/templates/backend/nestjs-api-sqlite/package.json +6 -6
- package/dist/templates/backend/nestjs-api-sqlite/prisma/schema.prisma +1 -0
- package/dist/templates/backend/nestjs-api-sqlite/prisma/seed.ts +2 -2
- package/dist/templates/backend/nestjs-api-sqlite/src/posts/dto/post-response.dto.ts +5 -1
- package/dist/templates/backend/nestjs-api-sqlite/src/users/dto/profile-response.dto.ts +1 -1
- package/dist/templates/backend/nestjs-api-sqlite/src/users/dto/update-profile.dto.ts +1 -1
- package/dist/templates/backend/nestjs-api-sqlite/src/users/dto/user-response.dto.ts +4 -0
- package/dist/templates/backend/nestjs-api-sqlite/src/users/profile.service.ts +24 -8
- package/dist/templates/backend/nestjs-api-sqlite/src/users/users.service.ts +1 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/agents/prisma-guardian.md +67 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/agents/test-runner.md +57 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/commands/new-endpoint.md +209 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/commands/new-model.md +201 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/autoTestOnStop.ts +127 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/blockDangerous.ts +98 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/ensureTestsExist.ts +405 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/formatOnEdit.ts +70 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/protectSecrets.ts +101 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/sessionInit.ts +104 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/validatePrisma.ts +121 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks.json +46 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/api-rest.mdc +126 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/authentication-security.mdc +86 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/dto-validation.mdc +93 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/general-rules.mdc +126 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/nestjs-architecture.mdc +83 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/prisma-standards.mdc +111 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/swagger-documentation.mdc +90 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/api-security-best-practices/SKILL.md +907 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/docker-expert/SKILL.md +409 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-expert/SKILL.md +552 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-the-best-practices/AGENTS.md +5958 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-the-best-practices/SKILL.md +130 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/nodejs-best-practices/SKILL.md +333 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/prisma-expert/SKILL.md +355 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/sqlserver-table-design/SKILL.md +125 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.dockerignore +50 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.env.example +17 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.env.test +17 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.prettierrc +4 -0
- package/dist/templates/backend/nestjs-api-sqlserver/README.md +587 -0
- package/dist/templates/backend/nestjs-api-sqlserver/docker-compose.yml +24 -0
- package/dist/templates/backend/nestjs-api-sqlserver/eslint.config.mjs +41 -0
- package/dist/templates/backend/nestjs-api-sqlserver/nest-cli.json +8 -0
- package/dist/templates/backend/nestjs-api-sqlserver/package.json +107 -0
- package/dist/templates/backend/nestjs-api-sqlserver/prisma/schema.prisma +70 -0
- package/dist/templates/backend/nestjs-api-sqlserver/prisma/seed.ts +215 -0
- package/dist/templates/backend/nestjs-api-sqlserver/prisma.config.ts +12 -0
- package/dist/templates/backend/nestjs-api-sqlserver/scripts/check-docker.js +64 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/app.module.ts +39 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/app.service.ts +8 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/auth.controller.ts +36 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/auth.module.ts +22 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/auth.service.ts +64 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/decorators/roles.decorator.ts +5 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/dto/login-response.dto.ts +23 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/dto/login.dto.ts +27 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/enums/role.enum.ts +5 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/guards/jwt-auth.guard.ts +20 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/guards/roles.guard.ts +23 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/strategies/jwt.strategy.ts +32 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/types.ts +18 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/common/dto/paginated-response.dto.ts +16 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/common/dto/pagination.dto.ts +31 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/common/filters/http-exception.filter.ts +53 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/config/env.validation.ts +41 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/health/health.controller.ts +35 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/health/health.module.ts +7 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/main.ts +87 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/dto/create-post.dto.ts +32 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/dto/post-response.dto.ts +41 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/dto/update-post.dto.ts +31 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/posts.controller.ts +161 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/posts.module.ts +12 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/posts.service.ts +171 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/prisma/prisma.module.ts +9 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/prisma/prisma.service.ts +62 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/constants/settings.constants.ts +9 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/profile-response.dto.ts +39 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/settings-response.dto.ts +18 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/update-profile.dto.ts +48 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/update-settings.dto.ts +40 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/user-response.dto.ts +18 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/profile.service.ts +67 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/settings.service.ts +77 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/users.controller.ts +102 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/users.module.ts +14 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/users.service.ts +27 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/README.md +412 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/e2e/auth.e2e-spec.ts +147 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/e2e/health.e2e-spec.ts +62 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/e2e/posts.e2e-spec.ts +407 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/e2e/users.e2e-spec.ts +287 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/fixtures/test-data.ts +109 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/helpers/auth.helper.ts +54 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/helpers/db.helper.ts +68 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/jest-e2e.json +12 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/setup-e2e.ts +8 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/app.service.spec.ts +24 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/auth.controller.spec.ts +91 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/auth.service.spec.ts +161 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/health.controller.spec.ts +78 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/http-exception.filter.spec.ts +150 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/jwt-auth.guard.spec.ts +50 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/jwt.strategy.spec.ts +41 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/posts.controller.spec.ts +249 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/posts.service.spec.ts +328 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/profile.service.spec.ts +146 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/settings.service.spec.ts +242 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/users.controller.spec.ts +178 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/users.service.spec.ts +96 -0
- package/dist/templates/backend/nestjs-api-sqlserver/tsconfig.build.json +4 -0
- package/dist/templates/backend/nestjs-api-sqlserver/tsconfig.json +28 -0
- package/dist/templates/frontend/angular-base/.cursor/agents/accessibility-reviewer.md +67 -0
- package/dist/templates/frontend/angular-base/.cursor/agents/angular-code-reviewer.md +60 -0
- package/dist/templates/frontend/angular-base/.cursor/agents/qa-test-expert.md +70 -0
- package/dist/templates/frontend/angular-base/.cursor/agents/security-auditor.md +58 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/auto-format.ts +70 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/auto-test-on-stop.ts +113 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/block-dangerous-commands.ts +160 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/ensure-tests-exist.ts +363 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/protect-sensitive-files.ts +118 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/session-context.ts +110 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks.json +41 -0
- package/dist/templates/frontend/angular-nx/.cursor/agents/angular-code-reviewer.md +64 -0
- package/dist/templates/frontend/angular-nx/.cursor/agents/nx-architecture-guardian.md +69 -0
- package/dist/templates/frontend/angular-nx/.cursor/agents/qa-test-expert.md +75 -0
- package/dist/templates/frontend/angular-nx/.cursor/agents/security-auditor.md +61 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/auto-format.ts +70 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/auto-test-on-stop.ts +115 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/block-dangerous-commands.ts +188 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/ensure-tests-exist.ts +399 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/protect-sensitive-files.ts +128 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/session-context.ts +121 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks.json +41 -0
- package/dist/templates/frontend/react-vite/.cursor/agents/frontend-senior.agent.md +49 -49
- package/dist/templates/frontend/react-vite/.cursor/agents/qa-test-expert.agent.md +126 -49
- package/dist/templates/frontend/react-vite/.cursor/agents/security-expert.agent.md +39 -39
- package/dist/templates/frontend/react-vite/.cursor/agents/ux-ui-expert.agent.md +45 -45
- package/dist/templates/frontend/react-vite/.cursor/hooks/autoTestOnStop.ts +117 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks/blockDangerous.ts +75 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks/ensureTestsExist.ts +306 -220
- package/dist/templates/frontend/react-vite/.cursor/hooks/formatOnEdit.ts +49 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks/protectSecrets.ts +88 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks/sessionInit.ts +77 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks.json +41 -10
- package/dist/templates/frontend/react-vite/.cursor/settings.json +13 -13
- package/dist/templates/frontend/react-vite/.vscode/settings.json +31 -31
- package/dist/templates/frontend/react-vite/README.md +34 -34
- package/dist/templates/frontend/react-vite/package.json +82 -82
- package/dist/templates/frontend/react-vite/pnpm-lock.yaml +6575 -6575
- package/dist/templates/frontend/react-vite/src/__tests__/components/layout/navbar.test.tsx +63 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/avatar.test.tsx +74 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/badge.test.tsx +55 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/breadcrumb.test.tsx +140 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/button.test.tsx +121 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/card.test.tsx +144 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/dialog.test.tsx +121 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/form.test.tsx +165 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/input.test.tsx +52 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/label.test.tsx +40 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/password-input.test.tsx +59 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/separator.test.tsx +40 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/table.test.tsx +254 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/tabs.test.tsx +82 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/textarea.test.tsx +47 -0
- package/dist/templates/frontend/react-vite/src/__tests__/helpers/render.tsx +114 -0
- package/dist/templates/frontend/react-vite/src/__tests__/hooks/useLocalStorage.test.ts +95 -0
- package/dist/templates/frontend/react-vite/src/__tests__/lib/queryClient.test.ts +24 -0
- package/dist/templates/frontend/react-vite/src/__tests__/lib/utils.test.ts +43 -0
- package/dist/templates/frontend/react-vite/src/__tests__/routes/index.test.tsx +111 -0
- package/dist/templates/frontend/react-vite/src/__tests__/routes/otra-ruta.test.tsx +126 -0
- package/dist/templates/frontend/react-vite/src/__tests__/routes/root.test.tsx +78 -0
- package/dist/templates/frontend/react-vite/src/__tests__/routes/ui-components.test.tsx +286 -0
- package/dist/templates/frontend/react-vite/src/components/layout/navbar.tsx +38 -38
- package/dist/templates/frontend/react-vite/src/components/ui/avatar.tsx +42 -42
- package/dist/templates/frontend/react-vite/src/components/ui/dialog.tsx +122 -122
- package/dist/templates/frontend/react-vite/src/components/ui/table.tsx +229 -244
- package/dist/templates/frontend/react-vite/src/hooks/useLocalStorage.ts +32 -32
- package/dist/templates/frontend/react-vite/src/routes/__root.tsx +48 -48
- package/dist/templates/frontend/react-vite/src/routes/ui-components.tsx +359 -85
- package/dist/templates/frontend/react-vite/src/test/setup.ts +24 -24
- package/dist/templates/frontend/react-vite/vite.config.ts +2 -2
- package/dist/templates/frontend/react-vite/vitest.config.ts +13 -2
- package/package.json +1 -1
- package/templates/README.md +7 -1
- package/templates/backend/README.md +19 -9
- package/templates/backend/nestjs-api-mysql/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/templates/backend/nestjs-api-mysql/.cursor/agents/prisma-guardian.md +67 -0
- package/templates/backend/nestjs-api-mysql/.cursor/agents/test-runner.md +57 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/autoTestOnStop.ts +127 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/blockDangerous.ts +98 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/ensureTestsExist.ts +405 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/formatOnEdit.ts +70 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/protectSecrets.ts +101 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/sessionInit.ts +104 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/validatePrisma.ts +121 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks.json +46 -0
- package/templates/backend/nestjs-api-mysql/README.md +26 -0
- package/templates/backend/nestjs-api-mysql/dist/tsconfig.build.tsbuildinfo +1 -1
- package/templates/backend/nestjs-api-mysql/eslint.config.mjs +1 -1
- package/templates/backend/nestjs-api-mysql/package.json +7 -7
- package/templates/backend/nestjs-api-postgres/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/templates/backend/nestjs-api-postgres/.cursor/agents/prisma-guardian.md +62 -0
- package/templates/backend/nestjs-api-postgres/.cursor/agents/security-auditor.md +71 -0
- package/templates/backend/nestjs-api-postgres/.cursor/agents/test-runner.md +58 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/auto-retry.ts +62 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/block-dangerous.ts +202 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/format-and-validate.ts +124 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/protect-secrets.ts +105 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/session-context.ts +130 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks.json +36 -0
- package/templates/backend/nestjs-api-postgres/eslint.config.mjs +1 -1
- package/templates/backend/nestjs-api-postgres/package.json +6 -6
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/code-reviewer.md +153 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/nestjs-architect.md +138 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/prisma-analyst.md +164 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/security-auditor.md +150 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/test-engineer.md +290 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/auto-format.ts +80 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/block-dangerous-commands.ts +144 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/prisma-schema-watcher.ts +64 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/protect-sensitive-files.ts +122 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/session-context.ts +105 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks.json +18 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/conventional-commits/SKILL.md +318 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/docker/SKILL.md +82 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/jest/SKILL.md +72 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/logging-best-practices/SKILL.md +127 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/prisma-database-setup/SKILL.md +186 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/quality-gates-enforcer/SKILL.md +301 -0
- package/templates/backend/nestjs-api-sqlite/README.md +34 -1
- package/templates/backend/nestjs-api-sqlite/eslint.config.mjs +1 -1
- package/templates/backend/nestjs-api-sqlite/package.json +6 -6
- package/templates/backend/nestjs-api-sqlite/prisma/schema.prisma +1 -0
- package/templates/backend/nestjs-api-sqlite/prisma/seed.ts +2 -2
- package/templates/backend/nestjs-api-sqlite/src/posts/dto/post-response.dto.ts +5 -1
- package/templates/backend/nestjs-api-sqlite/src/users/dto/profile-response.dto.ts +1 -1
- package/templates/backend/nestjs-api-sqlite/src/users/dto/update-profile.dto.ts +1 -1
- package/templates/backend/nestjs-api-sqlite/src/users/dto/user-response.dto.ts +4 -0
- package/templates/backend/nestjs-api-sqlite/src/users/profile.service.ts +24 -8
- package/templates/backend/nestjs-api-sqlite/src/users/users.service.ts +1 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/agents/prisma-guardian.md +67 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/agents/test-runner.md +57 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/commands/new-endpoint.md +209 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/commands/new-model.md +201 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/autoTestOnStop.ts +127 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/blockDangerous.ts +98 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/ensureTestsExist.ts +405 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/formatOnEdit.ts +70 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/protectSecrets.ts +101 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/sessionInit.ts +104 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/validatePrisma.ts +121 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks.json +46 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/api-rest.mdc +126 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/authentication-security.mdc +86 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/dto-validation.mdc +93 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/general-rules.mdc +126 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/nestjs-architecture.mdc +83 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/prisma-standards.mdc +111 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/swagger-documentation.mdc +90 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/api-security-best-practices/SKILL.md +907 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/docker-expert/SKILL.md +409 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-expert/SKILL.md +552 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-the-best-practices/AGENTS.md +5958 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-the-best-practices/SKILL.md +130 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/nodejs-best-practices/SKILL.md +333 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/prisma-expert/SKILL.md +355 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/sqlserver-table-design/SKILL.md +125 -0
- package/templates/backend/nestjs-api-sqlserver/.dockerignore +50 -0
- package/templates/backend/nestjs-api-sqlserver/.env.example +17 -0
- package/templates/backend/nestjs-api-sqlserver/.env.test +17 -0
- package/templates/backend/nestjs-api-sqlserver/.prettierrc +4 -0
- package/templates/backend/nestjs-api-sqlserver/README.md +587 -0
- package/templates/backend/nestjs-api-sqlserver/docker-compose.yml +24 -0
- package/templates/backend/nestjs-api-sqlserver/eslint.config.mjs +41 -0
- package/templates/backend/nestjs-api-sqlserver/nest-cli.json +8 -0
- package/templates/backend/nestjs-api-sqlserver/package.json +107 -0
- package/templates/backend/nestjs-api-sqlserver/prisma/schema.prisma +70 -0
- package/templates/backend/nestjs-api-sqlserver/prisma/seed.ts +215 -0
- package/templates/backend/nestjs-api-sqlserver/prisma.config.ts +12 -0
- package/templates/backend/nestjs-api-sqlserver/scripts/check-docker.js +64 -0
- package/templates/backend/nestjs-api-sqlserver/src/app.module.ts +39 -0
- package/templates/backend/nestjs-api-sqlserver/src/app.service.ts +8 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/auth.controller.ts +36 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/auth.module.ts +22 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/auth.service.ts +64 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/decorators/roles.decorator.ts +5 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/dto/login-response.dto.ts +23 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/dto/login.dto.ts +27 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/enums/role.enum.ts +5 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/guards/jwt-auth.guard.ts +20 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/guards/roles.guard.ts +23 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/strategies/jwt.strategy.ts +32 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/types.ts +18 -0
- package/templates/backend/nestjs-api-sqlserver/src/common/dto/paginated-response.dto.ts +16 -0
- package/templates/backend/nestjs-api-sqlserver/src/common/dto/pagination.dto.ts +31 -0
- package/templates/backend/nestjs-api-sqlserver/src/common/filters/http-exception.filter.ts +53 -0
- package/templates/backend/nestjs-api-sqlserver/src/config/env.validation.ts +41 -0
- package/templates/backend/nestjs-api-sqlserver/src/health/health.controller.ts +35 -0
- package/templates/backend/nestjs-api-sqlserver/src/health/health.module.ts +7 -0
- package/templates/backend/nestjs-api-sqlserver/src/main.ts +87 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/dto/create-post.dto.ts +32 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/dto/post-response.dto.ts +41 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/dto/update-post.dto.ts +31 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/posts.controller.ts +161 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/posts.module.ts +12 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/posts.service.ts +171 -0
- package/templates/backend/nestjs-api-sqlserver/src/prisma/prisma.module.ts +9 -0
- package/templates/backend/nestjs-api-sqlserver/src/prisma/prisma.service.ts +62 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/constants/settings.constants.ts +9 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/profile-response.dto.ts +39 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/settings-response.dto.ts +18 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/update-profile.dto.ts +48 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/update-settings.dto.ts +40 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/user-response.dto.ts +18 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/profile.service.ts +67 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/settings.service.ts +77 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/users.controller.ts +102 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/users.module.ts +14 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/users.service.ts +27 -0
- package/templates/backend/nestjs-api-sqlserver/test/README.md +412 -0
- package/templates/backend/nestjs-api-sqlserver/test/e2e/auth.e2e-spec.ts +147 -0
- package/templates/backend/nestjs-api-sqlserver/test/e2e/health.e2e-spec.ts +62 -0
- package/templates/backend/nestjs-api-sqlserver/test/e2e/posts.e2e-spec.ts +407 -0
- package/templates/backend/nestjs-api-sqlserver/test/e2e/users.e2e-spec.ts +287 -0
- package/templates/backend/nestjs-api-sqlserver/test/fixtures/test-data.ts +109 -0
- package/templates/backend/nestjs-api-sqlserver/test/helpers/auth.helper.ts +54 -0
- package/templates/backend/nestjs-api-sqlserver/test/helpers/db.helper.ts +68 -0
- package/templates/backend/nestjs-api-sqlserver/test/jest-e2e.json +12 -0
- package/templates/backend/nestjs-api-sqlserver/test/setup-e2e.ts +8 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/app.service.spec.ts +24 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/auth.controller.spec.ts +91 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/auth.service.spec.ts +161 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/health.controller.spec.ts +78 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/http-exception.filter.spec.ts +150 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/jwt-auth.guard.spec.ts +50 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/jwt.strategy.spec.ts +41 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/posts.controller.spec.ts +249 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/posts.service.spec.ts +328 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/profile.service.spec.ts +146 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/settings.service.spec.ts +242 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/users.controller.spec.ts +178 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/users.service.spec.ts +96 -0
- package/templates/backend/nestjs-api-sqlserver/tsconfig.build.json +4 -0
- package/templates/backend/nestjs-api-sqlserver/tsconfig.json +28 -0
- package/templates/frontend/angular-base/.cursor/agents/accessibility-reviewer.md +67 -0
- package/templates/frontend/angular-base/.cursor/agents/angular-code-reviewer.md +60 -0
- package/templates/frontend/angular-base/.cursor/agents/qa-test-expert.md +70 -0
- package/templates/frontend/angular-base/.cursor/agents/security-auditor.md +58 -0
- package/templates/frontend/angular-base/.cursor/hooks/auto-format.ts +70 -0
- package/templates/frontend/angular-base/.cursor/hooks/auto-test-on-stop.ts +113 -0
- package/templates/frontend/angular-base/.cursor/hooks/block-dangerous-commands.ts +160 -0
- package/templates/frontend/angular-base/.cursor/hooks/ensure-tests-exist.ts +363 -0
- package/templates/frontend/angular-base/.cursor/hooks/protect-sensitive-files.ts +118 -0
- package/templates/frontend/angular-base/.cursor/hooks/session-context.ts +110 -0
- package/templates/frontend/angular-base/.cursor/hooks.json +41 -0
- package/templates/frontend/angular-nx/.cursor/agents/angular-code-reviewer.md +64 -0
- package/templates/frontend/angular-nx/.cursor/agents/nx-architecture-guardian.md +69 -0
- package/templates/frontend/angular-nx/.cursor/agents/qa-test-expert.md +75 -0
- package/templates/frontend/angular-nx/.cursor/agents/security-auditor.md +61 -0
- package/templates/frontend/angular-nx/.cursor/hooks/auto-format.ts +70 -0
- package/templates/frontend/angular-nx/.cursor/hooks/auto-test-on-stop.ts +115 -0
- package/templates/frontend/angular-nx/.cursor/hooks/block-dangerous-commands.ts +188 -0
- package/templates/frontend/angular-nx/.cursor/hooks/ensure-tests-exist.ts +399 -0
- package/templates/frontend/angular-nx/.cursor/hooks/protect-sensitive-files.ts +128 -0
- package/templates/frontend/angular-nx/.cursor/hooks/session-context.ts +121 -0
- package/templates/frontend/angular-nx/.cursor/hooks.json +41 -0
- package/templates/frontend/react-vite/.cursor/agents/frontend-senior.agent.md +49 -49
- package/templates/frontend/react-vite/.cursor/agents/qa-test-expert.agent.md +126 -49
- package/templates/frontend/react-vite/.cursor/agents/security-expert.agent.md +39 -39
- package/templates/frontend/react-vite/.cursor/agents/ux-ui-expert.agent.md +45 -45
- package/templates/frontend/react-vite/.cursor/hooks/autoTestOnStop.ts +117 -0
- package/templates/frontend/react-vite/.cursor/hooks/blockDangerous.ts +75 -0
- package/templates/frontend/react-vite/.cursor/hooks/ensureTestsExist.ts +306 -220
- package/templates/frontend/react-vite/.cursor/hooks/formatOnEdit.ts +49 -0
- package/templates/frontend/react-vite/.cursor/hooks/protectSecrets.ts +88 -0
- package/templates/frontend/react-vite/.cursor/hooks/sessionInit.ts +77 -0
- package/templates/frontend/react-vite/.cursor/hooks.json +41 -10
- package/templates/frontend/react-vite/.cursor/settings.json +13 -13
- package/templates/frontend/react-vite/.vscode/settings.json +31 -31
- package/templates/frontend/react-vite/README.md +34 -34
- package/templates/frontend/react-vite/package.json +82 -82
- package/templates/frontend/react-vite/pnpm-lock.yaml +6575 -6575
- package/templates/frontend/react-vite/src/__tests__/components/layout/navbar.test.tsx +63 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/avatar.test.tsx +74 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/badge.test.tsx +55 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/breadcrumb.test.tsx +140 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/button.test.tsx +121 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/card.test.tsx +144 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/dialog.test.tsx +121 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/form.test.tsx +165 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/input.test.tsx +52 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/label.test.tsx +40 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/password-input.test.tsx +59 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/separator.test.tsx +40 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/table.test.tsx +254 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/tabs.test.tsx +82 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/textarea.test.tsx +47 -0
- package/templates/frontend/react-vite/src/__tests__/helpers/render.tsx +114 -0
- package/templates/frontend/react-vite/src/__tests__/hooks/useLocalStorage.test.ts +95 -0
- package/templates/frontend/react-vite/src/__tests__/lib/queryClient.test.ts +24 -0
- package/templates/frontend/react-vite/src/__tests__/lib/utils.test.ts +43 -0
- package/templates/frontend/react-vite/src/__tests__/routes/index.test.tsx +111 -0
- package/templates/frontend/react-vite/src/__tests__/routes/otra-ruta.test.tsx +126 -0
- package/templates/frontend/react-vite/src/__tests__/routes/root.test.tsx +78 -0
- package/templates/frontend/react-vite/src/__tests__/routes/ui-components.test.tsx +286 -0
- package/templates/frontend/react-vite/src/components/layout/navbar.tsx +38 -38
- package/templates/frontend/react-vite/src/components/ui/avatar.tsx +42 -42
- package/templates/frontend/react-vite/src/components/ui/dialog.tsx +122 -122
- package/templates/frontend/react-vite/src/components/ui/table.tsx +229 -244
- package/templates/frontend/react-vite/src/hooks/useLocalStorage.ts +32 -32
- package/templates/frontend/react-vite/src/routes/__root.tsx +48 -48
- package/templates/frontend/react-vite/src/routes/ui-components.tsx +359 -85
- package/templates/frontend/react-vite/src/test/setup.ts +24 -24
- package/templates/frontend/react-vite/vite.config.ts +2 -2
- package/templates/frontend/react-vite/vitest.config.ts +13 -2
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: test-engineer
|
|
3
|
+
model: claude-4.6-opus-high-thinking
|
|
4
|
+
description: Ingeniero de testing especializado en Jest y Supertest para NestJS. Usar proactivamente cuando se necesite crear tests unitarios o e2e, diagnosticar fallos de tests, mejorar cobertura, crear mocks de servicios, agregar fixtures o helpers de prueba. Activar ante tareas de testing, cobertura, tests unitarios, tests e2e, mocks, assertions, Jest o Supertest.
|
|
5
|
+
readonly: true
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
Eres un ingeniero de testing especializado en Jest 30 con NestJS 11 y Fastify. Tu rol es crear y mantener tests de alta calidad siguiendo exactamente los patrones establecidos en la suite de tests existente.
|
|
9
|
+
|
|
10
|
+
## Contexto de testing del proyecto
|
|
11
|
+
|
|
12
|
+
### Herramientas
|
|
13
|
+
|
|
14
|
+
- Jest 30 con ts-jest (transform TypeScript)
|
|
15
|
+
- Supertest 7 para tests e2e HTTP
|
|
16
|
+
- @nestjs/testing para crear módulos de prueba
|
|
17
|
+
- Fastify adapter (NO Express) en tests e2e
|
|
18
|
+
- Base de datos SQLite en memoria para e2e
|
|
19
|
+
|
|
20
|
+
### Configuración
|
|
21
|
+
|
|
22
|
+
**Unit tests** (config en `package.json` sección "jest"):
|
|
23
|
+
- testRegex: `.*\.spec\.ts$`
|
|
24
|
+
- Ubicación: `test/unit/`
|
|
25
|
+
- Coverage excluye: `main.ts`, `*.module.ts`, `*.dto.ts`
|
|
26
|
+
- Module alias: `@/` → `<rootDir>/src/`
|
|
27
|
+
|
|
28
|
+
**E2E tests** (config en `test/jest-e2e.json`):
|
|
29
|
+
- testRegex: `.e2e-spec.ts$`
|
|
30
|
+
- Ubicación: `test/e2e/`
|
|
31
|
+
- Setup: `test/setup-e2e.ts` (carga .env.test, NODE_ENV=test)
|
|
32
|
+
- Timeout: 30000ms
|
|
33
|
+
- maxWorkers: 1 (secuencial por BD compartida)
|
|
34
|
+
|
|
35
|
+
### Estructura de archivos de test
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
test/
|
|
39
|
+
├── unit/ # Tests unitarios (13 archivos)
|
|
40
|
+
│ ├── auth.service.spec.ts
|
|
41
|
+
│ ├── auth.controller.spec.ts
|
|
42
|
+
│ ├── posts.service.spec.ts
|
|
43
|
+
│ ├── posts.controller.spec.ts
|
|
44
|
+
│ ├── users.service.spec.ts
|
|
45
|
+
│ ├── users.controller.spec.ts
|
|
46
|
+
│ ├── profile.service.spec.ts
|
|
47
|
+
│ ├── settings.service.spec.ts
|
|
48
|
+
│ ├── health.controller.spec.ts
|
|
49
|
+
│ ├── app.service.spec.ts
|
|
50
|
+
│ ├── jwt-auth.guard.spec.ts
|
|
51
|
+
│ ├── jwt.strategy.spec.ts
|
|
52
|
+
│ └── http-exception.filter.spec.ts
|
|
53
|
+
├── e2e/ # Tests end-to-end (4 archivos)
|
|
54
|
+
│ ├── auth.e2e-spec.ts
|
|
55
|
+
│ ├── health.e2e-spec.ts
|
|
56
|
+
│ ├── posts.e2e-spec.ts
|
|
57
|
+
│ └── users.e2e-spec.ts
|
|
58
|
+
├── helpers/
|
|
59
|
+
│ ├── auth.helper.ts # createTestUser, getAuthToken, createMultipleUsers
|
|
60
|
+
│ └── db.helper.ts # setupTestDatabase, cleanDatabase, closeDatabase, seedTestUser, seedTestPost
|
|
61
|
+
├── fixtures/
|
|
62
|
+
│ └── test-data.ts # DTOs válidos e inválidos, testUsers por rol, testPosts
|
|
63
|
+
├── setup-e2e.ts # Carga .env.test, establece NODE_ENV=test
|
|
64
|
+
└── jest-e2e.json
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Patrón de test unitario
|
|
68
|
+
|
|
69
|
+
Los tests unitarios mockean TODAS las dependencias inyectadas.
|
|
70
|
+
|
|
71
|
+
### Estructura obligatoria
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
75
|
+
import { MiService } from '../../src/modulo/mi.service';
|
|
76
|
+
import { PrismaService } from '../../src/prisma/prisma.service';
|
|
77
|
+
|
|
78
|
+
describe('MiService', () => {
|
|
79
|
+
let service: MiService;
|
|
80
|
+
|
|
81
|
+
// Mock de PrismaService con los métodos usados
|
|
82
|
+
const mockPrismaService = {
|
|
83
|
+
modelo: {
|
|
84
|
+
create: jest.fn(),
|
|
85
|
+
findMany: jest.fn(),
|
|
86
|
+
findUnique: jest.fn(),
|
|
87
|
+
update: jest.fn(),
|
|
88
|
+
delete: jest.fn(),
|
|
89
|
+
count: jest.fn(),
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
beforeEach(async () => {
|
|
94
|
+
const module: TestingModule = await Test.createTestingModule({
|
|
95
|
+
providers: [
|
|
96
|
+
MiService,
|
|
97
|
+
{ provide: PrismaService, useValue: mockPrismaService },
|
|
98
|
+
],
|
|
99
|
+
}).compile();
|
|
100
|
+
|
|
101
|
+
service = module.get<MiService>(MiService);
|
|
102
|
+
jest.clearAllMocks();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('should be defined', () => {
|
|
106
|
+
expect(service).toBeDefined();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe('metodo', () => {
|
|
110
|
+
it('should succeed with valid input', async () => {
|
|
111
|
+
mockPrismaService.modelo.create.mockResolvedValue(expectedResult);
|
|
112
|
+
const result = await service.metodo(input);
|
|
113
|
+
expect(result).toEqual(expectedResult);
|
|
114
|
+
expect(mockPrismaService.modelo.create).toHaveBeenCalledWith(expectedArgs);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('should throw NotFoundException when not found', async () => {
|
|
118
|
+
mockPrismaService.modelo.findUnique.mockResolvedValue(null);
|
|
119
|
+
await expect(service.metodo(999)).rejects.toThrow(NotFoundException);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Mock de servicios adicionales
|
|
126
|
+
|
|
127
|
+
Para AuthService que usa JwtService:
|
|
128
|
+
```typescript
|
|
129
|
+
const mockJwtService = { sign: jest.fn().mockReturnValue('mock-token') };
|
|
130
|
+
|
|
131
|
+
// En providers:
|
|
132
|
+
{ provide: JwtService, useValue: mockJwtService },
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Qué testear en servicios
|
|
136
|
+
|
|
137
|
+
- Caso exitoso con datos válidos
|
|
138
|
+
- NotFoundException cuando el recurso no existe
|
|
139
|
+
- ForbiddenException cuando no hay permisos (ownership)
|
|
140
|
+
- Verificar que Prisma fue llamado con los argumentos correctos
|
|
141
|
+
- Verificar que mocks no fueron llamados en casos de error
|
|
142
|
+
|
|
143
|
+
## Patrón de test e2e
|
|
144
|
+
|
|
145
|
+
Los tests e2e usan la aplicación real con Fastify y BD real (SQLite).
|
|
146
|
+
|
|
147
|
+
### Estructura obligatoria
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
151
|
+
import { INestApplication, ValidationPipe } from '@nestjs/common';
|
|
152
|
+
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';
|
|
153
|
+
import request from 'supertest';
|
|
154
|
+
import { AppModule } from '../../src/app.module';
|
|
155
|
+
import { PrismaService } from '../../src/prisma/prisma.service';
|
|
156
|
+
import { cleanDatabase, seedTestUser } from '../helpers/db.helper';
|
|
157
|
+
import { HttpExceptionFilter } from '../../src/common/filters/http-exception.filter';
|
|
158
|
+
|
|
159
|
+
describe('MiController (e2e)', () => {
|
|
160
|
+
let app: NestFastifyApplication;
|
|
161
|
+
let prisma: PrismaService;
|
|
162
|
+
|
|
163
|
+
beforeAll(async () => {
|
|
164
|
+
const moduleFixture: TestingModule = await Test.createTestingModule({
|
|
165
|
+
imports: [AppModule],
|
|
166
|
+
}).compile();
|
|
167
|
+
|
|
168
|
+
app = moduleFixture.createNestApplication<NestFastifyApplication>(
|
|
169
|
+
new FastifyAdapter(),
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
app.useGlobalFilters(new HttpExceptionFilter());
|
|
173
|
+
app.useGlobalPipes(new ValidationPipe({
|
|
174
|
+
whitelist: true,
|
|
175
|
+
forbidNonWhitelisted: true,
|
|
176
|
+
transform: true,
|
|
177
|
+
}));
|
|
178
|
+
|
|
179
|
+
prisma = app.get<PrismaService>(PrismaService);
|
|
180
|
+
await app.init();
|
|
181
|
+
await app.getHttpAdapter().getInstance().ready();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
beforeEach(async () => {
|
|
185
|
+
await cleanDatabase(prisma);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
afterAll(async () => {
|
|
189
|
+
await cleanDatabase(prisma);
|
|
190
|
+
await app.close();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// Tests aquí
|
|
194
|
+
});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Patrón para endpoints protegidos
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
it('should return 401 without token', async () => {
|
|
201
|
+
await request(app.getHttpServer())
|
|
202
|
+
.get('/recurso')
|
|
203
|
+
.expect(401);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('should succeed with valid token', async () => {
|
|
207
|
+
const user = await seedTestUser(prisma, testUsers.admin);
|
|
208
|
+
const token = getAuthToken(user, process.env.JWT_SECRET!);
|
|
209
|
+
|
|
210
|
+
const response = await request(app.getHttpServer())
|
|
211
|
+
.get('/recurso')
|
|
212
|
+
.set('Authorization', `Bearer ${token}`)
|
|
213
|
+
.expect(200);
|
|
214
|
+
|
|
215
|
+
expect(response.body).toHaveProperty('expected_field');
|
|
216
|
+
});
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Orden de limpieza de BD
|
|
220
|
+
|
|
221
|
+
Siempre respetar foreign keys:
|
|
222
|
+
```typescript
|
|
223
|
+
await prisma.post.deleteMany({});
|
|
224
|
+
await prisma.userSettings.deleteMany({});
|
|
225
|
+
await prisma.userProfile.deleteMany({});
|
|
226
|
+
await prisma.user.deleteMany({});
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Helpers disponibles
|
|
230
|
+
|
|
231
|
+
### `test/helpers/db.helper.ts`
|
|
232
|
+
|
|
233
|
+
- `setupTestDatabase()`: crea PrismaClient con SQLite in-memory
|
|
234
|
+
- `cleanDatabase(prisma)`: limpia todas las tablas en orden
|
|
235
|
+
- `closeDatabase(prisma)`: desconecta
|
|
236
|
+
- `seedTestUser(prisma, data?)`: crea usuario con bcrypt hash (default: test@example.com / Test123!)
|
|
237
|
+
- `seedTestPost(prisma, authorId, data?)`: crea post de prueba
|
|
238
|
+
|
|
239
|
+
### `test/helpers/auth.helper.ts`
|
|
240
|
+
|
|
241
|
+
- `createTestUser(prisma, overrides?)`: wrapper de seedTestUser
|
|
242
|
+
- `getAuthToken(user, jwtSecret)`: genera JWT válido para testing
|
|
243
|
+
- `createMultipleUsers(prisma, count)`: crea N usuarios
|
|
244
|
+
|
|
245
|
+
### `test/fixtures/test-data.ts`
|
|
246
|
+
|
|
247
|
+
- `validLoginDto`, `invalidLoginDtos`: datos de login
|
|
248
|
+
- `validCreatePostDto`, `invalidCreatePostDtos`: datos de posts
|
|
249
|
+
- `validUpdatePostDto`, `validUpdateProfileDto`, `validUpdateSettingsDto`
|
|
250
|
+
- `testUsers`: { admin, editor, reader } con credenciales por rol
|
|
251
|
+
- `testPosts`: array de 3 posts de prueba
|
|
252
|
+
|
|
253
|
+
## Cuando seas invocado
|
|
254
|
+
|
|
255
|
+
1. Lee los tests existentes del módulo relevante para entender el patrón
|
|
256
|
+
2. Lee el servicio/controller que se está testeando
|
|
257
|
+
3. Usa los helpers y fixtures existentes (NO duplicar)
|
|
258
|
+
4. Genera tests siguiendo exactamente los patrones documentados
|
|
259
|
+
|
|
260
|
+
## Qué cubrir en cada módulo
|
|
261
|
+
|
|
262
|
+
### Para servicios: test unitario
|
|
263
|
+
|
|
264
|
+
- `should be defined`
|
|
265
|
+
- Un test por método público
|
|
266
|
+
- Caso exitoso
|
|
267
|
+
- Caso de error (NotFoundException, ForbiddenException)
|
|
268
|
+
- Verificación de argumentos a Prisma
|
|
269
|
+
|
|
270
|
+
### Para controllers: test unitario
|
|
271
|
+
|
|
272
|
+
- `should be defined`
|
|
273
|
+
- Verificar que el controller delega al servicio correcto
|
|
274
|
+
- Verificar que retorna lo que el servicio retorna
|
|
275
|
+
|
|
276
|
+
### Para endpoints: test e2e
|
|
277
|
+
|
|
278
|
+
- Request sin autenticación → 401
|
|
279
|
+
- Request con token válido → 200/201
|
|
280
|
+
- Request con datos inválidos → 400
|
|
281
|
+
- Request con recurso inexistente → 404
|
|
282
|
+
- Request sin permisos → 403
|
|
283
|
+
- Verificar estructura de respuesta
|
|
284
|
+
|
|
285
|
+
## Cuando NO usarme
|
|
286
|
+
|
|
287
|
+
- Decisiones de arquitectura (usar nestjs-architect)
|
|
288
|
+
- Cambios en schema de Prisma (usar prisma-analyst)
|
|
289
|
+
- Auditoría de seguridad (usar security-auditor)
|
|
290
|
+
- Revisión de estilo de código (usar code-reviewer)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
|
|
4
|
+
interface HookInput {
|
|
5
|
+
file_path: string;
|
|
6
|
+
workspace_roots?: string[];
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const FORMATTABLE_EXTENSIONS = new Set([
|
|
11
|
+
'.ts',
|
|
12
|
+
'.tsx',
|
|
13
|
+
'.js',
|
|
14
|
+
'.jsx',
|
|
15
|
+
'.mjs',
|
|
16
|
+
'.json',
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
const IGNORED_DIRS = ['node_modules', 'dist', 'coverage', 'generated', '.prisma'];
|
|
20
|
+
|
|
21
|
+
function readStdin(): Promise<string> {
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
let data = '';
|
|
24
|
+
process.stdin.setEncoding('utf8');
|
|
25
|
+
process.stdin.on('data', (chunk: string) => {
|
|
26
|
+
data += chunk;
|
|
27
|
+
});
|
|
28
|
+
process.stdin.on('end', () => resolve(data));
|
|
29
|
+
process.stdin.on('error', () => resolve(''));
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function isInIgnoredDir(filePath: string): boolean {
|
|
34
|
+
const normalized = filePath.replace(/\\/g, '/');
|
|
35
|
+
return IGNORED_DIRS.some((dir) => normalized.includes(`/${dir}/`));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function main(): Promise<void> {
|
|
39
|
+
try {
|
|
40
|
+
const raw = await readStdin();
|
|
41
|
+
if (!raw?.trim()) return;
|
|
42
|
+
|
|
43
|
+
const payload = JSON.parse(raw.replace(/^\uFEFF/, '').trim()) as HookInput;
|
|
44
|
+
const filePath = payload.file_path;
|
|
45
|
+
|
|
46
|
+
if (!filePath) {
|
|
47
|
+
console.error('[auto-format] No file_path in payload');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
52
|
+
|
|
53
|
+
if (!FORMATTABLE_EXTENSIONS.has(ext)) {
|
|
54
|
+
console.error(`[auto-format] Skipping non-formattable extension: ${ext}`);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (isInIgnoredDir(filePath)) {
|
|
59
|
+
console.error(`[auto-format] Skipping ignored directory: ${filePath}`);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
console.error(`[auto-format] Formatting: ${filePath}`);
|
|
64
|
+
|
|
65
|
+
execSync(`npx prettier --write "${filePath}"`, {
|
|
66
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
67
|
+
timeout: 10_000,
|
|
68
|
+
cwd: process.env['CURSOR_PROJECT_DIR'] || process.cwd(),
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
console.error(`[auto-format] Done: ${filePath}`);
|
|
72
|
+
} catch (err) {
|
|
73
|
+
console.error(
|
|
74
|
+
'[auto-format] Error:',
|
|
75
|
+
err instanceof Error ? err.message : String(err),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
main();
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
interface HookInput {
|
|
2
|
+
command: string;
|
|
3
|
+
cwd?: string;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface HookOutput {
|
|
9
|
+
permission: 'allow' | 'deny' | 'ask';
|
|
10
|
+
user_message?: string;
|
|
11
|
+
agent_message?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface DangerRule {
|
|
15
|
+
pattern: RegExp;
|
|
16
|
+
permission: 'deny' | 'ask';
|
|
17
|
+
userMessage: string;
|
|
18
|
+
agentMessage: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const DANGER_RULES: DangerRule[] = [
|
|
22
|
+
{
|
|
23
|
+
pattern: /rm\s+(-\w*r\w*f\w*|-\w*f\w*r\w*)\s+[/~.]/,
|
|
24
|
+
permission: 'deny',
|
|
25
|
+
userMessage: 'Comando rm -rf destructivo bloqueado.',
|
|
26
|
+
agentMessage:
|
|
27
|
+
'El comando fue bloqueado porque rm -rf apuntando a /, ~ o . puede borrar archivos criticos. Usa rutas especificas y seguras.',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
pattern: /prisma\s+migrate\s+reset/i,
|
|
31
|
+
permission: 'deny',
|
|
32
|
+
userMessage: 'prisma migrate reset bloqueado (borra toda la BD).',
|
|
33
|
+
agentMessage:
|
|
34
|
+
'prisma migrate reset fue bloqueado porque elimina todos los datos de la base de datos. Si necesitas resetear, pide confirmacion al usuario primero.',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
pattern: /prisma\s+db\s+push\s+--force-reset/i,
|
|
38
|
+
permission: 'deny',
|
|
39
|
+
userMessage: 'prisma db push --force-reset bloqueado (reset forzado de BD).',
|
|
40
|
+
agentMessage:
|
|
41
|
+
'prisma db push --force-reset fue bloqueado porque fuerza un reset completo de la base de datos. Usa prisma migrate dev para cambios seguros.',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
pattern: /DROP\s+(DATABASE|TABLE|SCHEMA)/i,
|
|
45
|
+
permission: 'deny',
|
|
46
|
+
userMessage: 'Comando SQL destructivo (DROP) bloqueado.',
|
|
47
|
+
agentMessage:
|
|
48
|
+
'Comandos DROP DATABASE/TABLE/SCHEMA fueron bloqueados por seguridad. Usa Prisma migrations para cambios de esquema.',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
pattern: /TRUNCATE\s+TABLE/i,
|
|
52
|
+
permission: 'deny',
|
|
53
|
+
userMessage: 'TRUNCATE TABLE bloqueado.',
|
|
54
|
+
agentMessage:
|
|
55
|
+
'TRUNCATE TABLE fue bloqueado. Si necesitas limpiar datos, usa el seed (pnpm prisma:seed) o pedi confirmacion al usuario.',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
pattern: /git\s+push\s+.*--force(?!-with-lease)\b.*(?:main|master)/i,
|
|
59
|
+
permission: 'deny',
|
|
60
|
+
userMessage: 'git push --force a main/master bloqueado.',
|
|
61
|
+
agentMessage:
|
|
62
|
+
'git push --force a main/master fue bloqueado. Usa --force-with-lease o trabaja en una branch separada.',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
pattern: /git\s+push\s+--force(?!-with-lease)/i,
|
|
66
|
+
permission: 'ask',
|
|
67
|
+
userMessage: 'git push --force requiere aprobacion manual.',
|
|
68
|
+
agentMessage:
|
|
69
|
+
'git push --force necesita aprobacion del usuario. Considera usar --force-with-lease que es mas seguro.',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
pattern: /prisma\s+db\s+push(?!\s+--force-reset)/i,
|
|
73
|
+
permission: 'ask',
|
|
74
|
+
userMessage: 'prisma db push puede causar perdida de datos. Aprobar?',
|
|
75
|
+
agentMessage:
|
|
76
|
+
'prisma db push requiere aprobacion porque puede causar perdida de datos si hay cambios destructivos en el schema. Considera usar prisma migrate dev.',
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
function readStdin(): Promise<string> {
|
|
81
|
+
return new Promise((resolve) => {
|
|
82
|
+
let data = '';
|
|
83
|
+
process.stdin.setEncoding('utf8');
|
|
84
|
+
process.stdin.on('data', (chunk: string) => {
|
|
85
|
+
data += chunk;
|
|
86
|
+
});
|
|
87
|
+
process.stdin.on('end', () => resolve(data));
|
|
88
|
+
process.stdin.on('error', () => resolve(''));
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function respond(output: HookOutput): void {
|
|
93
|
+
process.stdout.write(JSON.stringify(output) + '\n');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function evaluateCommand(command: string): HookOutput {
|
|
97
|
+
for (const rule of DANGER_RULES) {
|
|
98
|
+
if (rule.pattern.test(command)) {
|
|
99
|
+
return {
|
|
100
|
+
permission: rule.permission,
|
|
101
|
+
user_message: rule.userMessage,
|
|
102
|
+
agent_message: rule.agentMessage,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return { permission: 'allow' };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function main(): Promise<void> {
|
|
111
|
+
try {
|
|
112
|
+
const raw = await readStdin();
|
|
113
|
+
if (!raw?.trim()) {
|
|
114
|
+
respond({ permission: 'allow' });
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const payload = JSON.parse(raw.replace(/^\uFEFF/, '').trim()) as HookInput;
|
|
119
|
+
const command = payload.command;
|
|
120
|
+
|
|
121
|
+
if (!command) {
|
|
122
|
+
respond({ permission: 'allow' });
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const result = evaluateCommand(command);
|
|
127
|
+
|
|
128
|
+
if (result.permission !== 'allow') {
|
|
129
|
+
console.error(
|
|
130
|
+
`[block-dangerous] ${result.permission.toUpperCase()}: ${command}`,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
respond(result);
|
|
135
|
+
} catch (err) {
|
|
136
|
+
console.error(
|
|
137
|
+
'[block-dangerous] Error:',
|
|
138
|
+
err instanceof Error ? err.message : String(err),
|
|
139
|
+
);
|
|
140
|
+
respond({ permission: 'allow' });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
main();
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
interface HookInput {
|
|
4
|
+
file_path: string;
|
|
5
|
+
workspace_roots?: string[];
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function readStdin(): Promise<string> {
|
|
10
|
+
return new Promise((resolve) => {
|
|
11
|
+
let data = '';
|
|
12
|
+
process.stdin.setEncoding('utf8');
|
|
13
|
+
process.stdin.on('data', (chunk: string) => {
|
|
14
|
+
data += chunk;
|
|
15
|
+
});
|
|
16
|
+
process.stdin.on('end', () => resolve(data));
|
|
17
|
+
process.stdin.on('error', () => resolve(''));
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isSchemaFile(filePath: string): boolean {
|
|
22
|
+
const normalized = filePath.replace(/\\/g, '/');
|
|
23
|
+
return normalized.endsWith('prisma/schema.prisma') || normalized.endsWith('.prisma');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function main(): Promise<void> {
|
|
27
|
+
try {
|
|
28
|
+
const raw = await readStdin();
|
|
29
|
+
if (!raw?.trim()) return;
|
|
30
|
+
|
|
31
|
+
const payload = JSON.parse(raw.replace(/^\uFEFF/, '').trim()) as HookInput;
|
|
32
|
+
const filePath = payload.file_path;
|
|
33
|
+
|
|
34
|
+
if (!filePath) {
|
|
35
|
+
console.error('[prisma-watcher] No file_path in payload');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!isSchemaFile(filePath)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const cwd = process.env['CURSOR_PROJECT_DIR'] || process.cwd();
|
|
44
|
+
|
|
45
|
+
console.error(`[prisma-watcher] Schema changed: ${filePath}`);
|
|
46
|
+
console.error('[prisma-watcher] Running prisma generate...');
|
|
47
|
+
|
|
48
|
+
const output = execSync('npx prisma generate', {
|
|
49
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
50
|
+
timeout: 30_000,
|
|
51
|
+
cwd,
|
|
52
|
+
encoding: 'utf8',
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
console.error(`[prisma-watcher] prisma generate completed: ${output.trim()}`);
|
|
56
|
+
} catch (err) {
|
|
57
|
+
console.error(
|
|
58
|
+
'[prisma-watcher] Error running prisma generate:',
|
|
59
|
+
err instanceof Error ? err.message : String(err),
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
main();
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
|
|
3
|
+
interface HookInput {
|
|
4
|
+
file_path: string;
|
|
5
|
+
content?: string;
|
|
6
|
+
attachments?: { type: string; filePath: string }[];
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface HookOutput {
|
|
11
|
+
permission: 'allow' | 'deny';
|
|
12
|
+
user_message?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const BLOCKED_BASENAMES = new Set([
|
|
16
|
+
'.env',
|
|
17
|
+
'.env.local',
|
|
18
|
+
'.env.test',
|
|
19
|
+
'.env.production',
|
|
20
|
+
'.env.development',
|
|
21
|
+
'.env.staging',
|
|
22
|
+
'id_rsa',
|
|
23
|
+
'id_ed25519',
|
|
24
|
+
'credentials.json',
|
|
25
|
+
'secrets.yaml',
|
|
26
|
+
'secrets.yml',
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
const BLOCKED_EXTENSIONS = new Set(['.db', '.db-journal', '.pem', '.key', '.pfx', '.p12']);
|
|
30
|
+
|
|
31
|
+
const BLOCKED_PATTERNS = [/\.env\.\w+\.local$/];
|
|
32
|
+
|
|
33
|
+
const ALLOWED_BASENAMES = new Set(['.env.example', '.env.template', '.env.sample']);
|
|
34
|
+
|
|
35
|
+
function readStdin(): Promise<string> {
|
|
36
|
+
return new Promise((resolve) => {
|
|
37
|
+
let data = '';
|
|
38
|
+
process.stdin.setEncoding('utf8');
|
|
39
|
+
process.stdin.on('data', (chunk: string) => {
|
|
40
|
+
data += chunk;
|
|
41
|
+
});
|
|
42
|
+
process.stdin.on('end', () => resolve(data));
|
|
43
|
+
process.stdin.on('error', () => resolve(''));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function respond(output: HookOutput): void {
|
|
48
|
+
process.stdout.write(JSON.stringify(output) + '\n');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function shouldBlock(filePath: string): string | null {
|
|
52
|
+
const basename = path.basename(filePath);
|
|
53
|
+
|
|
54
|
+
if (ALLOWED_BASENAMES.has(basename)) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (BLOCKED_BASENAMES.has(basename)) {
|
|
59
|
+
return `"${basename}" puede contener secrets (JWT_SECRET, credenciales). Usa ".env.example" como referencia.`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
63
|
+
|
|
64
|
+
if (ext === '.db' || ext === '.db-journal') {
|
|
65
|
+
return `"${basename}" es un archivo binario SQLite. Usa Prisma Studio (pnpm prisma:studio) o el MCP sqlite para inspeccionar datos.`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (BLOCKED_EXTENSIONS.has(ext)) {
|
|
69
|
+
return `"${basename}" es un archivo de certificado/clave privada y no debe ser leido por el agente.`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
for (const pattern of BLOCKED_PATTERNS) {
|
|
73
|
+
if (pattern.test(basename)) {
|
|
74
|
+
return `"${basename}" es un archivo de entorno local que puede contener secrets.`;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function main(): Promise<void> {
|
|
82
|
+
try {
|
|
83
|
+
const raw = await readStdin();
|
|
84
|
+
if (!raw?.trim()) {
|
|
85
|
+
respond({ permission: 'allow' });
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const payload = JSON.parse(raw.replace(/^\uFEFF/, '').trim()) as HookInput;
|
|
90
|
+
const filePath = payload.file_path;
|
|
91
|
+
|
|
92
|
+
if (!filePath) {
|
|
93
|
+
respond({ permission: 'allow' });
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const blockReason = shouldBlock(filePath);
|
|
98
|
+
|
|
99
|
+
if (blockReason) {
|
|
100
|
+
console.error(`[protect-sensitive] BLOCKED: ${filePath}`);
|
|
101
|
+
respond({
|
|
102
|
+
permission: 'deny',
|
|
103
|
+
user_message: `Acceso bloqueado por hook de seguridad: ${blockReason}`,
|
|
104
|
+
});
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
respond({ permission: 'allow' });
|
|
109
|
+
} catch (err) {
|
|
110
|
+
console.error(
|
|
111
|
+
'[protect-sensitive] Error:',
|
|
112
|
+
err instanceof Error ? err.message : String(err),
|
|
113
|
+
);
|
|
114
|
+
respond({
|
|
115
|
+
permission: 'deny',
|
|
116
|
+
user_message:
|
|
117
|
+
'Hook de proteccion de archivos sensibles fallo. Acceso denegado por seguridad (fail-closed).',
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
main();
|