claude-code-templates 1.21.6 → 1.21.7
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/package.json +2 -2
- package/components/agents/ai-specialists/ai-ethics-advisor.md +0 -195
- package/components/agents/ai-specialists/hackathon-ai-strategist.md +0 -46
- package/components/agents/ai-specialists/llms-maintainer.md +0 -94
- package/components/agents/ai-specialists/model-evaluator.md +0 -150
- package/components/agents/ai-specialists/prompt-engineer.md +0 -112
- package/components/agents/ai-specialists/search-specialist.md +0 -59
- package/components/agents/ai-specialists/task-decomposition-expert.md +0 -97
- package/components/agents/api-graphql/graphql-architect.md +0 -208
- package/components/agents/api-graphql/graphql-performance-optimizer.md +0 -357
- package/components/agents/api-graphql/graphql-security-specialist.md +0 -519
- package/components/agents/blockchain-web3/smart-contract-auditor.md +0 -32
- package/components/agents/blockchain-web3/smart-contract-specialist.md +0 -32
- package/components/agents/blockchain-web3/web3-integration-specialist.md +0 -32
- package/components/agents/business-marketing/business-analyst.md +0 -194
- package/components/agents/business-marketing/content-marketer.md +0 -36
- package/components/agents/business-marketing/customer-support.md +0 -36
- package/components/agents/business-marketing/legal-advisor.md +0 -50
- package/components/agents/business-marketing/marketing-attribution-analyst.md +0 -352
- package/components/agents/business-marketing/payment-integration.md +0 -33
- package/components/agents/business-marketing/product-strategist.md +0 -212
- package/components/agents/business-marketing/risk-manager.md +0 -42
- package/components/agents/business-marketing/sales-automator.md +0 -36
- package/components/agents/data-ai/ai-engineer.md +0 -33
- package/components/agents/data-ai/computer-vision-engineer.md +0 -562
- package/components/agents/data-ai/data-engineer.md +0 -33
- package/components/agents/data-ai/data-scientist.md +0 -337
- package/components/agents/data-ai/ml-engineer.md +0 -33
- package/components/agents/data-ai/mlops-engineer.md +0 -58
- package/components/agents/data-ai/nlp-engineer.md +0 -680
- package/components/agents/data-ai/quant-analyst.md +0 -33
- package/components/agents/database/database-admin.md +0 -33
- package/components/agents/database/database-architect.md +0 -590
- package/components/agents/database/database-optimization.md +0 -33
- package/components/agents/database/database-optimizer.md +0 -33
- package/components/agents/database/nosql-specialist.md +0 -708
- package/components/agents/database/supabase-schema-architect.md +0 -138
- package/components/agents/deep-research-team/academic-researcher.md +0 -33
- package/components/agents/deep-research-team/agent-overview.md +0 -235
- package/components/agents/deep-research-team/competitive-intelligence-analyst.md +0 -530
- package/components/agents/deep-research-team/data-analyst.md +0 -112
- package/components/agents/deep-research-team/fact-checker.md +0 -553
- package/components/agents/deep-research-team/query-clarifier.md +0 -73
- package/components/agents/deep-research-team/report-generator.md +0 -108
- package/components/agents/deep-research-team/research-brief-generator.md +0 -108
- package/components/agents/deep-research-team/research-coordinator.md +0 -94
- package/components/agents/deep-research-team/research-orchestrator.md +0 -119
- package/components/agents/deep-research-team/research-synthesizer.md +0 -109
- package/components/agents/deep-research-team/technical-researcher.md +0 -95
- package/components/agents/development-team/backend-architect.md +0 -31
- package/components/agents/development-team/cli-ui-designer.md +0 -405
- package/components/agents/development-team/devops-engineer.md +0 -886
- package/components/agents/development-team/frontend-developer.md +0 -32
- package/components/agents/development-team/fullstack-developer.md +0 -1205
- package/components/agents/development-team/ios-developer.md +0 -36
- package/components/agents/development-team/mobile-developer.md +0 -33
- package/components/agents/development-team/ui-ux-designer.md +0 -36
- package/components/agents/development-tools/code-reviewer.md +0 -30
- package/components/agents/development-tools/command-expert.md +0 -422
- package/components/agents/development-tools/context-manager.md +0 -65
- package/components/agents/development-tools/debugger.md +0 -31
- package/components/agents/development-tools/dx-optimizer.md +0 -64
- package/components/agents/development-tools/error-detective.md +0 -33
- package/components/agents/development-tools/mcp-expert.md +0 -259
- package/components/agents/development-tools/performance-profiler.md +0 -799
- package/components/agents/development-tools/test-engineer.md +0 -936
- package/components/agents/devops-infrastructure/cloud-architect.md +0 -33
- package/components/agents/devops-infrastructure/deployment-engineer.md +0 -33
- package/components/agents/devops-infrastructure/devops-troubleshooter.md +0 -33
- package/components/agents/devops-infrastructure/monitoring-specialist.md +0 -36
- package/components/agents/devops-infrastructure/network-engineer.md +0 -33
- package/components/agents/devops-infrastructure/security-engineer.md +0 -971
- package/components/agents/devops-infrastructure/terraform-specialist.md +0 -36
- package/components/agents/devops-infrastructure/vercel-deployment-specialist.md +0 -357
- package/components/agents/documentation/api-documenter.md +0 -33
- package/components/agents/documentation/changelog-generator.md +0 -37
- package/components/agents/documentation/docusaurus-expert.md +0 -52
- package/components/agents/documentation/technical-writer.md +0 -37
- package/components/agents/expert-advisors/agent-expert.md +0 -477
- package/components/agents/expert-advisors/architect-review.md +0 -50
- package/components/agents/expert-advisors/dependency-manager.md +0 -45
- package/components/agents/expert-advisors/documentation-expert.md +0 -47
- package/components/agents/ffmpeg-clip-team/audio-mixer.md +0 -37
- package/components/agents/ffmpeg-clip-team/audio-quality-controller.md +0 -100
- package/components/agents/ffmpeg-clip-team/podcast-content-analyzer.md +0 -60
- package/components/agents/ffmpeg-clip-team/podcast-metadata-specialist.md +0 -46
- package/components/agents/ffmpeg-clip-team/podcast-transcriber.md +0 -68
- package/components/agents/ffmpeg-clip-team/social-media-clip-creator.md +0 -69
- package/components/agents/ffmpeg-clip-team/timestamp-precision-specialist.md +0 -98
- package/components/agents/ffmpeg-clip-team/video-editor.md +0 -37
- package/components/agents/game-development/3d-artist.md +0 -37
- package/components/agents/game-development/game-designer.md +0 -37
- package/components/agents/game-development/unity-game-developer.md +0 -110
- package/components/agents/game-development/unreal-engine-developer.md +0 -128
- package/components/agents/mcp-dev-team/mcp-deployment-orchestrator.md +0 -101
- package/components/agents/mcp-dev-team/mcp-integration-engineer.md +0 -37
- package/components/agents/mcp-dev-team/mcp-protocol-specialist.md +0 -37
- package/components/agents/mcp-dev-team/mcp-registry-navigator.md +0 -112
- package/components/agents/mcp-dev-team/mcp-security-auditor.md +0 -70
- package/components/agents/mcp-dev-team/mcp-server-architect.md +0 -74
- package/components/agents/mcp-dev-team/mcp-testing-engineer.md +0 -106
- package/components/agents/modernization/architecture-modernizer.md +0 -37
- package/components/agents/modernization/cloud-migration-specialist.md +0 -37
- package/components/agents/modernization/legacy-modernizer.md +0 -33
- package/components/agents/obsidian-ops-team/Scripts/daily_notes_connector.py +0 -306
- package/components/agents/obsidian-ops-team/Scripts/enhance_tag_standardizer.py +0 -343
- package/components/agents/obsidian-ops-team/Scripts/find_keyword_connections.py +0 -216
- package/components/agents/obsidian-ops-team/Scripts/fix_quoted_tags.py +0 -82
- package/components/agents/obsidian-ops-team/Scripts/implement_entity_connections.py +0 -195
- package/components/agents/obsidian-ops-team/Scripts/link_suggester.py +0 -301
- package/components/agents/obsidian-ops-team/Scripts/metadata_adder.py +0 -197
- package/components/agents/obsidian-ops-team/Scripts/moc_generator.py +0 -296
- package/components/agents/obsidian-ops-team/Scripts/parse_keyword_connections.py +0 -122
- package/components/agents/obsidian-ops-team/Scripts/tag_standardizer.py +0 -387
- package/components/agents/obsidian-ops-team/connection-agent.md +0 -67
- package/components/agents/obsidian-ops-team/content-curator.md +0 -81
- package/components/agents/obsidian-ops-team/metadata-agent.md +0 -51
- package/components/agents/obsidian-ops-team/moc-agent.md +0 -112
- package/components/agents/obsidian-ops-team/review-agent.md +0 -94
- package/components/agents/obsidian-ops-team/tag-agent.md +0 -92
- package/components/agents/obsidian-ops-team/vault-optimizer.md +0 -76
- package/components/agents/ocr-extraction-team/document-structure-analyzer.md +0 -37
- package/components/agents/ocr-extraction-team/markdown-syntax-formatter.md +0 -58
- package/components/agents/ocr-extraction-team/ocr-grammar-fixer.md +0 -36
- package/components/agents/ocr-extraction-team/ocr-preprocessing-optimizer.md +0 -37
- package/components/agents/ocr-extraction-team/ocr-quality-assurance.md +0 -62
- package/components/agents/ocr-extraction-team/text-comparison-validator.md +0 -60
- package/components/agents/ocr-extraction-team/visual-analysis-ocr.md +0 -52
- package/components/agents/performance-testing/load-testing-specialist.md +0 -37
- package/components/agents/performance-testing/performance-engineer.md +0 -33
- package/components/agents/performance-testing/react-performance-optimization.md +0 -65
- package/components/agents/performance-testing/test-automator.md +0 -33
- package/components/agents/performance-testing/web-vitals-optimizer.md +0 -37
- package/components/agents/podcast-creator-team/academic-research-synthesizer.md +0 -61
- package/components/agents/podcast-creator-team/comprehensive-researcher.md +0 -49
- package/components/agents/podcast-creator-team/episode-orchestrator.md +0 -52
- package/components/agents/podcast-creator-team/guest-outreach-coordinator.md +0 -37
- package/components/agents/podcast-creator-team/market-research-analyst.md +0 -54
- package/components/agents/podcast-creator-team/podcast-editor.md +0 -37
- package/components/agents/podcast-creator-team/podcast-trend-scout.md +0 -60
- package/components/agents/podcast-creator-team/project-supervisor-orchestrator.md +0 -48
- package/components/agents/podcast-creator-team/seo-podcast-optimizer.md +0 -58
- package/components/agents/podcast-creator-team/social-media-copywriter.md +0 -57
- package/components/agents/podcast-creator-team/twitter-ai-influencer-manager.md +0 -62
- package/components/agents/programming-languages/c-pro.md +0 -36
- package/components/agents/programming-languages/c-sharp-pro.md +0 -40
- package/components/agents/programming-languages/cpp-pro.md +0 -39
- package/components/agents/programming-languages/golang-pro.md +0 -33
- package/components/agents/programming-languages/javascript-pro.md +0 -36
- package/components/agents/programming-languages/php-pro.md +0 -44
- package/components/agents/programming-languages/python-pro.md +0 -33
- package/components/agents/programming-languages/rust-pro.md +0 -36
- package/components/agents/programming-languages/shell-scripting-pro.md +0 -38
- package/components/agents/programming-languages/sql-pro.md +0 -36
- package/components/agents/programming-languages/typescript-pro.md +0 -38
- package/components/agents/realtime/supabase-realtime-optimizer.md +0 -193
- package/components/agents/security/api-security-audit.md +0 -93
- package/components/agents/security/compliance-specialist.md +0 -37
- package/components/agents/security/incident-responder.md +0 -75
- package/components/agents/security/penetration-tester.md +0 -37
- package/components/agents/security/security-auditor.md +0 -33
- package/components/agents/web-tools/nextjs-architecture-expert.md +0 -194
- package/components/agents/web-tools/react-performance-optimizer.md +0 -425
- package/components/agents/web-tools/seo-analyzer.md +0 -37
- package/components/agents/web-tools/url-context-validator.md +0 -61
- package/components/agents/web-tools/url-link-extractor.md +0 -59
- package/components/agents/web-tools/web-accessibility-checker.md +0 -37
- package/components/commands/automation/act.md +0 -57
- package/components/commands/automation/ci-pipeline.md +0 -378
- package/components/commands/automation/husky.md +0 -130
- package/components/commands/automation/workflow-orchestrator.md +0 -576
- package/components/commands/database/supabase-backup-manager.md +0 -37
- package/components/commands/database/supabase-data-explorer.md +0 -37
- package/components/commands/database/supabase-migration-assistant.md +0 -37
- package/components/commands/database/supabase-performance-optimizer.md +0 -37
- package/components/commands/database/supabase-realtime-monitor.md +0 -37
- package/components/commands/database/supabase-schema-sync.md +0 -37
- package/components/commands/database/supabase-security-audit.md +0 -37
- package/components/commands/database/supabase-type-generator.md +0 -37
- package/components/commands/deployment/add-changelog.md +0 -92
- package/components/commands/deployment/blue-green-deployment.md +0 -824
- package/components/commands/deployment/changelog-demo-command.md +0 -43
- package/components/commands/deployment/ci-setup.md +0 -323
- package/components/commands/deployment/containerize-application.md +0 -93
- package/components/commands/deployment/deployment-monitoring.md +0 -1228
- package/components/commands/deployment/hotfix-deploy.md +0 -283
- package/components/commands/deployment/prepare-release.md +0 -357
- package/components/commands/deployment/rollback-deploy.md +0 -145
- package/components/commands/deployment/setup-automated-releases.md +0 -143
- package/components/commands/deployment/setup-kubernetes-deployment.md +0 -93
- package/components/commands/documentation/create-architecture-documentation.md +0 -95
- package/components/commands/documentation/create-onboarding-guide.md +0 -93
- package/components/commands/documentation/doc-api.md +0 -242
- package/components/commands/documentation/docs-maintenance.md +0 -119
- package/components/commands/documentation/generate-api-documentation.md +0 -97
- package/components/commands/documentation/interactive-documentation.md +0 -133
- package/components/commands/documentation/load-llms-txt.md +0 -39
- package/components/commands/documentation/migration-guide.md +0 -250
- package/components/commands/documentation/troubleshooting-guide.md +0 -370
- package/components/commands/documentation/update-docs.md +0 -107
- package/components/commands/game-development/game-analytics-integration.md +0 -128
- package/components/commands/game-development/game-asset-pipeline.md +0 -108
- package/components/commands/game-development/game-performance-profiler.md +0 -78
- package/components/commands/game-development/game-testing-framework.md +0 -112
- package/components/commands/game-development/unity-project-setup.md +0 -190
- package/components/commands/git-workflow/branch-cleanup.md +0 -181
- package/components/commands/git-workflow/commit.md +0 -167
- package/components/commands/git-workflow/create-pr.md +0 -19
- package/components/commands/git-workflow/create-pull-request.md +0 -126
- package/components/commands/git-workflow/create-worktrees.md +0 -174
- package/components/commands/git-workflow/fix-github-issue.md +0 -13
- package/components/commands/git-workflow/git-bisect-helper.md +0 -261
- package/components/commands/git-workflow/pr-review.md +0 -76
- package/components/commands/git-workflow/update-branch-name.md +0 -9
- package/components/commands/nextjs-vercel/nextjs-api-tester.md +0 -480
- package/components/commands/nextjs-vercel/nextjs-bundle-analyzer.md +0 -406
- package/components/commands/nextjs-vercel/nextjs-component-generator.md +0 -489
- package/components/commands/nextjs-vercel/nextjs-middleware-creator.md +0 -712
- package/components/commands/nextjs-vercel/nextjs-migration-helper.md +0 -778
- package/components/commands/nextjs-vercel/nextjs-performance-audit.md +0 -653
- package/components/commands/nextjs-vercel/nextjs-scaffold.md +0 -237
- package/components/commands/nextjs-vercel/vercel-deploy-optimize.md +0 -341
- package/components/commands/nextjs-vercel/vercel-edge-function.md +0 -810
- package/components/commands/nextjs-vercel/vercel-env-sync.md +0 -666
- package/components/commands/orchestration/archive.md +0 -414
- package/components/commands/orchestration/commit.md +0 -305
- package/components/commands/orchestration/find.md +0 -272
- package/components/commands/orchestration/log.md +0 -355
- package/components/commands/orchestration/move.md +0 -220
- package/components/commands/orchestration/optimize.md +0 -375
- package/components/commands/orchestration/remove.md +0 -301
- package/components/commands/orchestration/report.md +0 -292
- package/components/commands/orchestration/resume.md +0 -256
- package/components/commands/orchestration/start.md +0 -169
- package/components/commands/orchestration/status.md +0 -219
- package/components/commands/orchestration/sync.md +0 -294
- package/components/commands/performance/add-performance-monitoring.md +0 -84
- package/components/commands/performance/implement-caching-strategy.md +0 -84
- package/components/commands/performance/optimize-api-performance.md +0 -119
- package/components/commands/performance/optimize-build.md +0 -139
- package/components/commands/performance/optimize-bundle-size.md +0 -84
- package/components/commands/performance/optimize-database-performance.md +0 -84
- package/components/commands/performance/optimize-memory-usage.md +0 -91
- package/components/commands/performance/performance-audit.md +0 -89
- package/components/commands/performance/setup-cdn-optimization.md +0 -84
- package/components/commands/performance/system-behavior-simulator.md +0 -415
- package/components/commands/project-management/add-package.md +0 -90
- package/components/commands/project-management/add-to-changelog.md +0 -37
- package/components/commands/project-management/create-feature.md +0 -130
- package/components/commands/project-management/create-jtbd.md +0 -37
- package/components/commands/project-management/create-prd.md +0 -36
- package/components/commands/project-management/create-prp.md +0 -37
- package/components/commands/project-management/init-project.md +0 -80
- package/components/commands/project-management/milestone-tracker.md +0 -44
- package/components/commands/project-management/pac-configure.md +0 -32
- package/components/commands/project-management/pac-create-epic.md +0 -41
- package/components/commands/project-management/pac-create-ticket.md +0 -42
- package/components/commands/project-management/pac-update-status.md +0 -39
- package/components/commands/project-management/pac-validate.md +0 -35
- package/components/commands/project-management/project-health-check.md +0 -58
- package/components/commands/project-management/project-timeline-simulator.md +0 -37
- package/components/commands/project-management/project-to-linear.md +0 -38
- package/components/commands/project-management/release.md +0 -31
- package/components/commands/project-management/todo.md +0 -62
- package/components/commands/security/add-authentication-system.md +0 -34
- package/components/commands/security/dependency-audit.md +0 -32
- package/components/commands/security/penetration-test.md +0 -40
- package/components/commands/security/secrets-scanner.md +0 -39
- package/components/commands/security/security-audit.md +0 -82
- package/components/commands/security/security-hardening.md +0 -33
- package/components/commands/setup/create-database-migrations.md +0 -35
- package/components/commands/setup/design-database-schema.md +0 -37
- package/components/commands/setup/design-rest-api.md +0 -37
- package/components/commands/setup/implement-graphql-api.md +0 -37
- package/components/commands/setup/migrate-to-typescript.md +0 -37
- package/components/commands/setup/setup-ci-cd-pipeline.md +0 -37
- package/components/commands/setup/setup-development-environment.md +0 -37
- package/components/commands/setup/setup-docker-containers.md +0 -37
- package/components/commands/setup/setup-formatting.md +0 -37
- package/components/commands/setup/setup-linting.md +0 -37
- package/components/commands/setup/setup-monitoring-observability.md +0 -37
- package/components/commands/setup/setup-monorepo.md +0 -37
- package/components/commands/setup/setup-rate-limiting.md +0 -37
- package/components/commands/setup/update-dependencies.md +0 -35
- package/components/commands/simulation/business-scenario-explorer.md +0 -37
- package/components/commands/simulation/constraint-modeler.md +0 -37
- package/components/commands/simulation/decision-tree-explorer.md +0 -37
- package/components/commands/simulation/digital-twin-creator.md +0 -37
- package/components/commands/simulation/future-scenario-generator.md +0 -37
- package/components/commands/simulation/market-response-modeler.md +0 -37
- package/components/commands/simulation/monte-carlo-simulator.md +0 -37
- package/components/commands/simulation/simulation-calibrator.md +0 -37
- package/components/commands/simulation/system-dynamics-modeler.md +0 -37
- package/components/commands/simulation/timeline-compressor.md +0 -37
- package/components/commands/svelte/svelte:a11y.md +0 -105
- package/components/commands/svelte/svelte:component.md +0 -81
- package/components/commands/svelte/svelte:debug.md +0 -48
- package/components/commands/svelte/svelte:migrate.md +0 -79
- package/components/commands/svelte/svelte:optimize.md +0 -99
- package/components/commands/svelte/svelte:scaffold.md +0 -89
- package/components/commands/svelte/svelte:storybook-migrate.md +0 -204
- package/components/commands/svelte/svelte:storybook-mock.md +0 -213
- package/components/commands/svelte/svelte:storybook-setup.md +0 -113
- package/components/commands/svelte/svelte:storybook-story.md +0 -145
- package/components/commands/svelte/svelte:storybook-troubleshoot.md +0 -191
- package/components/commands/svelte/svelte:storybook.md +0 -48
- package/components/commands/svelte/svelte:test-coverage.md +0 -77
- package/components/commands/svelte/svelte:test-fix.md +0 -74
- package/components/commands/svelte/svelte:test-setup.md +0 -85
- package/components/commands/svelte/svelte:test.md +0 -60
- package/components/commands/sync/bidirectional-sync.md +0 -37
- package/components/commands/sync/bulk-import-issues.md +0 -37
- package/components/commands/sync/cross-reference-manager.md +0 -37
- package/components/commands/sync/issue-to-linear-task.md +0 -37
- package/components/commands/sync/linear-task-to-issue.md +0 -37
- package/components/commands/sync/sync-automation-setup.md +0 -37
- package/components/commands/sync/sync-conflict-resolver.md +0 -37
- package/components/commands/sync/sync-health-monitor.md +0 -37
- package/components/commands/sync/sync-issues-to-linear.md +0 -37
- package/components/commands/sync/sync-linear-to-issues.md +0 -37
- package/components/commands/sync/sync-migration-assistant.md +0 -37
- package/components/commands/sync/sync-pr-to-task.md +0 -37
- package/components/commands/sync/sync-status.md +0 -391
- package/components/commands/sync/task-from-pr.md +0 -37
- package/components/commands/team/architecture-review.md +0 -37
- package/components/commands/team/decision-quality-analyzer.md +0 -37
- package/components/commands/team/dependency-mapper.md +0 -37
- package/components/commands/team/estimate-assistant.md +0 -37
- package/components/commands/team/issue-triage.md +0 -37
- package/components/commands/team/memory-spring-cleaning.md +0 -37
- package/components/commands/team/migration-assistant.md +0 -37
- package/components/commands/team/retrospective-analyzer.md +0 -37
- package/components/commands/team/session-learning-capture.md +0 -37
- package/components/commands/team/sprint-planning.md +0 -189
- package/components/commands/team/standup-report.md +0 -37
- package/components/commands/team/team-knowledge-mapper.md +0 -37
- package/components/commands/team/team-velocity-tracker.md +0 -37
- package/components/commands/team/team-workload-balancer.md +0 -37
- package/components/commands/testing/add-mutation-testing.md +0 -37
- package/components/commands/testing/add-property-based-testing.md +0 -37
- package/components/commands/testing/e2e-setup.md +0 -37
- package/components/commands/testing/generate-test-cases.md +0 -37
- package/components/commands/testing/generate-tests.md +0 -82
- package/components/commands/testing/setup-comprehensive-testing.md +0 -37
- package/components/commands/testing/setup-load-testing.md +0 -37
- package/components/commands/testing/setup-visual-testing.md +0 -37
- package/components/commands/testing/test-automation-orchestrator.md +0 -37
- package/components/commands/testing/test-changelog-automation.md +0 -37
- package/components/commands/testing/test-coverage.md +0 -37
- package/components/commands/testing/test-quality-analyzer.md +0 -37
- package/components/commands/testing/testing_plan_integration.md +0 -37
- package/components/commands/testing/write-tests.md +0 -37
- package/components/commands/utilities/all-tools.md +0 -31
- package/components/commands/utilities/architecture-scenario-explorer.md +0 -375
- package/components/commands/utilities/check-file.md +0 -53
- package/components/commands/utilities/clean-branches.md +0 -243
- package/components/commands/utilities/clean.md +0 -1
- package/components/commands/utilities/code-permutation-tester.md +0 -341
- package/components/commands/utilities/code-review.md +0 -70
- package/components/commands/utilities/code-to-task.md +0 -583
- package/components/commands/utilities/context-prime.md +0 -1
- package/components/commands/utilities/debug-error.md +0 -121
- package/components/commands/utilities/directory-deep-dive.md +0 -34
- package/components/commands/utilities/explain-code.md +0 -194
- package/components/commands/utilities/fix-issue.md +0 -85
- package/components/commands/utilities/generate-linear-worklog.md +0 -113
- package/components/commands/utilities/git-status.md +0 -39
- package/components/commands/utilities/initref.md +0 -3
- package/components/commands/utilities/prime.md +0 -41
- package/components/commands/utilities/refactor-code.md +0 -116
- package/components/commands/utilities/ultra-think.md +0 -153
- package/components/hooks/HOOK_PATTERNS_COMPRESSED.json +0 -1
- package/components/hooks/automation/build-on-change.json +0 -16
- package/components/hooks/automation/dependency-checker.json +0 -16
- package/components/hooks/automation/deployment-health-monitor.json +0 -29
- package/components/hooks/automation/discord-detailed-notifications.json +0 -26
- package/components/hooks/automation/discord-error-notifications.json +0 -37
- package/components/hooks/automation/discord-notifications.json +0 -25
- package/components/hooks/automation/simple-notifications.json +0 -16
- package/components/hooks/automation/slack-detailed-notifications.json +0 -26
- package/components/hooks/automation/slack-error-notifications.json +0 -37
- package/components/hooks/automation/slack-notifications.json +0 -25
- package/components/hooks/automation/telegram-detailed-notifications.json +0 -26
- package/components/hooks/automation/telegram-error-notifications.json +0 -37
- package/components/hooks/automation/telegram-notifications.json +0 -25
- package/components/hooks/automation/vercel-auto-deploy.json +0 -17
- package/components/hooks/automation/vercel-environment-sync.json +0 -29
- package/components/hooks/development-tools/change-tracker.json +0 -25
- package/components/hooks/development-tools/command-logger.json +0 -16
- package/components/hooks/development-tools/file-backup.json +0 -16
- package/components/hooks/development-tools/lint-on-save.json +0 -16
- package/components/hooks/development-tools/nextjs-code-quality-enforcer.json +0 -17
- package/components/hooks/development-tools/smart-formatting.json +0 -16
- package/components/hooks/git-workflow/auto-git-add.json +0 -16
- package/components/hooks/git-workflow/smart-commit.json +0 -25
- package/components/hooks/performance/performance-budget-guard.json +0 -27
- package/components/hooks/performance/performance-monitor.json +0 -27
- package/components/hooks/post-tool/format-javascript-files.json +0 -16
- package/components/hooks/post-tool/format-python-files.json +0 -16
- package/components/hooks/post-tool/git-add-changes.json +0 -25
- package/components/hooks/post-tool/run-tests-after-changes.json +0 -16
- package/components/hooks/pre-tool/backup-before-edit.json +0 -16
- package/components/hooks/pre-tool/notify-before-bash.json +0 -16
- package/components/hooks/security/file-protection.json +0 -16
- package/components/hooks/security/security-scanner.json +0 -16
- package/components/hooks/testing/test-runner.json +0 -16
- package/components/mcps/browser_automation/browser-use-mcp-server.json +0 -20
- package/components/mcps/browser_automation/browsermcp.json +0 -9
- package/components/mcps/browser_automation/mcp-server-browserbase.json +0 -14
- package/components/mcps/browser_automation/mcp-server-playwright.json +0 -9
- package/components/mcps/browser_automation/playwright-mcp-server.json +0 -9
- package/components/mcps/browser_automation/playwright-mcp.json +0 -11
- package/components/mcps/database/mysql-integration.json +0 -12
- package/components/mcps/database/postgresql-integration.json +0 -12
- package/components/mcps/database/supabase.json +0 -17
- package/components/mcps/deepgraph/deepgraph-nextjs.json +0 -13
- package/components/mcps/deepgraph/deepgraph-react.json +0 -13
- package/components/mcps/deepgraph/deepgraph-typescript.json +0 -13
- package/components/mcps/deepgraph/deepgraph-vue.json +0 -13
- package/components/mcps/devtools/circleci.json +0 -13
- package/components/mcps/devtools/context7.json +0 -9
- package/components/mcps/devtools/firefly-mcp.json +0 -13
- package/components/mcps/devtools/ios-simulator-mcp.json +0 -9
- package/components/mcps/devtools/just-mcp.json +0 -9
- package/components/mcps/devtools/leetcode.json +0 -8
- package/components/mcps/devtools/mcp-server-atlassian-bitbucket.json +0 -9
- package/components/mcps/devtools/mcp-server-trello.json +0 -12
- package/components/mcps/filesystem/filesystem-access.json +0 -13
- package/components/mcps/integration/github-integration.json +0 -12
- package/components/mcps/integration/memory-integration.json +0 -9
- package/components/mcps/marketing/facebook-ads-mcp-server.json +0 -13
- package/components/mcps/marketing/google-ads-mcp-server.json +0 -11
- package/components/mcps/web/web-fetch.json +0 -9
- package/components/settings/api/bedrock-configuration.json +0 -7
- package/components/settings/api/corporate-proxy.json +0 -7
- package/components/settings/api/custom-headers.json +0 -6
- package/components/settings/api/vertex-configuration.json +0 -8
- package/components/settings/authentication/api-key-helper.json +0 -7
- package/components/settings/authentication/force-claudeai-login.json +0 -4
- package/components/settings/authentication/force-console-login.json +0 -4
- package/components/settings/cleanup/retention-7-days.json +0 -4
- package/components/settings/cleanup/retention-90-days.json +0 -4
- package/components/settings/environment/bash-timeouts.json +0 -8
- package/components/settings/environment/development-utils.json +0 -8
- package/components/settings/environment/performance-optimization.json +0 -8
- package/components/settings/environment/privacy-focused.json +0 -10
- package/components/settings/global/aws-credentials.json +0 -5
- package/components/settings/global/custom-model.json +0 -7
- package/components/settings/global/git-commit-settings.json +0 -4
- package/components/settings/mcp/disable-risky-servers.json +0 -8
- package/components/settings/mcp/enable-all-project-servers.json +0 -4
- package/components/settings/mcp/enable-specific-servers.json +0 -8
- package/components/settings/mcp/mcp-timeouts.json +0 -8
- package/components/settings/model/use-haiku.json +0 -4
- package/components/settings/model/use-sonnet.json +0 -4
- package/components/settings/permissions/additional-directories.json +0 -11
- package/components/settings/permissions/allow-git-operations.json +0 -14
- package/components/settings/permissions/allow-npm-commands.json +0 -11
- package/components/settings/permissions/deny-sensitive-files.json +0 -11
- package/components/settings/permissions/development-mode.json +0 -31
- package/components/settings/permissions/read-only-mode.json +0 -18
- package/components/settings/statusline/asset-pipeline-controller-statusline.json +0 -7
- package/components/settings/statusline/bug-circus-statusline.json +0 -7
- package/components/settings/statusline/code-casino-statusline.json +0 -7
- package/components/settings/statusline/code-spaceship-statusline.json +0 -7
- package/components/settings/statusline/colorful-statusline.json +0 -7
- package/components/settings/statusline/command-statusline.json +0 -8
- package/components/settings/statusline/context-monitor.json +0 -7
- package/components/settings/statusline/context-monitor.py +0 -236
- package/components/settings/statusline/data-ocean-statusline.json +0 -7
- package/components/settings/statusline/emotion-theater-statusline.json +0 -7
- package/components/settings/statusline/game-performance-monitor-statusline.json +0 -7
- package/components/settings/statusline/git-branch-statusline.json +0 -7
- package/components/settings/statusline/minimal-statusline.json +0 -7
- package/components/settings/statusline/multiplatform-build-status-statusline.json +0 -7
- package/components/settings/statusline/productivity-rainbow-statusline.json +0 -7
- package/components/settings/statusline/programmer-tamagotchi-statusline.json +0 -7
- package/components/settings/statusline/programming-fitness-tracker-statusline.json +0 -7
- package/components/settings/statusline/project-info-statusline.json +0 -7
- package/components/settings/statusline/rpg-status-bar-statusline.json +0 -7
- package/components/settings/statusline/time-statusline.json +0 -7
- package/components/settings/statusline/unity-project-dashboard-statusline.json +0 -7
- package/components/settings/statusline/vercel-deployment-monitor.json +0 -7
- package/components/settings/statusline/vercel-error-alert-system.json +0 -7
- package/components/settings/statusline/vercel-multi-env-status.json +0 -7
- package/components/settings/statusline/virtual-code-garden-statusline.json +0 -7
- package/components/settings/statusline/zero-config-deployment-monitor.json +0 -7
- package/components/settings/telemetry/custom-telemetry.json +0 -7
- package/components/settings/telemetry/disable-telemetry.json +0 -6
- package/components/settings/telemetry/enable-telemetry.json +0 -6
|
@@ -1,712 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
allowed-tools: Read, Write, Edit
|
|
3
|
-
argument-hint: [middleware-type] [--auth] [--rate-limit] [--redirect] [--rewrite]
|
|
4
|
-
description: Create optimized Next.js middleware with authentication, rate limiting, and routing logic
|
|
5
|
-
model: sonnet
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## Next.js Middleware Creator
|
|
9
|
-
|
|
10
|
-
**Middleware Type**: $ARGUMENTS
|
|
11
|
-
|
|
12
|
-
## Current Project Analysis
|
|
13
|
-
|
|
14
|
-
### Project Structure
|
|
15
|
-
- Next.js config: @next.config.js
|
|
16
|
-
- Existing middleware: @middleware.ts or @middleware.js (if exists)
|
|
17
|
-
- App directory: @app/ (if App Router)
|
|
18
|
-
- Auth configuration: @auth.config.ts or @lib/auth/ (if exists)
|
|
19
|
-
|
|
20
|
-
### Framework Detection
|
|
21
|
-
- Package.json: @package.json
|
|
22
|
-
- TypeScript config: @tsconfig.json (if exists)
|
|
23
|
-
- Authentication libraries: Detect NextAuth.js, Auth0, or custom auth
|
|
24
|
-
|
|
25
|
-
## Middleware Implementation Strategy
|
|
26
|
-
|
|
27
|
-
### 1. Middleware File Structure
|
|
28
|
-
Create comprehensive middleware at project root:
|
|
29
|
-
```
|
|
30
|
-
middleware.ts # Main middleware file
|
|
31
|
-
lib/middleware/ # Middleware utilities
|
|
32
|
-
├── auth.ts # Authentication middleware
|
|
33
|
-
├── rateLimit.ts # Rate limiting logic
|
|
34
|
-
├── redirects.ts # Redirect rules
|
|
35
|
-
├── rewrites.ts # URL rewriting
|
|
36
|
-
├── cors.ts # CORS handling
|
|
37
|
-
├── security.ts # Security headers
|
|
38
|
-
└── types.ts # TypeScript types
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### 2. Base Middleware Template
|
|
42
|
-
```typescript
|
|
43
|
-
// middleware.ts
|
|
44
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
45
|
-
import { authMiddleware } from './lib/middleware/auth';
|
|
46
|
-
import { rateLimitMiddleware } from './lib/middleware/rateLimit';
|
|
47
|
-
import { securityMiddleware } from './lib/middleware/security';
|
|
48
|
-
import { redirectMiddleware } from './lib/middleware/redirects';
|
|
49
|
-
|
|
50
|
-
export async function middleware(request: NextRequest) {
|
|
51
|
-
const { pathname } = request.nextUrl;
|
|
52
|
-
|
|
53
|
-
// Apply security headers first
|
|
54
|
-
let response = await securityMiddleware(request);
|
|
55
|
-
|
|
56
|
-
// Apply rate limiting
|
|
57
|
-
const rateLimitResult = await rateLimitMiddleware(request);
|
|
58
|
-
if (rateLimitResult) return rateLimitResult;
|
|
59
|
-
|
|
60
|
-
// Handle authentication for protected routes
|
|
61
|
-
if (isProtectedRoute(pathname)) {
|
|
62
|
-
const authResult = await authMiddleware(request);
|
|
63
|
-
if (authResult) return authResult;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Handle redirects
|
|
67
|
-
const redirectResult = await redirectMiddleware(request);
|
|
68
|
-
if (redirectResult) return redirectResult;
|
|
69
|
-
|
|
70
|
-
// Apply additional headers to response
|
|
71
|
-
if (response) {
|
|
72
|
-
return response;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return NextResponse.next();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function isProtectedRoute(pathname: string): boolean {
|
|
79
|
-
const protectedPaths = ['/dashboard', '/admin', '/api/protected'];
|
|
80
|
-
return protectedPaths.some(path => pathname.startsWith(path));
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export const config = {
|
|
84
|
-
matcher: [
|
|
85
|
-
// Match all request paths except static files and images
|
|
86
|
-
'/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)',
|
|
87
|
-
],
|
|
88
|
-
};
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
## Middleware Components
|
|
92
|
-
|
|
93
|
-
### 1. Authentication Middleware
|
|
94
|
-
```typescript
|
|
95
|
-
// lib/middleware/auth.ts
|
|
96
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
97
|
-
import { jwtVerify } from 'jose';
|
|
98
|
-
|
|
99
|
-
const JWT_SECRET = new TextEncoder().encode(
|
|
100
|
-
process.env.JWT_SECRET || 'your-secret-key'
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
export async function authMiddleware(request: NextRequest) {
|
|
104
|
-
try {
|
|
105
|
-
// Get token from cookies or Authorization header
|
|
106
|
-
const token = request.cookies.get('auth-token')?.value ||
|
|
107
|
-
request.headers.get('authorization')?.replace('Bearer ', '');
|
|
108
|
-
|
|
109
|
-
if (!token) {
|
|
110
|
-
return redirectToLogin(request);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Verify JWT token
|
|
114
|
-
const { payload } = await jwtVerify(token, JWT_SECRET);
|
|
115
|
-
|
|
116
|
-
// Add user info to headers for downstream use
|
|
117
|
-
const response = NextResponse.next();
|
|
118
|
-
response.headers.set('x-user-id', payload.sub as string);
|
|
119
|
-
response.headers.set('x-user-role', payload.role as string);
|
|
120
|
-
|
|
121
|
-
return response;
|
|
122
|
-
|
|
123
|
-
} catch (error) {
|
|
124
|
-
console.error('Auth middleware error:', error);
|
|
125
|
-
return redirectToLogin(request);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function redirectToLogin(request: NextRequest) {
|
|
130
|
-
const loginUrl = new URL('/login', request.url);
|
|
131
|
-
loginUrl.searchParams.set('callbackUrl', request.url);
|
|
132
|
-
return NextResponse.redirect(loginUrl);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Role-based access control
|
|
136
|
-
export function requireRole(allowedRoles: string[]) {
|
|
137
|
-
return async function roleMiddleware(request: NextRequest) {
|
|
138
|
-
const userRole = request.headers.get('x-user-role');
|
|
139
|
-
|
|
140
|
-
if (!userRole || !allowedRoles.includes(userRole)) {
|
|
141
|
-
return new NextResponse('Forbidden', { status: 403 });
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return NextResponse.next();
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
### 2. Rate Limiting Middleware
|
|
150
|
-
```typescript
|
|
151
|
-
// lib/middleware/rateLimit.ts
|
|
152
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
153
|
-
|
|
154
|
-
// Simple in-memory store (use Redis in production)
|
|
155
|
-
const requestCounts = new Map<string, { count: number; resetTime: number }>();
|
|
156
|
-
|
|
157
|
-
interface RateLimitConfig {
|
|
158
|
-
windowMs: number; // Time window in milliseconds
|
|
159
|
-
maxRequests: number; // Max requests per window
|
|
160
|
-
keyGenerator?: (request: NextRequest) => string;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const defaultConfig: RateLimitConfig = {
|
|
164
|
-
windowMs: 15 * 60 * 1000, // 15 minutes
|
|
165
|
-
maxRequests: 100, // 100 requests per 15 minutes
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
export async function rateLimitMiddleware(
|
|
169
|
-
request: NextRequest,
|
|
170
|
-
config: RateLimitConfig = defaultConfig
|
|
171
|
-
) {
|
|
172
|
-
const key = config.keyGenerator
|
|
173
|
-
? config.keyGenerator(request)
|
|
174
|
-
: getClientIP(request);
|
|
175
|
-
|
|
176
|
-
const now = Date.now();
|
|
177
|
-
const clientData = requestCounts.get(key);
|
|
178
|
-
|
|
179
|
-
// Reset window if expired
|
|
180
|
-
if (!clientData || now > clientData.resetTime) {
|
|
181
|
-
requestCounts.set(key, {
|
|
182
|
-
count: 1,
|
|
183
|
-
resetTime: now + config.windowMs
|
|
184
|
-
});
|
|
185
|
-
return null; // Allow request
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// Increment counter
|
|
189
|
-
clientData.count++;
|
|
190
|
-
|
|
191
|
-
// Check if limit exceeded
|
|
192
|
-
if (clientData.count > config.maxRequests) {
|
|
193
|
-
const resetTime = Math.ceil((clientData.resetTime - now) / 1000);
|
|
194
|
-
|
|
195
|
-
return new NextResponse('Rate limit exceeded', {
|
|
196
|
-
status: 429,
|
|
197
|
-
headers: {
|
|
198
|
-
'X-RateLimit-Limit': config.maxRequests.toString(),
|
|
199
|
-
'X-RateLimit-Remaining': '0',
|
|
200
|
-
'X-RateLimit-Reset': resetTime.toString(),
|
|
201
|
-
'Retry-After': resetTime.toString(),
|
|
202
|
-
},
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
return null; // Allow request
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
function getClientIP(request: NextRequest): string {
|
|
210
|
-
return request.headers.get('x-forwarded-for') ||
|
|
211
|
-
request.headers.get('x-real-ip') ||
|
|
212
|
-
request.ip ||
|
|
213
|
-
'unknown';
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// API-specific rate limiting
|
|
217
|
-
export const apiRateLimit = (request: NextRequest) =>
|
|
218
|
-
rateLimitMiddleware(request, {
|
|
219
|
-
windowMs: 60 * 1000, // 1 minute
|
|
220
|
-
maxRequests: 60, // 60 requests per minute
|
|
221
|
-
keyGenerator: (req) => `api:${getClientIP(req)}`,
|
|
222
|
-
});
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
### 3. Security Headers Middleware
|
|
226
|
-
```typescript
|
|
227
|
-
// lib/middleware/security.ts
|
|
228
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
229
|
-
|
|
230
|
-
export async function securityMiddleware(request: NextRequest) {
|
|
231
|
-
const response = NextResponse.next();
|
|
232
|
-
|
|
233
|
-
// Security headers
|
|
234
|
-
const securityHeaders = {
|
|
235
|
-
// XSS Protection
|
|
236
|
-
'X-XSS-Protection': '1; mode=block',
|
|
237
|
-
|
|
238
|
-
// Content Type Options
|
|
239
|
-
'X-Content-Type-Options': 'nosniff',
|
|
240
|
-
|
|
241
|
-
// Frame Options
|
|
242
|
-
'X-Frame-Options': 'DENY',
|
|
243
|
-
|
|
244
|
-
// HSTS
|
|
245
|
-
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
|
|
246
|
-
|
|
247
|
-
// Referrer Policy
|
|
248
|
-
'Referrer-Policy': 'strict-origin-when-cross-origin',
|
|
249
|
-
|
|
250
|
-
// Permissions Policy
|
|
251
|
-
'Permissions-Policy': 'camera=(), microphone=(), geolocation=()',
|
|
252
|
-
|
|
253
|
-
// Content Security Policy
|
|
254
|
-
'Content-Security-Policy': generateCSP(),
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
// Apply security headers
|
|
258
|
-
Object.entries(securityHeaders).forEach(([key, value]) => {
|
|
259
|
-
response.headers.set(key, value);
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
return response;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
function generateCSP(): string {
|
|
266
|
-
const csp = [
|
|
267
|
-
"default-src 'self'",
|
|
268
|
-
"script-src 'self' 'unsafe-eval' 'unsafe-inline'",
|
|
269
|
-
"style-src 'self' 'unsafe-inline'",
|
|
270
|
-
"img-src 'self' data: https:",
|
|
271
|
-
"font-src 'self' data:",
|
|
272
|
-
"connect-src 'self'",
|
|
273
|
-
"frame-ancestors 'none'",
|
|
274
|
-
];
|
|
275
|
-
|
|
276
|
-
return csp.join('; ');
|
|
277
|
-
}
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
### 4. CORS Middleware
|
|
281
|
-
```typescript
|
|
282
|
-
// lib/middleware/cors.ts
|
|
283
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
284
|
-
|
|
285
|
-
interface CorsOptions {
|
|
286
|
-
origin: string | string[] | boolean;
|
|
287
|
-
methods: string[];
|
|
288
|
-
allowedHeaders: string[];
|
|
289
|
-
credentials: boolean;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
const defaultCorsOptions: CorsOptions = {
|
|
293
|
-
origin: true, // Allow all origins in development
|
|
294
|
-
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
|
295
|
-
allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With'],
|
|
296
|
-
credentials: true,
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
export function corsMiddleware(options: Partial<CorsOptions> = {}) {
|
|
300
|
-
const config = { ...defaultCorsOptions, ...options };
|
|
301
|
-
|
|
302
|
-
return function cors(request: NextRequest) {
|
|
303
|
-
const response = NextResponse.next();
|
|
304
|
-
const origin = request.headers.get('origin');
|
|
305
|
-
|
|
306
|
-
// Handle preflight requests
|
|
307
|
-
if (request.method === 'OPTIONS') {
|
|
308
|
-
return handlePreflight(request, config);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// Set CORS headers
|
|
312
|
-
if (shouldAllowOrigin(origin, config.origin)) {
|
|
313
|
-
response.headers.set('Access-Control-Allow-Origin', origin || '*');
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
if (config.credentials) {
|
|
317
|
-
response.headers.set('Access-Control-Allow-Credentials', 'true');
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
response.headers.set(
|
|
321
|
-
'Access-Control-Allow-Methods',
|
|
322
|
-
config.methods.join(', ')
|
|
323
|
-
);
|
|
324
|
-
|
|
325
|
-
response.headers.set(
|
|
326
|
-
'Access-Control-Allow-Headers',
|
|
327
|
-
config.allowedHeaders.join(', ')
|
|
328
|
-
);
|
|
329
|
-
|
|
330
|
-
return response;
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
function handlePreflight(request: NextRequest, config: CorsOptions) {
|
|
335
|
-
const headers = new Headers();
|
|
336
|
-
const origin = request.headers.get('origin');
|
|
337
|
-
|
|
338
|
-
if (shouldAllowOrigin(origin, config.origin)) {
|
|
339
|
-
headers.set('Access-Control-Allow-Origin', origin || '*');
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
if (config.credentials) {
|
|
343
|
-
headers.set('Access-Control-Allow-Credentials', 'true');
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
headers.set('Access-Control-Allow-Methods', config.methods.join(', '));
|
|
347
|
-
headers.set('Access-Control-Allow-Headers', config.allowedHeaders.join(', '));
|
|
348
|
-
headers.set('Access-Control-Max-Age', '86400'); // 24 hours
|
|
349
|
-
|
|
350
|
-
return new NextResponse(null, { status: 200, headers });
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
function shouldAllowOrigin(
|
|
354
|
-
origin: string | null,
|
|
355
|
-
allowedOrigin: string | string[] | boolean
|
|
356
|
-
): boolean {
|
|
357
|
-
if (allowedOrigin === true) return true;
|
|
358
|
-
if (allowedOrigin === false) return false;
|
|
359
|
-
if (typeof allowedOrigin === 'string') return origin === allowedOrigin;
|
|
360
|
-
if (Array.isArray(allowedOrigin)) return allowedOrigin.includes(origin || '');
|
|
361
|
-
return false;
|
|
362
|
-
}
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
### 5. Redirect and Rewrite Middleware
|
|
366
|
-
```typescript
|
|
367
|
-
// lib/middleware/redirects.ts
|
|
368
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
369
|
-
|
|
370
|
-
interface RedirectRule {
|
|
371
|
-
source: string | RegExp;
|
|
372
|
-
destination: string;
|
|
373
|
-
permanent?: boolean;
|
|
374
|
-
conditions?: (request: NextRequest) => boolean;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
const redirectRules: RedirectRule[] = [
|
|
378
|
-
// Legacy URL redirects
|
|
379
|
-
{
|
|
380
|
-
source: '/old-page',
|
|
381
|
-
destination: '/new-page',
|
|
382
|
-
permanent: true,
|
|
383
|
-
},
|
|
384
|
-
|
|
385
|
-
// Dynamic redirects
|
|
386
|
-
{
|
|
387
|
-
source: /^\/user\/(.+)$/,
|
|
388
|
-
destination: '/profile/$1',
|
|
389
|
-
permanent: false,
|
|
390
|
-
},
|
|
391
|
-
|
|
392
|
-
// Conditional redirects
|
|
393
|
-
{
|
|
394
|
-
source: '/admin',
|
|
395
|
-
destination: '/admin/dashboard',
|
|
396
|
-
conditions: (request) => {
|
|
397
|
-
const userRole = request.headers.get('x-user-role');
|
|
398
|
-
return userRole === 'admin';
|
|
399
|
-
},
|
|
400
|
-
},
|
|
401
|
-
|
|
402
|
-
// Maintenance mode
|
|
403
|
-
{
|
|
404
|
-
source: /.*/,
|
|
405
|
-
destination: '/maintenance',
|
|
406
|
-
conditions: (request) => {
|
|
407
|
-
return process.env.MAINTENANCE_MODE === 'true' &&
|
|
408
|
-
!request.nextUrl.pathname.startsWith('/maintenance');
|
|
409
|
-
},
|
|
410
|
-
},
|
|
411
|
-
];
|
|
412
|
-
|
|
413
|
-
export async function redirectMiddleware(request: NextRequest) {
|
|
414
|
-
const { pathname } = request.nextUrl;
|
|
415
|
-
|
|
416
|
-
for (const rule of redirectRules) {
|
|
417
|
-
if (shouldApplyRule(rule, pathname, request)) {
|
|
418
|
-
const destination = resolveDestination(rule.destination, pathname);
|
|
419
|
-
const url = new URL(destination, request.url);
|
|
420
|
-
|
|
421
|
-
return NextResponse.redirect(url, {
|
|
422
|
-
status: rule.permanent ? 301 : 302,
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
return null; // No redirect needed
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
function shouldApplyRule(
|
|
431
|
-
rule: RedirectRule,
|
|
432
|
-
pathname: string,
|
|
433
|
-
request: NextRequest
|
|
434
|
-
): boolean {
|
|
435
|
-
// Check pattern match
|
|
436
|
-
const matches = typeof rule.source === 'string'
|
|
437
|
-
? pathname === rule.source
|
|
438
|
-
: rule.source.test(pathname);
|
|
439
|
-
|
|
440
|
-
if (!matches) return false;
|
|
441
|
-
|
|
442
|
-
// Check additional conditions
|
|
443
|
-
if (rule.conditions) {
|
|
444
|
-
return rule.conditions(request);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
return true;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
function resolveDestination(destination: string, pathname: string): string {
|
|
451
|
-
// Handle dynamic replacements
|
|
452
|
-
return destination.replace(/\$(\d+)/g, (match, num) => {
|
|
453
|
-
// Extract from regex matches
|
|
454
|
-
return pathname; // Simplified - would need actual regex matching
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
```
|
|
458
|
-
|
|
459
|
-
### 6. A/B Testing Middleware
|
|
460
|
-
```typescript
|
|
461
|
-
// lib/middleware/abTest.ts
|
|
462
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
463
|
-
|
|
464
|
-
interface ABTest {
|
|
465
|
-
name: string;
|
|
466
|
-
variants: string[];
|
|
467
|
-
traffic: number; // Percentage of traffic to include (0-100)
|
|
468
|
-
condition?: (request: NextRequest) => boolean;
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
const activeTests: ABTest[] = [
|
|
472
|
-
{
|
|
473
|
-
name: 'homepage-design',
|
|
474
|
-
variants: ['control', 'variant-a', 'variant-b'],
|
|
475
|
-
traffic: 50,
|
|
476
|
-
},
|
|
477
|
-
{
|
|
478
|
-
name: 'checkout-flow',
|
|
479
|
-
variants: ['old-checkout', 'new-checkout'],
|
|
480
|
-
traffic: 100,
|
|
481
|
-
condition: (req) => req.nextUrl.pathname.startsWith('/checkout'),
|
|
482
|
-
},
|
|
483
|
-
];
|
|
484
|
-
|
|
485
|
-
export function abTestMiddleware(request: NextRequest) {
|
|
486
|
-
const response = NextResponse.next();
|
|
487
|
-
|
|
488
|
-
for (const test of activeTests) {
|
|
489
|
-
// Check if user should be included in test
|
|
490
|
-
if (test.condition && !test.condition(request)) continue;
|
|
491
|
-
|
|
492
|
-
// Check traffic allocation
|
|
493
|
-
const userId = getUserId(request);
|
|
494
|
-
const hash = hashString(userId + test.name);
|
|
495
|
-
const bucket = hash % 100;
|
|
496
|
-
|
|
497
|
-
if (bucket >= test.traffic) continue;
|
|
498
|
-
|
|
499
|
-
// Assign variant
|
|
500
|
-
const variantIndex = hash % test.variants.length;
|
|
501
|
-
const variant = test.variants[variantIndex];
|
|
502
|
-
|
|
503
|
-
// Set cookie for consistent experience
|
|
504
|
-
response.cookies.set(`ab_${test.name}`, variant, {
|
|
505
|
-
maxAge: 30 * 24 * 60 * 60, // 30 days
|
|
506
|
-
httpOnly: false, // Allow client-side access
|
|
507
|
-
});
|
|
508
|
-
|
|
509
|
-
// Set header for server-side use
|
|
510
|
-
response.headers.set(`x-ab-${test.name}`, variant);
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
return response;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
function getUserId(request: NextRequest): string {
|
|
517
|
-
// Get user ID from cookie, or generate anonymous ID
|
|
518
|
-
return request.cookies.get('user-id')?.value ||
|
|
519
|
-
request.headers.get('x-forwarded-for') ||
|
|
520
|
-
'anonymous';
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
function hashString(str: string): number {
|
|
524
|
-
let hash = 0;
|
|
525
|
-
for (let i = 0; i < str.length; i++) {
|
|
526
|
-
const char = str.charCodeAt(i);
|
|
527
|
-
hash = ((hash << 5) - hash) + char;
|
|
528
|
-
hash = hash & hash; // Convert to 32-bit integer
|
|
529
|
-
}
|
|
530
|
-
return Math.abs(hash);
|
|
531
|
-
}
|
|
532
|
-
```
|
|
533
|
-
|
|
534
|
-
## Advanced Middleware Patterns
|
|
535
|
-
|
|
536
|
-
### 1. Middleware Composition
|
|
537
|
-
```typescript
|
|
538
|
-
// lib/middleware/compose.ts
|
|
539
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
540
|
-
|
|
541
|
-
type MiddlewareFunction = (
|
|
542
|
-
request: NextRequest,
|
|
543
|
-
response?: NextResponse
|
|
544
|
-
) => NextResponse | Promise<NextResponse> | null;
|
|
545
|
-
|
|
546
|
-
export function composeMiddleware(...middlewares: MiddlewareFunction[]) {
|
|
547
|
-
return async function composedMiddleware(request: NextRequest) {
|
|
548
|
-
let response: NextResponse | null = null;
|
|
549
|
-
|
|
550
|
-
for (const middleware of middlewares) {
|
|
551
|
-
const result = await middleware(request, response || undefined);
|
|
552
|
-
|
|
553
|
-
if (result && result.status >= 300 && result.status < 400) {
|
|
554
|
-
// Handle redirects immediately
|
|
555
|
-
return result;
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
if (result && result.status >= 400) {
|
|
559
|
-
// Handle errors immediately
|
|
560
|
-
return result;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
if (result) {
|
|
564
|
-
response = result;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
return response || NextResponse.next();
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
|
-
```
|
|
572
|
-
|
|
573
|
-
### 2. Feature Flag Middleware
|
|
574
|
-
```typescript
|
|
575
|
-
// lib/middleware/featureFlags.ts
|
|
576
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
577
|
-
|
|
578
|
-
interface FeatureFlag {
|
|
579
|
-
name: string;
|
|
580
|
-
enabled: boolean;
|
|
581
|
-
percentage?: number;
|
|
582
|
-
userGroups?: string[];
|
|
583
|
-
geoRegions?: string[];
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
const featureFlags: FeatureFlag[] = [
|
|
587
|
-
{
|
|
588
|
-
name: 'new-dashboard',
|
|
589
|
-
enabled: true,
|
|
590
|
-
percentage: 25,
|
|
591
|
-
},
|
|
592
|
-
{
|
|
593
|
-
name: 'premium-features',
|
|
594
|
-
enabled: true,
|
|
595
|
-
userGroups: ['premium', 'admin'],
|
|
596
|
-
},
|
|
597
|
-
];
|
|
598
|
-
|
|
599
|
-
export function featureFlagMiddleware(request: NextRequest) {
|
|
600
|
-
const response = NextResponse.next();
|
|
601
|
-
const activeFlags: Record<string, boolean> = {};
|
|
602
|
-
|
|
603
|
-
for (const flag of featureFlags) {
|
|
604
|
-
if (!flag.enabled) {
|
|
605
|
-
activeFlags[flag.name] = false;
|
|
606
|
-
continue;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
// Check percentage rollout
|
|
610
|
-
if (flag.percentage) {
|
|
611
|
-
const userId = getUserId(request);
|
|
612
|
-
const hash = hashString(userId + flag.name) % 100;
|
|
613
|
-
if (hash >= flag.percentage) {
|
|
614
|
-
activeFlags[flag.name] = false;
|
|
615
|
-
continue;
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
// Check user groups
|
|
620
|
-
if (flag.userGroups) {
|
|
621
|
-
const userRole = request.headers.get('x-user-role');
|
|
622
|
-
if (!userRole || !flag.userGroups.includes(userRole)) {
|
|
623
|
-
activeFlags[flag.name] = false;
|
|
624
|
-
continue;
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
activeFlags[flag.name] = true;
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
// Set feature flags in headers
|
|
632
|
-
response.headers.set('x-feature-flags', JSON.stringify(activeFlags));
|
|
633
|
-
|
|
634
|
-
return response;
|
|
635
|
-
}
|
|
636
|
-
```
|
|
637
|
-
|
|
638
|
-
## Middleware Testing
|
|
639
|
-
|
|
640
|
-
### 1. Unit Tests
|
|
641
|
-
```typescript
|
|
642
|
-
// __tests__/middleware.test.ts
|
|
643
|
-
import { NextRequest } from 'next/server';
|
|
644
|
-
import { middleware } from '../middleware';
|
|
645
|
-
|
|
646
|
-
describe('Middleware', () => {
|
|
647
|
-
it('should add security headers', async () => {
|
|
648
|
-
const request = new NextRequest('http://localhost:3000/');
|
|
649
|
-
const response = await middleware(request);
|
|
650
|
-
|
|
651
|
-
expect(response.headers.get('X-Frame-Options')).toBe('DENY');
|
|
652
|
-
expect(response.headers.get('X-Content-Type-Options')).toBe('nosniff');
|
|
653
|
-
});
|
|
654
|
-
|
|
655
|
-
it('should redirect unauthenticated users from protected routes', async () => {
|
|
656
|
-
const request = new NextRequest('http://localhost:3000/dashboard');
|
|
657
|
-
const response = await middleware(request);
|
|
658
|
-
|
|
659
|
-
expect(response.status).toBe(302);
|
|
660
|
-
expect(response.headers.get('location')).toContain('/login');
|
|
661
|
-
});
|
|
662
|
-
});
|
|
663
|
-
```
|
|
664
|
-
|
|
665
|
-
### 2. Integration Tests
|
|
666
|
-
```typescript
|
|
667
|
-
// __tests__/middleware.integration.test.ts
|
|
668
|
-
describe('Middleware Integration', () => {
|
|
669
|
-
it('should handle complete authentication flow', async () => {
|
|
670
|
-
// Test login -> dashboard -> logout flow
|
|
671
|
-
});
|
|
672
|
-
|
|
673
|
-
it('should respect rate limiting', async () => {
|
|
674
|
-
// Test multiple requests hitting rate limit
|
|
675
|
-
});
|
|
676
|
-
});
|
|
677
|
-
```
|
|
678
|
-
|
|
679
|
-
## Deployment and Monitoring
|
|
680
|
-
|
|
681
|
-
### 1. Performance Monitoring
|
|
682
|
-
```typescript
|
|
683
|
-
// lib/middleware/monitoring.ts
|
|
684
|
-
export function monitoringMiddleware(request: NextRequest) {
|
|
685
|
-
const start = Date.now();
|
|
686
|
-
|
|
687
|
-
return new Response(JSON.stringify({}), {
|
|
688
|
-
status: 200,
|
|
689
|
-
headers: {
|
|
690
|
-
'x-response-time': `${Date.now() - start}ms`,
|
|
691
|
-
},
|
|
692
|
-
});
|
|
693
|
-
}
|
|
694
|
-
```
|
|
695
|
-
|
|
696
|
-
### 2. Error Handling
|
|
697
|
-
```typescript
|
|
698
|
-
// lib/middleware/errorHandler.ts
|
|
699
|
-
export function errorHandlerMiddleware(
|
|
700
|
-
error: Error,
|
|
701
|
-
request: NextRequest
|
|
702
|
-
): NextResponse {
|
|
703
|
-
console.error('Middleware error:', error);
|
|
704
|
-
|
|
705
|
-
// Log to monitoring service
|
|
706
|
-
// logError(error, request);
|
|
707
|
-
|
|
708
|
-
return new NextResponse('Internal Server Error', { status: 500 });
|
|
709
|
-
}
|
|
710
|
-
```
|
|
711
|
-
|
|
712
|
-
Generate comprehensive middleware implementation with all requested features, proper TypeScript types, and production-ready patterns.
|