@punks/cli 2.1.11 → 2.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 +3 -1
- package/dist/index.js +0 -0
- package/package.json +1 -1
- package/dist/data/AGENTS.md +0 -119
- package/dist/data/catalog/hooks.ts +0 -26
- package/dist/data/catalog/lint.ts +0 -266
- package/dist/data/catalog/packs.ts +0 -327
- package/dist/data/catalog/skills.ts +0 -449
- package/dist/data/catalog/tools.ts +0 -48
- package/dist/data/control-plane.json +0 -3
- package/dist/data/hooks/format-edited-file.mjs +0 -699
- package/dist/data/hooks/format-edited-file.sh +0 -37
- package/dist/data/hooks/require-tests-for-pr.mjs +0 -206
- package/dist/data/hooks/scaffold-update-check.mjs +0 -181
- package/dist/data/hooks.test.ts +0 -109
- package/dist/data/scripts/sync-subagents.mjs +0 -524
- package/dist/data/subagents/manifest.mjs +0 -487
- package/dist/data/subagents/manifest.test.ts +0 -40
- package/dist/skills/agnostic/backend/backend-domain-structure/SKILL.md +0 -50
- package/dist/skills/agnostic/backend/backend-domain-structure/agents/openai.yaml +0 -4
- package/dist/skills/agnostic/backend/backend-domain-structure/references/layout.md +0 -167
- package/dist/skills/agnostic/backend/backend-recoverable-actions/SKILL.md +0 -49
- package/dist/skills/agnostic/backend/backend-recoverable-actions/agents/openai.yaml +0 -4
- package/dist/skills/agnostic/backend/backend-recoverable-actions/references/strategy-matrix.md +0 -34
- package/dist/skills/agnostic/backend/backend-recoverable-actions/references/test-matrix.md +0 -34
- package/dist/skills/agnostic/backend/logging-best-practices/SKILL.md +0 -127
- package/dist/skills/agnostic/backend/logging-best-practices/rules/context.md +0 -157
- package/dist/skills/agnostic/backend/logging-best-practices/rules/pitfalls.md +0 -118
- package/dist/skills/agnostic/backend/logging-best-practices/rules/structure.md +0 -193
- package/dist/skills/agnostic/backend/logging-best-practices/rules/wide-events.md +0 -113
- package/dist/skills/agnostic/cli/dp-cli/SKILL.md +0 -125
- package/dist/skills/agnostic/cli/dp-cli/references/commands.md +0 -70
- package/dist/skills/agnostic/cli/dp-cli/references/post-command-flow.md +0 -70
- package/dist/skills/agnostic/debug/debug-agent/SKILL.md +0 -184
- package/dist/skills/agnostic/docs/docs-onboarding/SKILL.md +0 -46
- package/dist/skills/agnostic/docs/docs-onboarding/agents/openai.yaml +0 -4
- package/dist/skills/agnostic/docs/docs-onboarding/references/artifact-contract.md +0 -67
- package/dist/skills/agnostic/docs/writing-beats/SKILL.md +0 -69
- package/dist/skills/agnostic/docs/writing-fragments/SKILL.md +0 -76
- package/dist/skills/agnostic/docs/writing-shape/SKILL.md +0 -75
- package/dist/skills/agnostic/frontend/agent-browser/.clawdhub/origin.json +0 -7
- package/dist/skills/agnostic/frontend/agent-browser/SKILL.md +0 -229
- package/dist/skills/agnostic/frontend/agent-browser/references/authentication.md +0 -202
- package/dist/skills/agnostic/frontend/agent-browser/references/commands.md +0 -259
- package/dist/skills/agnostic/frontend/agent-browser/references/proxy-support.md +0 -188
- package/dist/skills/agnostic/frontend/agent-browser/references/session-management.md +0 -193
- package/dist/skills/agnostic/frontend/agent-browser/references/snapshot-refs.md +0 -194
- package/dist/skills/agnostic/frontend/agent-browser/references/video-recording.md +0 -173
- package/dist/skills/agnostic/frontend/agent-browser/templates/authenticated-session.sh +0 -97
- package/dist/skills/agnostic/frontend/agent-browser/templates/capture-workflow.sh +0 -69
- package/dist/skills/agnostic/frontend/agent-browser/templates/form-automation.sh +0 -62
- package/dist/skills/agnostic/frontend/design-taste-frontend/SKILL.md +0 -226
- package/dist/skills/agnostic/frontend/frontend-domain-structure/SKILL.md +0 -55
- package/dist/skills/agnostic/frontend/frontend-domain-structure/agents/openai.yaml +0 -4
- package/dist/skills/agnostic/frontend/frontend-domain-structure/references/react/structure.md +0 -102
- package/dist/skills/agnostic/frontend/frontend-domain-structure/references/structure.md +0 -257
- package/dist/skills/agnostic/frontend/gpt-taste/SKILL.md +0 -74
- package/dist/skills/agnostic/frontend/image-taste-frontend/SKILL.md +0 -1102
- package/dist/skills/agnostic/frontend/redesign-existing-projects/SKILL.md +0 -178
- package/dist/skills/agnostic/generic/handoff/SKILL.md +0 -15
- package/dist/skills/agnostic/planning/create-plan/REFERENCE.md +0 -37
- package/dist/skills/agnostic/planning/create-plan/SKILL.md +0 -88
- package/dist/skills/agnostic/planning/create-plan/references/backlog-sync.md +0 -44
- package/dist/skills/agnostic/planning/create-plan/references/grill-phase.md +0 -87
- package/dist/skills/agnostic/planning/create-plan/references/plan-schema.md +0 -90
- package/dist/skills/agnostic/planning/create-plan/references/planner-phase.md +0 -42
- package/dist/skills/agnostic/planning/create-plan/references/stop-conditions.md +0 -18
- package/dist/skills/agnostic/planning/create-plan/references/tdd-phase.md +0 -48
- package/dist/skills/agnostic/planning/create-spec/SKILL.md +0 -111
- package/dist/skills/agnostic/planning/create-spec/assets/SPEC-TEMPLATE.md +0 -91
- package/dist/skills/agnostic/planning/create-spec/references/backlog-sync.md +0 -49
- package/dist/skills/agnostic/planning/create-spec/references/discovery.md +0 -54
- package/dist/skills/agnostic/planning/create-spec/references/folder-naming.md +0 -33
- package/dist/skills/agnostic/planning/create-spec/references/grill-phase.md +0 -47
- package/dist/skills/agnostic/planning/create-spec/references/handoff.md +0 -47
- package/dist/skills/agnostic/planning/create-spec/references/questioning.md +0 -51
- package/dist/skills/agnostic/planning/create-spec/references/spec-quality-bar.md +0 -58
- package/dist/skills/agnostic/planning/create-spec/references/wiki-bookkeeping.md +0 -50
- package/dist/skills/agnostic/planning/grill-me/SKILL.md +0 -28
- package/dist/skills/agnostic/planning/implement-spec/SKILL.md +0 -99
- package/dist/skills/agnostic/planning/implement-spec/assets/IMPLEMENTATION-NOTES-TEMPLATE.md +0 -53
- package/dist/skills/agnostic/planning/implement-spec/references/lifecycle.md +0 -199
- package/dist/skills/agnostic/planning/implement-spec/references/parallel-orchestration.md +0 -102
- package/dist/skills/agnostic/planning/implement-spec/references/parallel-worker-brief.md +0 -74
- package/dist/skills/agnostic/planning/implement-spec/references/parallel.md +0 -56
- package/dist/skills/agnostic/planning/implement-spec/references/sequential.md +0 -43
- package/dist/skills/agnostic/planning/stack/SKILL.md +0 -89
- package/dist/skills/agnostic/planning/swarm-planner/SKILL.md +0 -179
- package/dist/skills/agnostic/quality/autoreview/SKILL.md +0 -191
- package/dist/skills/agnostic/quality/autoreview/scripts/autoreview +0 -1176
- package/dist/skills/agnostic/quality/autoreview/scripts/test-review-harness +0 -176
- package/dist/skills/agnostic/quality/simplify/SKILL.md +0 -14
- package/dist/skills/agnostic/quality/tdd/SKILL.md +0 -138
- package/dist/skills/agnostic/quality/tdd/deep-modules.md +0 -33
- package/dist/skills/agnostic/quality/tdd/interface-design.md +0 -31
- package/dist/skills/agnostic/quality/tdd/mocking.md +0 -59
- package/dist/skills/agnostic/quality/tdd/refactoring.md +0 -10
- package/dist/skills/agnostic/quality/tdd/tests.md +0 -61
- package/dist/skills/agnostic/requirements/requirements-grill/SKILL.md +0 -44
- package/dist/skills/agnostic/requirements/requirements-grill/references/artifact-output.md +0 -157
- package/dist/skills/agnostic/requirements/requirements-grill/references/grilling-flow.md +0 -69
- package/dist/skills/agnostic/requirements/requirements-grill/references/wiki-output.md +0 -101
- package/dist/skills/agnostic/requirements/write-backlog/EXAMPLES.md +0 -67
- package/dist/skills/agnostic/requirements/write-backlog/REFERENCE.md +0 -262
- package/dist/skills/agnostic/requirements/write-backlog/SKILL.md +0 -71
- package/dist/skills/agnostic/requirements/write-backlog/assets/concepts/backlog-model.md +0 -69
- package/dist/skills/agnostic/requirements/write-backlog/assets/concepts/story-shape.md +0 -66
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/azure-devops-create-payload.md +0 -63
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/github-projects-create-payload.md +0 -224
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/linear-create-payload.md +0 -76
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/monday-create-payload.md +0 -146
- package/dist/skills/agnostic/research/improve-codebase-architecture/REFERENCE.md +0 -78
- package/dist/skills/agnostic/research/improve-codebase-architecture/SKILL.md +0 -76
- package/dist/skills/agnostic/research/parallel-research/SKILL.md +0 -68
- package/dist/skills/agnostic/research/parallel-research/agents/openai.yaml +0 -4
- package/dist/skills/agnostic/subagents/swarm-planner/SKILL.md +0 -179
- package/dist/skills/agnostic/write-a-skill/SKILL.md +0 -117
- package/dist/skills/frameworks/better-auth/better-auth-best-practices/SKILL.md +0 -166
- package/dist/skills/frameworks/better-auth/better-auth-security-best-practices/SKILL.MD +0 -432
- package/dist/skills/frameworks/effect/effect-authoring/SKILL.md +0 -116
- package/dist/skills/frameworks/effect/effect-authoring/references/branded-types.md +0 -98
- package/dist/skills/frameworks/effect/effect-authoring/references/effect-atom-patterns.md +0 -257
- package/dist/skills/frameworks/effect/effect-authoring/references/effect-primitives.md +0 -144
- package/dist/skills/frameworks/effect/effect-authoring/references/error-patterns.md +0 -156
- package/dist/skills/frameworks/effect/effect-authoring/references/otel-patterns.md +0 -113
- package/dist/skills/frameworks/effect/effect-authoring/references/test-patterns.md +0 -146
- package/dist/skills/frameworks/effect/effect-backend-structure/SKILL.md +0 -96
- package/dist/skills/frameworks/effect/effect-backend-structure/agents/openai.yaml +0 -4
- package/dist/skills/frameworks/effect/effect-backend-structure/references/layout.md +0 -68
- package/dist/skills/frameworks/effect/effect-best-practices/SKILL.md +0 -517
- package/dist/skills/frameworks/effect/effect-best-practices/references/anti-patterns.md +0 -392
- package/dist/skills/frameworks/effect/effect-best-practices/references/effect-atom-patterns.md +0 -653
- package/dist/skills/frameworks/effect/effect-best-practices/references/error-patterns.md +0 -464
- package/dist/skills/frameworks/effect/effect-best-practices/references/language-server.md +0 -287
- package/dist/skills/frameworks/effect/effect-best-practices/references/layer-patterns.md +0 -495
- package/dist/skills/frameworks/effect/effect-best-practices/references/observability-patterns.md +0 -342
- package/dist/skills/frameworks/effect/effect-best-practices/references/rpc-cluster-patterns.md +0 -418
- package/dist/skills/frameworks/effect/effect-best-practices/references/schema-patterns.md +0 -353
- package/dist/skills/frameworks/effect/effect-best-practices/references/service-patterns.md +0 -299
- package/dist/skills/frameworks/effect/effect-recoverable-actions/SKILL.md +0 -65
- package/dist/skills/frameworks/effect/effect-recoverable-actions/agents/openai.yaml +0 -4
- package/dist/skills/frameworks/effect/effect-recoverable-actions/references/flow-examples.md +0 -154
- package/dist/skills/frameworks/effect/effect-recoverable-actions/references/source-backed-primitives.md +0 -104
- package/dist/skills/frameworks/effect/effect-recoverable-actions/references/strategy-matrix.md +0 -34
- package/dist/skills/frameworks/effect/effect-recoverable-actions/references/test-matrix.md +0 -36
- package/dist/skills/frameworks/elysia/elysiajs/SKILL.md +0 -475
- package/dist/skills/frameworks/elysia/elysiajs/examples/basic.ts +0 -9
- package/dist/skills/frameworks/elysia/elysiajs/examples/body-parser.ts +0 -33
- package/dist/skills/frameworks/elysia/elysiajs/examples/complex.ts +0 -112
- package/dist/skills/frameworks/elysia/elysiajs/examples/cookie.ts +0 -45
- package/dist/skills/frameworks/elysia/elysiajs/examples/error.ts +0 -38
- package/dist/skills/frameworks/elysia/elysiajs/examples/file.ts +0 -10
- package/dist/skills/frameworks/elysia/elysiajs/examples/guard.ts +0 -34
- package/dist/skills/frameworks/elysia/elysiajs/examples/map-response.ts +0 -15
- package/dist/skills/frameworks/elysia/elysiajs/examples/redirect.ts +0 -6
- package/dist/skills/frameworks/elysia/elysiajs/examples/rename.ts +0 -32
- package/dist/skills/frameworks/elysia/elysiajs/examples/schema.ts +0 -61
- package/dist/skills/frameworks/elysia/elysiajs/examples/state.ts +0 -6
- package/dist/skills/frameworks/elysia/elysiajs/examples/upload-file.ts +0 -20
- package/dist/skills/frameworks/elysia/elysiajs/examples/websocket.ts +0 -25
- package/dist/skills/frameworks/elysia/elysiajs/integrations/ai-sdk.md +0 -92
- package/dist/skills/frameworks/elysia/elysiajs/integrations/astro.md +0 -59
- package/dist/skills/frameworks/elysia/elysiajs/integrations/better-auth.md +0 -117
- package/dist/skills/frameworks/elysia/elysiajs/integrations/cloudflare-worker.md +0 -95
- package/dist/skills/frameworks/elysia/elysiajs/integrations/deno.md +0 -34
- package/dist/skills/frameworks/elysia/elysiajs/integrations/drizzle.md +0 -258
- package/dist/skills/frameworks/elysia/elysiajs/integrations/expo.md +0 -95
- package/dist/skills/frameworks/elysia/elysiajs/integrations/nextjs.md +0 -103
- package/dist/skills/frameworks/elysia/elysiajs/integrations/nodejs.md +0 -64
- package/dist/skills/frameworks/elysia/elysiajs/integrations/nuxt.md +0 -67
- package/dist/skills/frameworks/elysia/elysiajs/integrations/prisma.md +0 -93
- package/dist/skills/frameworks/elysia/elysiajs/integrations/react-email.md +0 -134
- package/dist/skills/frameworks/elysia/elysiajs/integrations/sveltekit.md +0 -53
- package/dist/skills/frameworks/elysia/elysiajs/integrations/tanstack-start.md +0 -87
- package/dist/skills/frameworks/elysia/elysiajs/integrations/vercel.md +0 -55
- package/dist/skills/frameworks/elysia/elysiajs/patterns/mvc.md +0 -380
- package/dist/skills/frameworks/elysia/elysiajs/plugins/bearer.md +0 -30
- package/dist/skills/frameworks/elysia/elysiajs/plugins/cors.md +0 -141
- package/dist/skills/frameworks/elysia/elysiajs/plugins/cron.md +0 -265
- package/dist/skills/frameworks/elysia/elysiajs/plugins/graphql-apollo.md +0 -90
- package/dist/skills/frameworks/elysia/elysiajs/plugins/graphql-yoga.md +0 -87
- package/dist/skills/frameworks/elysia/elysiajs/plugins/html.md +0 -188
- package/dist/skills/frameworks/elysia/elysiajs/plugins/jwt.md +0 -197
- package/dist/skills/frameworks/elysia/elysiajs/plugins/openapi.md +0 -246
- package/dist/skills/frameworks/elysia/elysiajs/plugins/opentelemetry.md +0 -167
- package/dist/skills/frameworks/elysia/elysiajs/plugins/server-timing.md +0 -71
- package/dist/skills/frameworks/elysia/elysiajs/plugins/static.md +0 -84
- package/dist/skills/frameworks/elysia/elysiajs/references/bun-fullstack-dev-server.md +0 -129
- package/dist/skills/frameworks/elysia/elysiajs/references/cookie.md +0 -187
- package/dist/skills/frameworks/elysia/elysiajs/references/deployment.md +0 -413
- package/dist/skills/frameworks/elysia/elysiajs/references/eden.md +0 -158
- package/dist/skills/frameworks/elysia/elysiajs/references/lifecycle.md +0 -198
- package/dist/skills/frameworks/elysia/elysiajs/references/macro.md +0 -83
- package/dist/skills/frameworks/elysia/elysiajs/references/plugin.md +0 -207
- package/dist/skills/frameworks/elysia/elysiajs/references/route.md +0 -331
- package/dist/skills/frameworks/elysia/elysiajs/references/testing.md +0 -385
- package/dist/skills/frameworks/elysia/elysiajs/references/validation.md +0 -491
- package/dist/skills/frameworks/elysia/elysiajs/references/websocket.md +0 -250
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/.github/workflows/branch-protection.yml +0 -24
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/.github/workflows/deploy.yml +0 -61
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/AGENTS.md +0 -5958
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/SKILL.md +0 -130
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/api-use-dto-serialization.md +0 -182
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/api-use-interceptors.md +0 -202
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/api-use-pipes.md +0 -205
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/api-versioning.md +0 -191
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/arch-avoid-circular-deps.md +0 -80
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/arch-feature-modules.md +0 -82
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/arch-module-sharing.md +0 -141
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/arch-single-responsibility.md +0 -106
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/arch-use-events.md +0 -108
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/arch-use-repository-pattern.md +0 -97
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/db-avoid-n-plus-one.md +0 -139
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/db-use-migrations.md +0 -129
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/db-use-transactions.md +0 -140
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/devops-graceful-shutdown.md +0 -222
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/devops-use-config-module.md +0 -167
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/devops-use-logging.md +0 -232
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/di-avoid-service-locator.md +0 -104
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/di-interface-segregation.md +0 -165
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/di-liskov-substitution.md +0 -221
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/di-prefer-constructor-injection.md +0 -86
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/di-scope-awareness.md +0 -94
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/di-use-interfaces-tokens.md +0 -101
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/error-handle-async-errors.md +0 -125
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/error-throw-http-exceptions.md +0 -114
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/error-use-exception-filters.md +0 -140
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/micro-use-health-checks.md +0 -226
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/micro-use-patterns.md +0 -167
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/micro-use-queues.md +0 -252
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/perf-async-hooks.md +0 -109
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/perf-lazy-loading.md +0 -121
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/perf-optimize-database.md +0 -131
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/perf-use-caching.md +0 -128
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/security-auth-jwt.md +0 -146
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/security-rate-limiting.md +0 -125
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/security-sanitize-output.md +0 -139
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/security-use-guards.md +0 -135
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/security-validate-all-input.md +0 -150
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/test-e2e-supertest.md +0 -178
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/test-mock-external-services.md +0 -179
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/test-use-testing-module.md +0 -153
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/scripts/build-agents.ts +0 -299
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/scripts/build.sh +0 -16
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/scripts/package-lock.json +0 -237
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/scripts/package.json +0 -15
- package/dist/skills/frameworks/nestjs/nestjs-expert/SKILL.md +0 -208
- package/dist/skills/frameworks/nestjs/nestjs-expert/references/authentication.md +0 -166
- package/dist/skills/frameworks/nestjs/nestjs-expert/references/controllers-routing.md +0 -111
- package/dist/skills/frameworks/nestjs/nestjs-expert/references/dtos-validation.md +0 -153
- package/dist/skills/frameworks/nestjs/nestjs-expert/references/migration-from-express.md +0 -1237
- package/dist/skills/frameworks/nestjs/nestjs-expert/references/services-di.md +0 -140
- package/dist/skills/frameworks/nestjs/nestjs-expert/references/testing-patterns.md +0 -186
- package/dist/skills/frameworks/nextjs/next-best-practices/SKILL.md +0 -153
- package/dist/skills/frameworks/nextjs/next-best-practices/async-patterns.md +0 -87
- package/dist/skills/frameworks/nextjs/next-best-practices/bundling.md +0 -180
- package/dist/skills/frameworks/nextjs/next-best-practices/data-patterns.md +0 -297
- package/dist/skills/frameworks/nextjs/next-best-practices/debug-tricks.md +0 -105
- package/dist/skills/frameworks/nextjs/next-best-practices/directives.md +0 -73
- package/dist/skills/frameworks/nextjs/next-best-practices/error-handling.md +0 -227
- package/dist/skills/frameworks/nextjs/next-best-practices/file-conventions.md +0 -140
- package/dist/skills/frameworks/nextjs/next-best-practices/font.md +0 -245
- package/dist/skills/frameworks/nextjs/next-best-practices/functions.md +0 -108
- package/dist/skills/frameworks/nextjs/next-best-practices/hydration-error.md +0 -91
- package/dist/skills/frameworks/nextjs/next-best-practices/image.md +0 -173
- package/dist/skills/frameworks/nextjs/next-best-practices/metadata.md +0 -301
- package/dist/skills/frameworks/nextjs/next-best-practices/parallel-routes.md +0 -287
- package/dist/skills/frameworks/nextjs/next-best-practices/route-handlers.md +0 -146
- package/dist/skills/frameworks/nextjs/next-best-practices/rsc-boundaries.md +0 -159
- package/dist/skills/frameworks/nextjs/next-best-practices/runtime-selection.md +0 -39
- package/dist/skills/frameworks/nextjs/next-best-practices/scripts.md +0 -141
- package/dist/skills/frameworks/nextjs/next-best-practices/self-hosting.md +0 -371
- package/dist/skills/frameworks/nextjs/next-best-practices/suspense-boundaries.md +0 -67
- package/dist/skills/frameworks/nextjs/next-cache-components/SKILL.md +0 -360
- package/dist/skills/frameworks/react/async-react-patterns/SKILL.md +0 -78
- package/dist/skills/frameworks/react/vercel-composition-patterns/AGENTS.md +0 -946
- package/dist/skills/frameworks/react/vercel-composition-patterns/SKILL.md +0 -89
- package/dist/skills/frameworks/react/vercel-composition-patterns/rules/architecture-avoid-boolean-props.md +0 -100
- package/dist/skills/frameworks/react/vercel-composition-patterns/rules/architecture-compound-components.md +0 -112
- package/dist/skills/frameworks/react/vercel-composition-patterns/rules/patterns-children-over-render-props.md +0 -87
- package/dist/skills/frameworks/react/vercel-composition-patterns/rules/patterns-explicit-variants.md +0 -100
- package/dist/skills/frameworks/react/vercel-composition-patterns/rules/react19-no-forwardref.md +0 -42
- package/dist/skills/frameworks/react/vercel-composition-patterns/rules/state-context-interface.md +0 -191
- package/dist/skills/frameworks/react/vercel-composition-patterns/rules/state-decouple-implementation.md +0 -113
- package/dist/skills/frameworks/react/vercel-composition-patterns/rules/state-lift-state.md +0 -125
- package/dist/skills/frameworks/react/vercel-react-best-practices/AGENTS.md +0 -3750
- package/dist/skills/frameworks/react/vercel-react-best-practices/SKILL.md +0 -148
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/advanced-effect-event-deps.md +0 -56
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/advanced-event-handler-refs.md +0 -55
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/advanced-init-once.md +0 -42
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/advanced-use-latest.md +0 -39
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/async-api-routes.md +0 -38
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/async-cheap-condition-before-await.md +0 -37
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/async-defer-await.md +0 -82
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/async-dependencies.md +0 -51
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/async-parallel.md +0 -28
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/async-suspense-boundaries.md +0 -99
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/bundle-barrel-imports.md +0 -60
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/bundle-conditional.md +0 -31
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/bundle-defer-third-party.md +0 -49
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/bundle-dynamic-imports.md +0 -35
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/bundle-preload.md +0 -50
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/client-event-listeners.md +0 -74
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/client-localstorage-schema.md +0 -71
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/client-passive-event-listeners.md +0 -48
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/client-swr-dedup.md +0 -56
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/js-batch-dom-css.md +0 -107
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/js-cache-function-results.md +0 -80
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/js-cache-property-access.md +0 -28
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/js-cache-storage.md +0 -70
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/js-combine-iterations.md +0 -32
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/js-early-exit.md +0 -50
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/js-flatmap-filter.md +0 -60
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/js-hoist-regexp.md +0 -45
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/js-index-maps.md +0 -37
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/js-length-check-first.md +0 -49
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/js-min-max-loop.md +0 -82
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/js-request-idle-callback.md +0 -105
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/js-set-map-lookups.md +0 -24
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/js-tosorted-immutable.md +0 -57
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rendering-activity.md +0 -26
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rendering-animate-svg-wrapper.md +0 -47
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rendering-conditional-render.md +0 -40
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rendering-content-visibility.md +0 -38
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rendering-hoist-jsx.md +0 -46
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rendering-hydration-no-flicker.md +0 -82
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rendering-hydration-suppress-warning.md +0 -30
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rendering-resource-hints.md +0 -85
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rendering-script-defer-async.md +0 -68
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rendering-svg-precision.md +0 -28
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rendering-usetransition-loading.md +0 -75
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rerender-defer-reads.md +0 -39
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rerender-dependencies.md +0 -45
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rerender-derived-state-no-effect.md +0 -40
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rerender-derived-state.md +0 -29
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rerender-functional-setstate.md +0 -74
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rerender-lazy-state-init.md +0 -58
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rerender-memo-with-default-value.md +0 -38
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rerender-memo.md +0 -44
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rerender-move-effect-to-event.md +0 -45
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rerender-no-inline-components.md +0 -82
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rerender-simple-expression-in-memo.md +0 -35
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rerender-split-combined-hooks.md +0 -64
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rerender-transitions.md +0 -40
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rerender-use-deferred-value.md +0 -59
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/rerender-use-ref-transient-values.md +0 -73
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/server-after-nonblocking.md +0 -73
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/server-auth-actions.md +0 -96
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/server-cache-lru.md +0 -41
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/server-cache-react.md +0 -76
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/server-dedup-props.md +0 -65
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/server-hoist-static-io.md +0 -149
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/server-no-shared-module-state.md +0 -50
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/server-parallel-fetching.md +0 -83
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/server-parallel-nested-fetching.md +0 -34
- package/dist/skills/frameworks/react/vercel-react-best-practices/rules/server-serialization.md +0 -38
- package/dist/skills/frameworks/tanstack-query/tanstack-query/.claude-plugin/plugin.json +0 -12
- package/dist/skills/frameworks/tanstack-query/tanstack-query/SKILL.md +0 -849
- package/dist/skills/frameworks/tanstack-query/tanstack-query/assets/example-template.txt +0 -14
- package/dist/skills/frameworks/tanstack-query/tanstack-query/references/best-practices.md +0 -304
- package/dist/skills/frameworks/tanstack-query/tanstack-query/references/common-patterns.md +0 -271
- package/dist/skills/frameworks/tanstack-query/tanstack-query/references/example-reference.md +0 -26
- package/dist/skills/frameworks/tanstack-query/tanstack-query/references/testing.md +0 -282
- package/dist/skills/frameworks/tanstack-query/tanstack-query/references/top-errors.md +0 -332
- package/dist/skills/frameworks/tanstack-query/tanstack-query/references/typescript-patterns.md +0 -291
- package/dist/skills/frameworks/tanstack-query/tanstack-query/references/v4-to-v5-migration.md +0 -231
- package/dist/skills/frameworks/tanstack-query/tanstack-query/rules/tanstack-query.md +0 -126
- package/dist/skills/frameworks/tanstack-query/tanstack-query/scripts/example-script.sh +0 -15
- package/dist/skills/frameworks/tanstack-query/tanstack-query/templates/custom-hooks-pattern.tsx +0 -281
- package/dist/skills/frameworks/tanstack-query/tanstack-query/templates/devtools-setup.tsx +0 -248
- package/dist/skills/frameworks/tanstack-query/tanstack-query/templates/error-boundary.tsx +0 -243
- package/dist/skills/frameworks/tanstack-query/tanstack-query/templates/package.json +0 -31
- package/dist/skills/frameworks/tanstack-query/tanstack-query/templates/provider-setup.tsx +0 -50
- package/dist/skills/frameworks/tanstack-query/tanstack-query/templates/query-client-config.ts +0 -72
- package/dist/skills/frameworks/tanstack-query/tanstack-query/templates/use-infinite-query.tsx +0 -214
- package/dist/skills/frameworks/tanstack-query/tanstack-query/templates/use-mutation-basic.tsx +0 -201
- package/dist/skills/frameworks/tanstack-query/tanstack-query/templates/use-mutation-optimistic.tsx +0 -234
- package/dist/skills/frameworks/tanstack-query/tanstack-query/templates/use-query-basic.tsx +0 -119
- package/dist/skills/frameworks/tanstack-start/tanstack-start/SKILL.md +0 -250
- package/dist/skills/frameworks/trpc/tanstack-query/.claude-plugin/plugin.json +0 -12
- package/dist/skills/frameworks/trpc/tanstack-query/SKILL.md +0 -1058
- package/dist/skills/frameworks/trpc/tanstack-query/assets/example-template.txt +0 -14
- package/dist/skills/frameworks/trpc/tanstack-query/references/best-practices.md +0 -304
- package/dist/skills/frameworks/trpc/tanstack-query/references/common-patterns.md +0 -271
- package/dist/skills/frameworks/trpc/tanstack-query/references/example-reference.md +0 -26
- package/dist/skills/frameworks/trpc/tanstack-query/references/testing.md +0 -282
- package/dist/skills/frameworks/trpc/tanstack-query/references/top-errors.md +0 -332
- package/dist/skills/frameworks/trpc/tanstack-query/references/typescript-patterns.md +0 -291
- package/dist/skills/frameworks/trpc/tanstack-query/references/v4-to-v5-migration.md +0 -231
- package/dist/skills/frameworks/trpc/tanstack-query/rules/tanstack-query.md +0 -126
- package/dist/skills/frameworks/trpc/tanstack-query/scripts/example-script.sh +0 -15
- package/dist/skills/frameworks/trpc/tanstack-query/templates/custom-hooks-pattern.tsx +0 -281
- package/dist/skills/frameworks/trpc/tanstack-query/templates/devtools-setup.tsx +0 -248
- package/dist/skills/frameworks/trpc/tanstack-query/templates/error-boundary.tsx +0 -243
- package/dist/skills/frameworks/trpc/tanstack-query/templates/package.json +0 -31
- package/dist/skills/frameworks/trpc/tanstack-query/templates/provider-setup.tsx +0 -50
- package/dist/skills/frameworks/trpc/tanstack-query/templates/query-client-config.ts +0 -72
- package/dist/skills/frameworks/trpc/tanstack-query/templates/use-infinite-query.tsx +0 -214
- package/dist/skills/frameworks/trpc/tanstack-query/templates/use-mutation-basic.tsx +0 -201
- package/dist/skills/frameworks/trpc/tanstack-query/templates/use-mutation-optimistic.tsx +0 -234
- package/dist/skills/frameworks/trpc/tanstack-query/templates/use-query-basic.tsx +0 -119
- package/dist/skills/frameworks/turborepo/turborepo/SKILL.md +0 -914
- package/dist/skills/frameworks/turborepo/turborepo/command/turborepo.md +0 -70
- package/dist/skills/frameworks/turborepo/turborepo/references/best-practices/RULE.md +0 -241
- package/dist/skills/frameworks/turborepo/turborepo/references/best-practices/dependencies.md +0 -246
- package/dist/skills/frameworks/turborepo/turborepo/references/best-practices/packages.md +0 -335
- package/dist/skills/frameworks/turborepo/turborepo/references/best-practices/structure.md +0 -270
- package/dist/skills/frameworks/turborepo/turborepo/references/boundaries/RULE.md +0 -126
- package/dist/skills/frameworks/turborepo/turborepo/references/caching/RULE.md +0 -107
- package/dist/skills/frameworks/turborepo/turborepo/references/caching/gotchas.md +0 -169
- package/dist/skills/frameworks/turborepo/turborepo/references/caching/remote-cache.md +0 -127
- package/dist/skills/frameworks/turborepo/turborepo/references/ci/RULE.md +0 -79
- package/dist/skills/frameworks/turborepo/turborepo/references/ci/github-actions.md +0 -162
- package/dist/skills/frameworks/turborepo/turborepo/references/ci/patterns.md +0 -145
- package/dist/skills/frameworks/turborepo/turborepo/references/ci/vercel.md +0 -103
- package/dist/skills/frameworks/turborepo/turborepo/references/cli/RULE.md +0 -100
- package/dist/skills/frameworks/turborepo/turborepo/references/cli/commands.md +0 -297
- package/dist/skills/frameworks/turborepo/turborepo/references/configuration/RULE.md +0 -211
- package/dist/skills/frameworks/turborepo/turborepo/references/configuration/global-options.md +0 -187
- package/dist/skills/frameworks/turborepo/turborepo/references/configuration/gotchas.md +0 -348
- package/dist/skills/frameworks/turborepo/turborepo/references/configuration/tasks.md +0 -285
- package/dist/skills/frameworks/turborepo/turborepo/references/environment/RULE.md +0 -96
- package/dist/skills/frameworks/turborepo/turborepo/references/environment/gotchas.md +0 -141
- package/dist/skills/frameworks/turborepo/turborepo/references/environment/modes.md +0 -101
- package/dist/skills/frameworks/turborepo/turborepo/references/filtering/RULE.md +0 -148
- package/dist/skills/frameworks/turborepo/turborepo/references/filtering/patterns.md +0 -152
- package/dist/skills/frameworks/turborepo/turborepo/references/watch/RULE.md +0 -99
- package/dist/skills/languages/python/async-python-patterns/SKILL.md +0 -735
- package/dist/skills/languages/python/python-code-style/SKILL.md +0 -360
- package/dist/skills/languages/python/python-design-patterns/SKILL.md +0 -433
- package/dist/skills/languages/python/python-project-structure/SKILL.md +0 -252
- package/dist/skills/languages/python/python-testing-patterns/SKILL.md +0 -622
- package/dist/skills/languages/python/python-testing-patterns/references/advanced-patterns.md +0 -411
- package/dist/skills/languages/typescript/quality-types/SKILL.md +0 -93
- package/dist/skills/phases/bug-discovery-phase/REFERENCE.md +0 -170
- package/dist/skills/phases/bug-discovery-phase/SKILL.md +0 -85
- package/dist/skills/phases/bug-resolution-phase/REFERENCE.md +0 -160
- package/dist/skills/phases/bug-resolution-phase/SKILL.md +0 -64
- package/dist/skills/phases/debugging-phase/SKILL.md +0 -88
- package/dist/skills/phases/delivery-phase/SKILL.md +0 -50
- package/dist/skills/phases/delivery-phase/phases/closeout.md +0 -33
- package/dist/skills/phases/delivery-phase/phases/debug.md +0 -30
- package/dist/skills/phases/delivery-phase/phases/docs-ingest.md +0 -27
- package/dist/skills/phases/delivery-phase/phases/implement.md +0 -30
- package/dist/skills/phases/delivery-phase/phases/plan.md +0 -27
- package/dist/skills/phases/delivery-phase/phases/review.md +0 -29
- package/dist/skills/phases/delivery-phase/phases/router.md +0 -46
- package/dist/skills/phases/delivery-phase/phases/spec.md +0 -26
- package/dist/skills/phases/delivery-phase/references/artifact-state.md +0 -42
- package/dist/skills/phases/delivery-phase/references/phase-handoff.md +0 -25
- package/dist/skills/phases/docs-ingest-phase/SKILL.md +0 -46
- package/dist/skills/phases/docs-ingest-phase/agents/openai.yaml +0 -4
- package/dist/skills/phases/docs-ingest-phase/phases/private-internal.md +0 -57
- package/dist/skills/phases/docs-ingest-phase/phases/public-docs.md +0 -52
- package/dist/skills/phases/docs-ingest-phase/phases/router.md +0 -42
- package/dist/skills/phases/docs-ingest-phase/references/concept-pages.md +0 -70
- package/dist/skills/phases/docs-ingest-phase/references/flow-pages.md +0 -56
- package/dist/skills/phases/docs-ingest-phase/references/fumadocs-routing.md +0 -74
- package/dist/skills/phases/docs-ingest-phase/references/learning-artifacts.md +0 -96
- package/dist/skills/phases/docs-ingest-phase/references/public-docs.md +0 -90
- package/dist/skills/phases/docs-ingest-phase/references/repo-docs.md +0 -38
- package/dist/skills/phases/docs-ingest-phase/references/wiki-ingest.md +0 -133
- package/dist/skills/phases/goalify/EXAMPLES.md +0 -78
- package/dist/skills/phases/goalify/SKILL.md +0 -129
- package/dist/skills/phases/requirements-phase/SKILL.md +0 -70
- package/dist/skills/phases/resolve-debt-phase/SKILL.md +0 -87
- package/dist/skills/phases/review-phase/SKILL.md +0 -118
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Use Guards for Authentication and Authorization
|
|
3
|
-
impact: HIGH
|
|
4
|
-
impactDescription: Enforces access control before handlers execute
|
|
5
|
-
tags: security, guards, authentication, authorization
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## Use Guards for Authentication and Authorization
|
|
9
|
-
|
|
10
|
-
Guards determine whether a request should be handled based on authentication state, roles, permissions, or other conditions. They run after middleware but before pipes and interceptors, making them ideal for access control. Use guards instead of manual checks in controllers.
|
|
11
|
-
|
|
12
|
-
**Incorrect (manual auth checks in every handler):**
|
|
13
|
-
|
|
14
|
-
```typescript
|
|
15
|
-
// Manual auth checks in every handler
|
|
16
|
-
@Controller('admin')
|
|
17
|
-
export class AdminController {
|
|
18
|
-
@Get('users')
|
|
19
|
-
async getUsers(@Request() req) {
|
|
20
|
-
if (!req.user) {
|
|
21
|
-
throw new UnauthorizedException();
|
|
22
|
-
}
|
|
23
|
-
if (!req.user.roles.includes('admin')) {
|
|
24
|
-
throw new ForbiddenException();
|
|
25
|
-
}
|
|
26
|
-
return this.adminService.getUsers();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
@Delete('users/:id')
|
|
30
|
-
async deleteUser(@Request() req, @Param('id') id: string) {
|
|
31
|
-
if (!req.user) {
|
|
32
|
-
throw new UnauthorizedException();
|
|
33
|
-
}
|
|
34
|
-
if (!req.user.roles.includes('admin')) {
|
|
35
|
-
throw new ForbiddenException();
|
|
36
|
-
}
|
|
37
|
-
return this.adminService.deleteUser(id);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
**Correct (guards with declarative decorators):**
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
// JWT Auth Guard
|
|
46
|
-
@Injectable()
|
|
47
|
-
export class JwtAuthGuard implements CanActivate {
|
|
48
|
-
constructor(
|
|
49
|
-
private jwtService: JwtService,
|
|
50
|
-
private reflector: Reflector,
|
|
51
|
-
) {}
|
|
52
|
-
|
|
53
|
-
async canActivate(context: ExecutionContext): Promise<boolean> {
|
|
54
|
-
// Check for @Public() decorator
|
|
55
|
-
const isPublic = this.reflector.getAllAndOverride<boolean>('isPublic', [
|
|
56
|
-
context.getHandler(),
|
|
57
|
-
context.getClass(),
|
|
58
|
-
]);
|
|
59
|
-
if (isPublic) return true;
|
|
60
|
-
|
|
61
|
-
const request = context.switchToHttp().getRequest();
|
|
62
|
-
const token = this.extractToken(request);
|
|
63
|
-
|
|
64
|
-
if (!token) {
|
|
65
|
-
throw new UnauthorizedException('No token provided');
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
try {
|
|
69
|
-
request.user = await this.jwtService.verifyAsync(token);
|
|
70
|
-
return true;
|
|
71
|
-
} catch {
|
|
72
|
-
throw new UnauthorizedException('Invalid token');
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
private extractToken(request: Request): string | undefined {
|
|
77
|
-
const [type, token] = request.headers.authorization?.split(' ') ?? [];
|
|
78
|
-
return type === 'Bearer' ? token : undefined;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Roles Guard
|
|
83
|
-
@Injectable()
|
|
84
|
-
export class RolesGuard implements CanActivate {
|
|
85
|
-
constructor(private reflector: Reflector) {}
|
|
86
|
-
|
|
87
|
-
canActivate(context: ExecutionContext): boolean {
|
|
88
|
-
const requiredRoles = this.reflector.getAllAndOverride<Role[]>('roles', [
|
|
89
|
-
context.getHandler(),
|
|
90
|
-
context.getClass(),
|
|
91
|
-
]);
|
|
92
|
-
|
|
93
|
-
if (!requiredRoles) return true;
|
|
94
|
-
|
|
95
|
-
const { user } = context.switchToHttp().getRequest();
|
|
96
|
-
return requiredRoles.some((role) => user.roles?.includes(role));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Decorators
|
|
101
|
-
export const Public = () => SetMetadata('isPublic', true);
|
|
102
|
-
export const Roles = (...roles: Role[]) => SetMetadata('roles', roles);
|
|
103
|
-
|
|
104
|
-
// Register guards globally
|
|
105
|
-
@Module({
|
|
106
|
-
providers: [
|
|
107
|
-
{ provide: APP_GUARD, useClass: JwtAuthGuard },
|
|
108
|
-
{ provide: APP_GUARD, useClass: RolesGuard },
|
|
109
|
-
],
|
|
110
|
-
})
|
|
111
|
-
export class AppModule {}
|
|
112
|
-
|
|
113
|
-
// Clean controller
|
|
114
|
-
@Controller('admin')
|
|
115
|
-
@Roles(Role.Admin) // Applied to all routes
|
|
116
|
-
export class AdminController {
|
|
117
|
-
@Get('users')
|
|
118
|
-
getUsers(): Promise<User[]> {
|
|
119
|
-
return this.adminService.getUsers();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
@Delete('users/:id')
|
|
123
|
-
deleteUser(@Param('id') id: string): Promise<void> {
|
|
124
|
-
return this.adminService.deleteUser(id);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
@Public() // Override: no auth required
|
|
128
|
-
@Get('health')
|
|
129
|
-
health() {
|
|
130
|
-
return { status: 'ok' };
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
Reference: [NestJS Guards](https://docs.nestjs.com/guards)
|
package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/security-validate-all-input.md
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Validate All Input with DTOs and Pipes
|
|
3
|
-
impact: HIGH
|
|
4
|
-
impactDescription: First line of defense against attacks
|
|
5
|
-
tags: security, validation, dto, pipes
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## Validate All Input with DTOs and Pipes
|
|
9
|
-
|
|
10
|
-
Always validate incoming data using class-validator decorators on DTOs and the global ValidationPipe. Never trust user input. Validate all request bodies, query parameters, and route parameters before processing.
|
|
11
|
-
|
|
12
|
-
**Incorrect (trust raw input without validation):**
|
|
13
|
-
|
|
14
|
-
```typescript
|
|
15
|
-
// Trust raw input without validation
|
|
16
|
-
@Controller('users')
|
|
17
|
-
export class UsersController {
|
|
18
|
-
@Post()
|
|
19
|
-
create(@Body() body: any) {
|
|
20
|
-
// body could contain anything - SQL injection, XSS, etc.
|
|
21
|
-
return this.usersService.create(body);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
@Get()
|
|
25
|
-
findAll(@Query() query: any) {
|
|
26
|
-
// query.limit could be "'; DROP TABLE users; --"
|
|
27
|
-
return this.usersService.findAll(query.limit);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// DTOs without validation decorators
|
|
32
|
-
export class CreateUserDto {
|
|
33
|
-
name: string; // No validation
|
|
34
|
-
email: string; // Could be "not-an-email"
|
|
35
|
-
age: number; // Could be "abc" or -999
|
|
36
|
-
}
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
**Correct (validated DTOs with global ValidationPipe):**
|
|
40
|
-
|
|
41
|
-
```typescript
|
|
42
|
-
// Enable ValidationPipe globally in main.ts
|
|
43
|
-
async function bootstrap() {
|
|
44
|
-
const app = await NestFactory.create(AppModule);
|
|
45
|
-
|
|
46
|
-
app.useGlobalPipes(
|
|
47
|
-
new ValidationPipe({
|
|
48
|
-
whitelist: true, // Strip unknown properties
|
|
49
|
-
forbidNonWhitelisted: true, // Throw on unknown properties
|
|
50
|
-
transform: true, // Auto-transform to DTO types
|
|
51
|
-
transformOptions: {
|
|
52
|
-
enableImplicitConversion: true,
|
|
53
|
-
},
|
|
54
|
-
}),
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
await app.listen(3000);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Create well-validated DTOs
|
|
61
|
-
import {
|
|
62
|
-
IsString,
|
|
63
|
-
IsEmail,
|
|
64
|
-
IsInt,
|
|
65
|
-
Min,
|
|
66
|
-
Max,
|
|
67
|
-
IsOptional,
|
|
68
|
-
MinLength,
|
|
69
|
-
MaxLength,
|
|
70
|
-
Matches,
|
|
71
|
-
IsNotEmpty,
|
|
72
|
-
} from 'class-validator';
|
|
73
|
-
import { Transform, Type } from 'class-transformer';
|
|
74
|
-
|
|
75
|
-
export class CreateUserDto {
|
|
76
|
-
@IsString()
|
|
77
|
-
@IsNotEmpty()
|
|
78
|
-
@MinLength(2)
|
|
79
|
-
@MaxLength(100)
|
|
80
|
-
@Transform(({ value }) => value?.trim())
|
|
81
|
-
name: string;
|
|
82
|
-
|
|
83
|
-
@IsEmail()
|
|
84
|
-
@Transform(({ value }) => value?.toLowerCase().trim())
|
|
85
|
-
email: string;
|
|
86
|
-
|
|
87
|
-
@IsInt()
|
|
88
|
-
@Min(0)
|
|
89
|
-
@Max(150)
|
|
90
|
-
age: number;
|
|
91
|
-
|
|
92
|
-
@IsString()
|
|
93
|
-
@MinLength(8)
|
|
94
|
-
@MaxLength(100)
|
|
95
|
-
@Matches(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)/, {
|
|
96
|
-
message: 'Password must contain uppercase, lowercase, and number',
|
|
97
|
-
})
|
|
98
|
-
password: string;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Query DTO with defaults and transformation
|
|
102
|
-
export class FindUsersQueryDto {
|
|
103
|
-
@IsOptional()
|
|
104
|
-
@IsString()
|
|
105
|
-
@MaxLength(100)
|
|
106
|
-
search?: string;
|
|
107
|
-
|
|
108
|
-
@IsOptional()
|
|
109
|
-
@Type(() => Number)
|
|
110
|
-
@IsInt()
|
|
111
|
-
@Min(1)
|
|
112
|
-
@Max(100)
|
|
113
|
-
limit: number = 20;
|
|
114
|
-
|
|
115
|
-
@IsOptional()
|
|
116
|
-
@Type(() => Number)
|
|
117
|
-
@IsInt()
|
|
118
|
-
@Min(0)
|
|
119
|
-
offset: number = 0;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Param validation
|
|
123
|
-
export class UserIdParamDto {
|
|
124
|
-
@IsUUID('4')
|
|
125
|
-
id: string;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
@Controller('users')
|
|
129
|
-
export class UsersController {
|
|
130
|
-
@Post()
|
|
131
|
-
create(@Body() dto: CreateUserDto): Promise<User> {
|
|
132
|
-
// dto is guaranteed to be valid
|
|
133
|
-
return this.usersService.create(dto);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
@Get()
|
|
137
|
-
findAll(@Query() query: FindUsersQueryDto): Promise<User[]> {
|
|
138
|
-
// query.limit is a number, query.search is sanitized
|
|
139
|
-
return this.usersService.findAll(query);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
@Get(':id')
|
|
143
|
-
findOne(@Param() params: UserIdParamDto): Promise<User> {
|
|
144
|
-
// params.id is a valid UUID
|
|
145
|
-
return this.usersService.findById(params.id);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
Reference: [NestJS Validation](https://docs.nestjs.com/techniques/validation)
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Use Supertest for E2E Testing
|
|
3
|
-
impact: HIGH
|
|
4
|
-
impactDescription: Validates the full request/response cycle
|
|
5
|
-
tags: testing, e2e, supertest, integration
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## Use Supertest for E2E Testing
|
|
9
|
-
|
|
10
|
-
End-to-end tests use Supertest to make real HTTP requests against your NestJS application. They test the full stack including middleware, guards, pipes, and interceptors. E2E tests catch integration issues that unit tests miss.
|
|
11
|
-
|
|
12
|
-
**Incorrect (no proper E2E setup or teardown):**
|
|
13
|
-
|
|
14
|
-
```typescript
|
|
15
|
-
// Only unit test controllers
|
|
16
|
-
describe('UsersController', () => {
|
|
17
|
-
it('should return users', async () => {
|
|
18
|
-
const service = { findAll: jest.fn().mockResolvedValue([]) };
|
|
19
|
-
const controller = new UsersController(service as any);
|
|
20
|
-
|
|
21
|
-
const result = await controller.findAll();
|
|
22
|
-
|
|
23
|
-
expect(result).toEqual([]);
|
|
24
|
-
// Doesn't test: routes, guards, pipes, serialization
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// E2E tests without proper setup/teardown
|
|
29
|
-
describe('Users API', () => {
|
|
30
|
-
it('should create user', async () => {
|
|
31
|
-
const app = await NestFactory.create(AppModule);
|
|
32
|
-
// No proper initialization
|
|
33
|
-
// No cleanup after test
|
|
34
|
-
// Hits real database
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
**Correct (proper E2E setup with Supertest):**
|
|
40
|
-
|
|
41
|
-
```typescript
|
|
42
|
-
// Proper E2E test setup
|
|
43
|
-
import { Test, TestingModule } from '@nestjs/testing';
|
|
44
|
-
import { INestApplication, ValidationPipe } from '@nestjs/common';
|
|
45
|
-
import * as request from 'supertest';
|
|
46
|
-
import { AppModule } from '../src/app.module';
|
|
47
|
-
|
|
48
|
-
describe('UsersController (e2e)', () => {
|
|
49
|
-
let app: INestApplication;
|
|
50
|
-
|
|
51
|
-
beforeAll(async () => {
|
|
52
|
-
const moduleFixture: TestingModule = await Test.createTestingModule({
|
|
53
|
-
imports: [AppModule],
|
|
54
|
-
}).compile();
|
|
55
|
-
|
|
56
|
-
app = moduleFixture.createNestApplication();
|
|
57
|
-
|
|
58
|
-
// Apply same config as production
|
|
59
|
-
app.useGlobalPipes(
|
|
60
|
-
new ValidationPipe({
|
|
61
|
-
whitelist: true,
|
|
62
|
-
transform: true,
|
|
63
|
-
forbidNonWhitelisted: true,
|
|
64
|
-
}),
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
await app.init();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
afterAll(async () => {
|
|
71
|
-
await app.close();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
describe('/users (POST)', () => {
|
|
75
|
-
it('should create a user', () => {
|
|
76
|
-
return request(app.getHttpServer())
|
|
77
|
-
.post('/users')
|
|
78
|
-
.send({ name: 'John', email: 'john@test.com' })
|
|
79
|
-
.expect(201)
|
|
80
|
-
.expect((res) => {
|
|
81
|
-
expect(res.body).toHaveProperty('id');
|
|
82
|
-
expect(res.body.name).toBe('John');
|
|
83
|
-
expect(res.body.email).toBe('john@test.com');
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('should return 400 for invalid email', () => {
|
|
88
|
-
return request(app.getHttpServer())
|
|
89
|
-
.post('/users')
|
|
90
|
-
.send({ name: 'John', email: 'invalid-email' })
|
|
91
|
-
.expect(400)
|
|
92
|
-
.expect((res) => {
|
|
93
|
-
expect(res.body.message).toContain('email');
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe('/users/:id (GET)', () => {
|
|
99
|
-
it('should return 404 for non-existent user', () => {
|
|
100
|
-
return request(app.getHttpServer())
|
|
101
|
-
.get('/users/non-existent-id')
|
|
102
|
-
.expect(404);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
// Testing with authentication
|
|
108
|
-
describe('Protected Routes (e2e)', () => {
|
|
109
|
-
let app: INestApplication;
|
|
110
|
-
let authToken: string;
|
|
111
|
-
|
|
112
|
-
beforeAll(async () => {
|
|
113
|
-
const moduleFixture = await Test.createTestingModule({
|
|
114
|
-
imports: [AppModule],
|
|
115
|
-
}).compile();
|
|
116
|
-
|
|
117
|
-
app = moduleFixture.createNestApplication();
|
|
118
|
-
app.useGlobalPipes(new ValidationPipe({ whitelist: true }));
|
|
119
|
-
await app.init();
|
|
120
|
-
|
|
121
|
-
// Get auth token
|
|
122
|
-
const loginResponse = await request(app.getHttpServer())
|
|
123
|
-
.post('/auth/login')
|
|
124
|
-
.send({ email: 'test@test.com', password: 'password' });
|
|
125
|
-
|
|
126
|
-
authToken = loginResponse.body.accessToken;
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('should return 401 without token', () => {
|
|
130
|
-
return request(app.getHttpServer())
|
|
131
|
-
.get('/users/me')
|
|
132
|
-
.expect(401);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('should return user profile with valid token', () => {
|
|
136
|
-
return request(app.getHttpServer())
|
|
137
|
-
.get('/users/me')
|
|
138
|
-
.set('Authorization', `Bearer ${authToken}`)
|
|
139
|
-
.expect(200)
|
|
140
|
-
.expect((res) => {
|
|
141
|
-
expect(res.body.email).toBe('test@test.com');
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
// Database isolation for E2E tests
|
|
147
|
-
describe('Orders API (e2e)', () => {
|
|
148
|
-
let app: INestApplication;
|
|
149
|
-
let dataSource: DataSource;
|
|
150
|
-
|
|
151
|
-
beforeAll(async () => {
|
|
152
|
-
const moduleFixture = await Test.createTestingModule({
|
|
153
|
-
imports: [
|
|
154
|
-
ConfigModule.forRoot({
|
|
155
|
-
envFilePath: '.env.test', // Test database config
|
|
156
|
-
}),
|
|
157
|
-
AppModule,
|
|
158
|
-
],
|
|
159
|
-
}).compile();
|
|
160
|
-
|
|
161
|
-
app = moduleFixture.createNestApplication();
|
|
162
|
-
dataSource = moduleFixture.get(DataSource);
|
|
163
|
-
await app.init();
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
beforeEach(async () => {
|
|
167
|
-
// Clean database between tests
|
|
168
|
-
await dataSource.synchronize(true);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
afterAll(async () => {
|
|
172
|
-
await dataSource.destroy();
|
|
173
|
-
await app.close();
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
Reference: [NestJS E2E Testing](https://docs.nestjs.com/fundamentals/testing#end-to-end-testing)
|
package/dist/skills/frameworks/nestjs/nestjs-best-practices/rules/test-mock-external-services.md
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Mock External Services in Tests
|
|
3
|
-
impact: HIGH
|
|
4
|
-
impactDescription: Ensures fast, reliable, deterministic tests
|
|
5
|
-
tags: testing, mocking, external-services, jest
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## Mock External Services in Tests
|
|
9
|
-
|
|
10
|
-
Never call real external services (APIs, databases, message queues) in unit tests. Mock them to ensure tests are fast, deterministic, and don't incur costs. Use realistic mock data and test edge cases like timeouts and errors.
|
|
11
|
-
|
|
12
|
-
**Incorrect (calling real APIs and databases):**
|
|
13
|
-
|
|
14
|
-
```typescript
|
|
15
|
-
// Call real APIs in tests
|
|
16
|
-
describe('PaymentService', () => {
|
|
17
|
-
it('should process payment', async () => {
|
|
18
|
-
const service = new PaymentService(new StripeClient(realApiKey));
|
|
19
|
-
// Hits real Stripe API!
|
|
20
|
-
const result = await service.charge('tok_visa', 1000);
|
|
21
|
-
// Slow, costs money, flaky
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
// Use real database
|
|
26
|
-
describe('UsersService', () => {
|
|
27
|
-
beforeEach(async () => {
|
|
28
|
-
await connection.query('DELETE FROM users'); // Modifies real DB
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('should create user', async () => {
|
|
32
|
-
const user = await service.create({ email: 'test@test.com' });
|
|
33
|
-
// Side effects on shared database
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// Incomplete mocks
|
|
38
|
-
const mockHttpService = {
|
|
39
|
-
get: jest.fn().mockResolvedValue({ data: {} }),
|
|
40
|
-
// Missing error scenarios, missing other methods
|
|
41
|
-
};
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
**Correct (mock all external dependencies):**
|
|
45
|
-
|
|
46
|
-
```typescript
|
|
47
|
-
// Mock HTTP service properly
|
|
48
|
-
describe('WeatherService', () => {
|
|
49
|
-
let service: WeatherService;
|
|
50
|
-
let httpService: jest.Mocked<HttpService>;
|
|
51
|
-
|
|
52
|
-
beforeEach(async () => {
|
|
53
|
-
const module = await Test.createTestingModule({
|
|
54
|
-
providers: [
|
|
55
|
-
WeatherService,
|
|
56
|
-
{
|
|
57
|
-
provide: HttpService,
|
|
58
|
-
useValue: {
|
|
59
|
-
get: jest.fn(),
|
|
60
|
-
post: jest.fn(),
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
}).compile();
|
|
65
|
-
|
|
66
|
-
service = module.get(WeatherService);
|
|
67
|
-
httpService = module.get(HttpService);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('should return weather data', async () => {
|
|
71
|
-
const mockResponse = {
|
|
72
|
-
data: { temperature: 72, humidity: 45 },
|
|
73
|
-
status: 200,
|
|
74
|
-
statusText: 'OK',
|
|
75
|
-
headers: {},
|
|
76
|
-
config: {},
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
httpService.get.mockReturnValue(of(mockResponse));
|
|
80
|
-
|
|
81
|
-
const result = await service.getWeather('NYC');
|
|
82
|
-
|
|
83
|
-
expect(result).toEqual({ temperature: 72, humidity: 45 });
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('should handle API timeout', async () => {
|
|
87
|
-
httpService.get.mockReturnValue(
|
|
88
|
-
throwError(() => new Error('ETIMEDOUT')),
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
await expect(service.getWeather('NYC')).rejects.toThrow('Weather service unavailable');
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('should handle rate limiting', async () => {
|
|
95
|
-
httpService.get.mockReturnValue(
|
|
96
|
-
throwError(() => ({
|
|
97
|
-
response: { status: 429, data: { message: 'Rate limited' } },
|
|
98
|
-
})),
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
await expect(service.getWeather('NYC')).rejects.toThrow(TooManyRequestsException);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// Mock repository instead of database
|
|
106
|
-
describe('UsersService', () => {
|
|
107
|
-
let service: UsersService;
|
|
108
|
-
let repo: jest.Mocked<Repository<User>>;
|
|
109
|
-
|
|
110
|
-
beforeEach(async () => {
|
|
111
|
-
const mockRepo = {
|
|
112
|
-
find: jest.fn(),
|
|
113
|
-
findOne: jest.fn(),
|
|
114
|
-
save: jest.fn(),
|
|
115
|
-
delete: jest.fn(),
|
|
116
|
-
createQueryBuilder: jest.fn(),
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const module = await Test.createTestingModule({
|
|
120
|
-
providers: [
|
|
121
|
-
UsersService,
|
|
122
|
-
{ provide: getRepositoryToken(User), useValue: mockRepo },
|
|
123
|
-
],
|
|
124
|
-
}).compile();
|
|
125
|
-
|
|
126
|
-
service = module.get(UsersService);
|
|
127
|
-
repo = module.get(getRepositoryToken(User));
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('should find user by id', async () => {
|
|
131
|
-
const mockUser = { id: '1', name: 'John', email: 'john@test.com' };
|
|
132
|
-
repo.findOne.mockResolvedValue(mockUser);
|
|
133
|
-
|
|
134
|
-
const result = await service.findById('1');
|
|
135
|
-
|
|
136
|
-
expect(result).toEqual(mockUser);
|
|
137
|
-
expect(repo.findOne).toHaveBeenCalledWith({ where: { id: '1' } });
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
// Create mock factory for complex SDKs
|
|
142
|
-
function createMockStripe(): jest.Mocked<Stripe> {
|
|
143
|
-
return {
|
|
144
|
-
paymentIntents: {
|
|
145
|
-
create: jest.fn(),
|
|
146
|
-
retrieve: jest.fn(),
|
|
147
|
-
confirm: jest.fn(),
|
|
148
|
-
cancel: jest.fn(),
|
|
149
|
-
},
|
|
150
|
-
customers: {
|
|
151
|
-
create: jest.fn(),
|
|
152
|
-
retrieve: jest.fn(),
|
|
153
|
-
},
|
|
154
|
-
} as any;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Mock time for time-dependent tests
|
|
158
|
-
describe('TokenService', () => {
|
|
159
|
-
beforeEach(() => {
|
|
160
|
-
jest.useFakeTimers();
|
|
161
|
-
jest.setSystemTime(new Date('2024-01-15'));
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
afterEach(() => {
|
|
165
|
-
jest.useRealTimers();
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('should expire token after 1 hour', async () => {
|
|
169
|
-
const token = await service.createToken();
|
|
170
|
-
|
|
171
|
-
// Fast-forward time
|
|
172
|
-
jest.advanceTimersByTime(61 * 60 * 1000);
|
|
173
|
-
|
|
174
|
-
expect(await service.isValid(token)).toBe(false);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
Reference: [Jest Mocking](https://jestjs.io/docs/mock-functions)
|