claude-flow-novice 1.6.1 → 1.6.3
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/.claude/agents/cfn-loop/product-owner.md +54 -4
- package/.claude/commands/cfn-claude-sync.md +303 -0
- package/.claude/commands/cfn-loop-epic.md +290 -0
- package/.claude/commands/cfn-loop-single.md +168 -0
- package/.claude/commands/cfn-loop-sprints.md +384 -0
- package/.claude/commands/cfn-loop.md +180 -0
- package/.claude/commands/metrics-summary.md +58 -0
- package/.claude/commands/parse-epic.md +357 -0
- package/.claude/settings.json +5 -4
- package/.claude/settings.local.json +9 -2
- package/.claude-flow-novice/.claude/agents/cfn-loop/product-owner.md +792 -0
- package/.claude-flow-novice/dist/mcp/server.js +21 -2
- package/.claude-flow-novice/dist/src/api/auth-service.js +84 -38
- package/.claude-flow-novice/dist/src/api/auth-service.js.map +1 -1
- package/.claude-flow-novice/dist/src/api/claude-client.js +138 -3
- package/.claude-flow-novice/dist/src/api/claude-client.js.map +1 -1
- package/.claude-flow-novice/dist/src/cfn-loop/phase-orchestrator-example.js +1 -1
- package/.claude-flow-novice/dist/src/cfn-loop/scope-control.js +247 -0
- package/.claude-flow-novice/dist/src/cfn-loop/scope-control.js.map +1 -0
- package/.claude-flow-novice/dist/src/cli/commands/swarm.js +32 -15
- package/.claude-flow-novice/dist/src/cli/commands/swarm.js.map +1 -1
- package/.claude-flow-novice/dist/src/cli/commands/transparency.js +455 -0
- package/.claude-flow-novice/dist/src/cli/commands/transparency.js.map +1 -0
- package/.claude-flow-novice/dist/src/cli/simple-commands/init/templates/CLAUDE.md +129 -13
- package/.claude-flow-novice/dist/src/components/visualizations/index.js +9 -0
- package/.claude-flow-novice/dist/src/components/visualizations/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/adapters/v1-coordinator-adapter.js +462 -0
- package/.claude-flow-novice/dist/src/coordination/adapters/v1-coordinator-adapter.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/config-translator.js +248 -0
- package/.claude-flow-novice/dist/src/coordination/config-translator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/coordination-toggle.js +287 -0
- package/.claude-flow-novice/dist/src/coordination/coordination-toggle.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/distributed-consensus.js +68 -9
- package/.claude-flow-novice/dist/src/coordination/distributed-consensus.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/feature-flags.js +166 -0
- package/.claude-flow-novice/dist/src/coordination/feature-flags.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/queen-agent.js +18 -4
- package/.claude-flow-novice/dist/src/coordination/queen-agent.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/role-assignment.js +6 -110
- package/.claude-flow-novice/dist/src/coordination/role-assignment.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/cache/artifact-cache-optimizer.js +632 -0
- package/.claude-flow-novice/dist/src/coordination/v2/cache/artifact-cache-optimizer.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/cache/index.js +11 -0
- package/.claude-flow-novice/dist/src/coordination/v2/cache/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/checkpoints/checkpoint-compressor.js +318 -0
- package/.claude-flow-novice/dist/src/coordination/v2/checkpoints/checkpoint-compressor.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.example.js +364 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.example.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.js +492 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/hierarchical-coordinator.js +786 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/hierarchical-coordinator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/index.js +16 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/parent-child-manager.js +342 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/parent-child-manager.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/swarm-coordinator-v2.js +601 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/swarm-coordinator-v2.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/help-request-metrics.js +211 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/help-request-metrics.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/index.js +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/index.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/core/message-broker.js +365 -6
- package/.claude-flow-novice/dist/src/coordination/v2/core/message-broker.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/core/resource-manager-safe.js +478 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/resource-manager-safe.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine-config.js +5 -2
- package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine-config.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine.js +189 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/deadlock/deadlock-detector.js +424 -0
- package/.claude-flow-novice/dist/src/coordination/v2/deadlock/deadlock-detector.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/deadlock/index.js +9 -0
- package/.claude-flow-novice/dist/src/coordination/v2/deadlock/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/deadlock/resource-manager.js +669 -0
- package/.claude-flow-novice/dist/src/coordination/v2/deadlock/resource-manager.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/artifact-storage.js +451 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/artifact-storage.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/cycle-detector.js +271 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/cycle-detector.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-graph.js +335 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-graph.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-manager.js +439 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-manager.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-request.js +92 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-request.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/index.js +21 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/topological-sort.js +223 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/topological-sort.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-coordinator.js +436 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-coordinator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-matcher.js +278 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-matcher.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request-handler.js +317 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request-handler.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request.js +273 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/index.js +15 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/waiting-agent-pool.js +512 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/waiting-agent-pool.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/index.js +6 -0
- package/.claude-flow-novice/dist/src/coordination/v2/index.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/integration/help-deadlock-integration.js +557 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/help-deadlock-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/index.js +14 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.example.js +212 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.example.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.js +552 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/memory/dependency-storage.js +367 -0
- package/.claude-flow-novice/dist/src/coordination/v2/memory/dependency-storage.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/memory/index.js +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/memory/index.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channel.js +371 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channel.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/dependency-channel.js +355 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/dependency-channel.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/help-channel.js +424 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/help-channel.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/index.js +16 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/state-channel.js +295 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/state-channel.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/task-channel.js +411 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/task-channel.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/index.js +14 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-bus.js +387 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-bus.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-persistence.js +589 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-persistence.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-router.js +444 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-router.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/checkpoint-manager.js +29 -8
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/checkpoint-manager.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/help-coordinator.js +470 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/help-coordinator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/hierarchical-background-integration.js +450 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/hierarchical-background-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/index.js +5 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/index.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/multi-level-control.js +545 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/multi-level-control.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-controller.js +44 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-controller.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-message-integration.js +415 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-message-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/session-pool-optimizer.js +615 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/session-pool-optimizer.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/security/payload-validator.js +259 -0
- package/.claude-flow-novice/dist/src/coordination/v2/security/payload-validator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/transparency/index.js +17 -0
- package/.claude-flow-novice/dist/src/coordination/v2/transparency/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-integration.js +357 -0
- package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-system.js +679 -0
- package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-system.js.map +1 -0
- package/.claude-flow-novice/dist/src/core/agent-manager.js +30 -0
- package/.claude-flow-novice/dist/src/core/agent-manager.js.map +1 -1
- package/.claude-flow-novice/dist/src/mcp/server.js +21 -2
- package/.claude-flow-novice/dist/src/mcp/server.js.map +1 -1
- package/.claude-flow-novice/dist/src/monitoring/apm/apm-integration.js +719 -0
- package/.claude-flow-novice/dist/src/monitoring/apm/apm-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/monitoring/apm/datadog-collector.js +363 -0
- package/.claude-flow-novice/dist/src/monitoring/apm/datadog-collector.js.map +1 -0
- package/.claude-flow-novice/dist/src/monitoring/apm/index.js +97 -0
- package/.claude-flow-novice/dist/src/monitoring/apm/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/monitoring/apm/newrelic-collector.js +384 -0
- package/.claude-flow-novice/dist/src/monitoring/apm/newrelic-collector.js.map +1 -0
- package/.claude-flow-novice/dist/src/monitoring/apm/performance-optimizer.js +612 -0
- package/.claude-flow-novice/dist/src/monitoring/apm/performance-optimizer.js.map +1 -0
- package/.claude-flow-novice/dist/src/monitoring/metrics-collector.js +282 -0
- package/.claude-flow-novice/dist/src/monitoring/metrics-collector.js.map +1 -0
- package/.claude-flow-novice/dist/src/observability/metrics-counter.js +268 -0
- package/.claude-flow-novice/dist/src/observability/metrics-counter.js.map +1 -0
- package/.claude-flow-novice/dist/src/observability/metrics-storage.js +265 -0
- package/.claude-flow-novice/dist/src/observability/metrics-storage.js.map +1 -0
- package/.claude-flow-novice/dist/src/observability/telemetry.js +26 -0
- package/.claude-flow-novice/dist/src/observability/telemetry.js.map +1 -1
- package/.claude-flow-novice/dist/src/providers/tiered-router.js +64 -10
- package/.claude-flow-novice/dist/src/providers/tiered-router.js.map +1 -1
- package/.claude-flow-novice/dist/src/providers/zai-provider.js +196 -97
- package/.claude-flow-novice/dist/src/providers/zai-provider.js.map +1 -1
- package/.claude-flow-novice/dist/src/slash-commands/cfn-claude-sync.js +533 -0
- package/.claude-flow-novice/dist/src/slash-commands/index.js +5 -0
- package/.claude-flow-novice/dist/src/slash-commands/metrics-summary-class.js +74 -0
- package/.claude-flow-novice/dist/src/slash-commands/metrics-summary.js +335 -0
- package/.claude-flow-novice/dist/src/slash-commands/register-all-commands.js +12 -0
- package/.claude-flow-novice/dist/src/verification/checkpoint-compression-demo.js +96 -0
- package/.claude-flow-novice/dist/src/verification/checkpoint-compression-demo.js.map +1 -0
- package/.claude-flow-novice/dist/src/verification/checkpoint-compression.js +406 -0
- package/.claude-flow-novice/dist/src/verification/checkpoint-compression.js.map +1 -0
- package/.claude-flow-novice/dist/src/verification/checkpoint-manager.js +35 -5
- package/.claude-flow-novice/dist/src/verification/checkpoint-manager.js.map +1 -1
- package/.claude-flow-novice/dist/src/web/api/apm-routes.js +355 -0
- package/.claude-flow-novice/dist/src/web/api/apm-routes.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/config/api-config.js +186 -0
- package/.claude-flow-novice/dist/src/web/api/config/api-config.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/auth.js +205 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/auth.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/cache.js +262 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/cache.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/error-handler.js +250 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/error-handler.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/request-logger.js +217 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/request-logger.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/validation.js +325 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/validation.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/routes/events.js +465 -0
- package/.claude-flow-novice/dist/src/web/api/routes/events.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/routes/hierarchy.js +302 -0
- package/.claude-flow-novice/dist/src/web/api/routes/hierarchy.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/routes/index.js +14 -0
- package/.claude-flow-novice/dist/src/web/api/routes/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/routes/metrics.js +561 -0
- package/.claude-flow-novice/dist/src/web/api/routes/metrics.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/routes/status.js +450 -0
- package/.claude-flow-novice/dist/src/web/api/routes/status.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/server.js +451 -0
- package/.claude-flow-novice/dist/src/web/api/server.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/dashboard/hooks/useWebSocket.js +385 -0
- package/.claude-flow-novice/dist/src/web/dashboard/hooks/useWebSocket.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/dashboard/index.js +87 -0
- package/.claude-flow-novice/dist/src/web/dashboard/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/dashboard/types.js +6 -0
- package/.claude-flow-novice/dist/src/web/dashboard/types.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/frontend/src/utils/security.js +425 -0
- package/.claude-flow-novice/dist/src/web/frontend/src/utils/security.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/security/security-middleware.js +379 -0
- package/.claude-flow-novice/dist/src/web/security/security-middleware.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/websocket/apm-websocket-handler.js +441 -0
- package/.claude-flow-novice/dist/src/web/websocket/apm-websocket-handler.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/websocket/websocket-manager.js +255 -1
- package/.claude-flow-novice/dist/src/web/websocket/websocket-manager.js.map +1 -1
- package/.claude-flow-novice/metrics.db +0 -0
- package/.claude-flow-novice/metrics.db-shm +0 -0
- package/.claude-flow-novice/metrics.db-wal +0 -0
- package/AGENT_PERFORMANCE_GUIDELINES.md +88 -0
- package/CLAUDE.md +60 -3
- package/MEMORY_LEAK_ROOT_CAUSE.md +149 -0
- package/README.md +27 -0
- package/config/hooks/post-edit-pipeline.js +36 -2
- package/examples/metrics-counter-demo.ts +106 -0
- package/examples/persistent-metrics-demo.ts +83 -0
- package/examples/phase-5-multi-level-control.ts +282 -0
- package/examples/session-pool-optimizer-example.ts +311 -0
- package/package.json +18 -4
- package/scripts/check-routing-stats.cjs +122 -0
- package/scripts/monitor-loop.sh +65 -0
- package/scripts/monitor-memory.sh +47 -0
- package/scripts/monitor.py +43 -0
- package/scripts/pre-publish-validation.cjs +212 -0
- package/scripts/test-provider-routing.cjs +228 -0
- package/scripts/test-routing-telemetry.cjs +147 -0
- package/scripts/test-zai-10k.cjs +81 -0
- package/scripts/test-zai-api.cjs +191 -0
- package/scripts/test-zai-diagnostic.cjs +151 -0
- package/scripts/test-zai-final.cjs +128 -0
- package/scripts/test-zai-with-env.cjs +85 -0
- package/scripts/validate-coordination-cli.js +69 -0
- package/scripts/validate-coordination-toggle-integration.cjs +501 -0
- package/src/cli/simple-commands/init/templates/CLAUDE.md +29 -0
- package/src/observability/metrics-counter.ts +347 -0
- package/src/observability/metrics-storage.ts +356 -0
- package/src/observability/telemetry.ts +658 -0
- package/src/slash-commands/cfn-claude-sync.js +533 -0
- package/src/slash-commands/index.js +5 -0
- package/src/slash-commands/metrics-summary-class.js +74 -0
- package/src/slash-commands/metrics-summary.js +335 -0
- package/src/slash-commands/register-all-commands.js +12 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication Middleware
|
|
3
|
+
*
|
|
4
|
+
* JWT and API key authentication for the transparency API server
|
|
5
|
+
*
|
|
6
|
+
* @module web/api/middleware/auth
|
|
7
|
+
*/ import jwt from 'jsonwebtoken';
|
|
8
|
+
/**
|
|
9
|
+
* JWT Authentication Middleware
|
|
10
|
+
*/ export function authMiddleware(config) {
|
|
11
|
+
return (req, res, next)=>{
|
|
12
|
+
// Skip authentication for health check and API documentation
|
|
13
|
+
if (req.path === '/health' || req.path === '/api') {
|
|
14
|
+
return next();
|
|
15
|
+
}
|
|
16
|
+
// Try JWT authentication first
|
|
17
|
+
const authHeader = req.headers.authorization;
|
|
18
|
+
if (authHeader && authHeader.startsWith('Bearer ')) {
|
|
19
|
+
const token = authHeader.substring(7);
|
|
20
|
+
try {
|
|
21
|
+
const decoded = jwt.verify(token, config.jwtSecret);
|
|
22
|
+
req.user = {
|
|
23
|
+
id: decoded.sub || decoded.id,
|
|
24
|
+
username: decoded.username,
|
|
25
|
+
role: decoded.role || 'user',
|
|
26
|
+
permissions: decoded.permissions || []
|
|
27
|
+
};
|
|
28
|
+
return next();
|
|
29
|
+
} catch (error) {
|
|
30
|
+
// Invalid JWT, try API key authentication
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Try API key authentication
|
|
34
|
+
const apiKey = req.headers['x-api-key'];
|
|
35
|
+
if (apiKey && apiKey === config.apiKey) {
|
|
36
|
+
req.apiKey = apiKey;
|
|
37
|
+
return next();
|
|
38
|
+
}
|
|
39
|
+
// Check for basic auth (for development/testing)
|
|
40
|
+
const basicAuth = req.headers.authorization;
|
|
41
|
+
if (basicAuth && basicAuth.startsWith('Basic ')) {
|
|
42
|
+
try {
|
|
43
|
+
const credentials = Buffer.from(basicAuth.substring(6), 'base64').toString();
|
|
44
|
+
const [username, password] = credentials.split(':');
|
|
45
|
+
// Simple development authentication (replace with proper auth in production)
|
|
46
|
+
if (config.environment === 'development' && username === 'admin' && password === 'admin') {
|
|
47
|
+
req.user = {
|
|
48
|
+
id: 'dev-admin',
|
|
49
|
+
username: 'admin',
|
|
50
|
+
role: 'admin',
|
|
51
|
+
permissions: [
|
|
52
|
+
'read',
|
|
53
|
+
'write',
|
|
54
|
+
'admin'
|
|
55
|
+
]
|
|
56
|
+
};
|
|
57
|
+
return next();
|
|
58
|
+
}
|
|
59
|
+
} catch (error) {
|
|
60
|
+
// Invalid basic auth
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// No valid authentication found
|
|
64
|
+
if (config.environment === 'development') {
|
|
65
|
+
// Allow unauthenticated access in development with warning
|
|
66
|
+
console.warn('Unauthenticated request in development mode:', req.method, req.path);
|
|
67
|
+
req.user = {
|
|
68
|
+
id: 'dev-anonymous',
|
|
69
|
+
username: 'anonymous',
|
|
70
|
+
role: 'user',
|
|
71
|
+
permissions: [
|
|
72
|
+
'read'
|
|
73
|
+
]
|
|
74
|
+
};
|
|
75
|
+
return next();
|
|
76
|
+
}
|
|
77
|
+
return res.status(401).json({
|
|
78
|
+
error: 'Unauthorized',
|
|
79
|
+
message: 'Authentication required',
|
|
80
|
+
timestamp: new Date().toISOString()
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Role-based authorization middleware
|
|
86
|
+
*/ export function requireRole(requiredRole) {
|
|
87
|
+
return (req, res, next)=>{
|
|
88
|
+
if (!req.user) {
|
|
89
|
+
return res.status(401).json({
|
|
90
|
+
error: 'Unauthorized',
|
|
91
|
+
message: 'Authentication required',
|
|
92
|
+
timestamp: new Date().toISOString()
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (req.user.role !== requiredRole && req.user.role !== 'admin') {
|
|
96
|
+
return res.status(403).json({
|
|
97
|
+
error: 'Forbidden',
|
|
98
|
+
message: `Requires ${requiredRole} role`,
|
|
99
|
+
timestamp: new Date().toISOString()
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
next();
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Permission-based authorization middleware
|
|
107
|
+
*/ export function requirePermission(permission) {
|
|
108
|
+
return (req, res, next)=>{
|
|
109
|
+
if (!req.user) {
|
|
110
|
+
return res.status(401).json({
|
|
111
|
+
error: 'Unauthorized',
|
|
112
|
+
message: 'Authentication required',
|
|
113
|
+
timestamp: new Date().toISOString()
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const hasPermission = req.user.permissions?.includes(permission) || req.user.role === 'admin' || req.user.permissions?.includes('*');
|
|
117
|
+
if (!hasPermission) {
|
|
118
|
+
return res.status(403).json({
|
|
119
|
+
error: 'Forbidden',
|
|
120
|
+
message: `Requires ${permission} permission`,
|
|
121
|
+
timestamp: new Date().toISOString()
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
next();
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Optional authentication middleware (doesn't fail if no auth)
|
|
129
|
+
*/ export function optionalAuth(config) {
|
|
130
|
+
return (req, res, next)=>{
|
|
131
|
+
// Try JWT authentication
|
|
132
|
+
const authHeader = req.headers.authorization;
|
|
133
|
+
if (authHeader && authHeader.startsWith('Bearer ')) {
|
|
134
|
+
const token = authHeader.substring(7);
|
|
135
|
+
try {
|
|
136
|
+
const decoded = jwt.verify(token, config.jwtSecret);
|
|
137
|
+
req.user = {
|
|
138
|
+
id: decoded.sub || decoded.id,
|
|
139
|
+
username: decoded.username,
|
|
140
|
+
role: decoded.role || 'user',
|
|
141
|
+
permissions: decoded.permissions || []
|
|
142
|
+
};
|
|
143
|
+
} catch (error) {
|
|
144
|
+
// Invalid JWT, ignore
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// Try API key authentication
|
|
148
|
+
const apiKey = req.headers['x-api-key'];
|
|
149
|
+
if (apiKey && apiKey === config.apiKey) {
|
|
150
|
+
req.apiKey = apiKey;
|
|
151
|
+
}
|
|
152
|
+
next();
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* WebSocket authentication helper
|
|
157
|
+
*/ export function authenticateWebSocket(socket, config) {
|
|
158
|
+
const token = socket.handshake.auth.token || socket.handshake.headers.authorization?.replace('Bearer ', '');
|
|
159
|
+
if (!token) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
// JWT authentication
|
|
164
|
+
const decoded = jwt.verify(token, config.jwtSecret);
|
|
165
|
+
socket.data.user = {
|
|
166
|
+
id: decoded.sub || decoded.id,
|
|
167
|
+
username: decoded.username,
|
|
168
|
+
role: decoded.role || 'user',
|
|
169
|
+
permissions: decoded.permissions || []
|
|
170
|
+
};
|
|
171
|
+
return true;
|
|
172
|
+
} catch (error) {
|
|
173
|
+
// API key authentication
|
|
174
|
+
if (token === config.apiKey) {
|
|
175
|
+
socket.data.apiKey = token;
|
|
176
|
+
socket.data.user = {
|
|
177
|
+
id: 'api-key-user',
|
|
178
|
+
username: 'api-key',
|
|
179
|
+
role: 'service',
|
|
180
|
+
permissions: [
|
|
181
|
+
'read',
|
|
182
|
+
'write'
|
|
183
|
+
]
|
|
184
|
+
};
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Generate JWT token for user
|
|
192
|
+
*/ export function generateToken(user, config) {
|
|
193
|
+
return jwt.sign({
|
|
194
|
+
sub: user.id,
|
|
195
|
+
username: user.username,
|
|
196
|
+
role: user.role,
|
|
197
|
+
permissions: user.permissions
|
|
198
|
+
}, config.jwtSecret, {
|
|
199
|
+
expiresIn: config.jwtExpiration,
|
|
200
|
+
issuer: 'transparency-api',
|
|
201
|
+
audience: 'transparency-dashboard'
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/web/api/middleware/auth.ts"],"names":["jwt","authMiddleware","config","req","res","next","path","authHeader","headers","authorization","startsWith","token","substring","decoded","verify","jwtSecret","user","id","sub","username","role","permissions","error","apiKey","basicAuth","credentials","Buffer","from","toString","password","split","environment","console","warn","method","status","json","message","timestamp","Date","toISOString","requireRole","requiredRole","requirePermission","permission","hasPermission","includes","optionalAuth","authenticateWebSocket","socket","handshake","auth","replace","data","generateToken","sign","expiresIn","jwtExpiration","issuer","audience"],"mappings":"AAAA;;;;;;CAMC,GAGD,OAAOA,SAAS,eAAe;AAgB/B;;CAEC,GACD,OAAO,SAASC,eAAeC,MAAiB;IAC9C,OAAO,CAACC,KAA2BC,KAAeC;QAChD,6DAA6D;QAC7D,IAAIF,IAAIG,IAAI,KAAK,aAAaH,IAAIG,IAAI,KAAK,QAAQ;YACjD,OAAOD;QACT;QAEA,+BAA+B;QAC/B,MAAME,aAAaJ,IAAIK,OAAO,CAACC,aAAa;QAC5C,IAAIF,cAAcA,WAAWG,UAAU,CAAC,YAAY;YAClD,MAAMC,QAAQJ,WAAWK,SAAS,CAAC;YAEnC,IAAI;gBACF,MAAMC,UAAUb,IAAIc,MAAM,CAACH,OAAOT,OAAOa,SAAS;gBAClDZ,IAAIa,IAAI,GAAG;oBACTC,IAAIJ,QAAQK,GAAG,IAAIL,QAAQI,EAAE;oBAC7BE,UAAUN,QAAQM,QAAQ;oBAC1BC,MAAMP,QAAQO,IAAI,IAAI;oBACtBC,aAAaR,QAAQQ,WAAW,IAAI,EAAE;gBACxC;gBACA,OAAOhB;YACT,EAAE,OAAOiB,OAAO;YACd,0CAA0C;YAC5C;QACF;QAE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BAAC;oBAAQ;iBAAQ;YAChC;YACA,OAAO;QACT;IACF;IAEA,OAAO;AACT;AAEA;;CAEC,GACD,OAAO,SAASiC,cAActC,IAAS,EAAEd,MAAiB;IACxD,OAAOF,IAAIuD,IAAI,CACb;QACErC,KAAKF,KAAKC,EAAE;QACZE,UAAUH,KAAKG,QAAQ;QACvBC,MAAMJ,KAAKI,IAAI;QACfC,aAAaL,KAAKK,WAAW;IAC/B,GACAnB,OAAOa,SAAS,EAChB;QACEyC,WAAWtD,OAAOuD,aAAa;QAC/BC,QAAQ;QACRC,UAAU;IACZ;AAEJ"}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache Middleware
|
|
3
|
+
*
|
|
4
|
+
* Response caching middleware for the transparency API server
|
|
5
|
+
*
|
|
6
|
+
* @module web/api/middleware/cache
|
|
7
|
+
*/ /**
|
|
8
|
+
* Cache middleware factory
|
|
9
|
+
*/ export function cacheMiddleware(cache, defaultTtl = 5000 // 5 seconds
|
|
10
|
+
) {
|
|
11
|
+
return (req, res, next)=>{
|
|
12
|
+
// Only cache GET requests
|
|
13
|
+
if (req.method !== 'GET') {
|
|
14
|
+
return next();
|
|
15
|
+
}
|
|
16
|
+
// Generate cache key
|
|
17
|
+
const cacheKey = generateCacheKey(req);
|
|
18
|
+
// Check if we have a valid cached response
|
|
19
|
+
const cached = cache.get(cacheKey);
|
|
20
|
+
if (cached && Date.now() - cached.timestamp < cached.ttl) {
|
|
21
|
+
// Add cache headers
|
|
22
|
+
res.setHeader('X-Cache', 'HIT');
|
|
23
|
+
res.setHeader('X-Cache-Age', Math.floor((Date.now() - cached.timestamp) / 1000));
|
|
24
|
+
if (cached.etag) {
|
|
25
|
+
res.setHeader('ETag', cached.etag);
|
|
26
|
+
}
|
|
27
|
+
return res.json(cached.data);
|
|
28
|
+
}
|
|
29
|
+
// Intercept res.json to cache the response
|
|
30
|
+
const originalJson = res.json;
|
|
31
|
+
res.json = function(data) {
|
|
32
|
+
// Only cache successful responses
|
|
33
|
+
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
34
|
+
const ttl = getCacheTtl(req, defaultTtl);
|
|
35
|
+
const etag = generateETag(data);
|
|
36
|
+
// Cache the response
|
|
37
|
+
cache.set(cacheKey, {
|
|
38
|
+
data,
|
|
39
|
+
timestamp: Date.now(),
|
|
40
|
+
ttl,
|
|
41
|
+
etag
|
|
42
|
+
});
|
|
43
|
+
// Add cache headers
|
|
44
|
+
res.setHeader('X-Cache', 'MISS');
|
|
45
|
+
res.setHeader('X-Cache-TTL', Math.floor(ttl / 1000));
|
|
46
|
+
res.setHeader('Cache-Control', `public, max-age=${Math.floor(ttl / 1000)}`);
|
|
47
|
+
if (etag) {
|
|
48
|
+
res.setHeader('ETag', etag);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return originalJson.call(this, data);
|
|
52
|
+
};
|
|
53
|
+
next();
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Generate cache key from request
|
|
58
|
+
*/ function generateCacheKey(req) {
|
|
59
|
+
const url = new URL(req.originalUrl, `http://${req.headers.host}`);
|
|
60
|
+
// Include query parameters in cache key
|
|
61
|
+
const queryParams = new URLSearchParams(url.search);
|
|
62
|
+
queryParams.sort(); // Sort for consistent keys
|
|
63
|
+
const queryString = queryParams.toString();
|
|
64
|
+
const path = url.pathname;
|
|
65
|
+
// Include user ID if authenticated (for user-specific caching)
|
|
66
|
+
const userId = req.user?.id || 'anonymous';
|
|
67
|
+
return `${req.method}:${path}:${queryString}:${userId}`;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get cache TTL based on request characteristics
|
|
71
|
+
*/ function getCacheTtl(req, defaultTtl) {
|
|
72
|
+
// Different TTLs for different endpoints
|
|
73
|
+
const path = req.path;
|
|
74
|
+
if (path.includes('/metrics')) {
|
|
75
|
+
return 10000; // 10 seconds for metrics
|
|
76
|
+
}
|
|
77
|
+
if (path.includes('/status')) {
|
|
78
|
+
return 2000; // 2 seconds for status
|
|
79
|
+
}
|
|
80
|
+
if (path.includes('/events')) {
|
|
81
|
+
return 5000; // 5 seconds for events
|
|
82
|
+
}
|
|
83
|
+
if (path.includes('/hierarchy')) {
|
|
84
|
+
return 30000; // 30 seconds for hierarchy (changes less frequently)
|
|
85
|
+
}
|
|
86
|
+
if (path.includes('/analytics')) {
|
|
87
|
+
return 60000; // 1 minute for analytics
|
|
88
|
+
}
|
|
89
|
+
return defaultTtl;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Generate ETag for response data
|
|
93
|
+
*/ function generateETag(data) {
|
|
94
|
+
const crypto = require('crypto');
|
|
95
|
+
const hash = crypto.createHash('md5');
|
|
96
|
+
hash.update(JSON.stringify(data));
|
|
97
|
+
return `"${hash.digest('hex')}"`;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Conditional request middleware (ETag support)
|
|
101
|
+
*/ export function conditionalRequest() {
|
|
102
|
+
return (req, res, next)=>{
|
|
103
|
+
const ifNoneMatch = req.get('If-None-Match');
|
|
104
|
+
// This will be checked in the cache middleware
|
|
105
|
+
if (ifNoneMatch) {
|
|
106
|
+
req.ifNoneMatch = ifNoneMatch;
|
|
107
|
+
}
|
|
108
|
+
next();
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Cache invalidation middleware
|
|
113
|
+
*/ export function invalidateCache(cache) {
|
|
114
|
+
return (req, res, next)=>{
|
|
115
|
+
// Invalidate cache for POST, PUT, DELETE, PATCH requests
|
|
116
|
+
if ([
|
|
117
|
+
'POST',
|
|
118
|
+
'PUT',
|
|
119
|
+
'DELETE',
|
|
120
|
+
'PATCH'
|
|
121
|
+
].includes(req.method)) {
|
|
122
|
+
const pattern = getInvalidationPattern(req);
|
|
123
|
+
// Remove matching cache entries
|
|
124
|
+
for (const key of cache.keys()){
|
|
125
|
+
if (key.includes(pattern)) {
|
|
126
|
+
cache.delete(key);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
next();
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get cache invalidation pattern for request
|
|
135
|
+
*/ function getInvalidationPattern(req) {
|
|
136
|
+
const path = req.path;
|
|
137
|
+
if (path.includes('/agents')) {
|
|
138
|
+
return '/agents';
|
|
139
|
+
}
|
|
140
|
+
if (path.includes('/status')) {
|
|
141
|
+
return '/status';
|
|
142
|
+
}
|
|
143
|
+
if (path.includes('/events')) {
|
|
144
|
+
return '/events';
|
|
145
|
+
}
|
|
146
|
+
if (path.includes('/metrics')) {
|
|
147
|
+
return '/metrics';
|
|
148
|
+
}
|
|
149
|
+
if (path.includes('/hierarchy')) {
|
|
150
|
+
return '/hierarchy';
|
|
151
|
+
}
|
|
152
|
+
return path;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Cache warming middleware
|
|
156
|
+
*/ export function warmCache(cache, warmupFn) {
|
|
157
|
+
return async (req, res, next)=>{
|
|
158
|
+
// Run cache warmup on first request
|
|
159
|
+
if (cache.size === 0 && req.path === '/health') {
|
|
160
|
+
try {
|
|
161
|
+
await warmupFn();
|
|
162
|
+
} catch (error) {
|
|
163
|
+
console.error('Cache warmup failed:', error);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
next();
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Memory-based cache store
|
|
171
|
+
*/ export class MemoryCache {
|
|
172
|
+
cache = new Map();
|
|
173
|
+
maxSize;
|
|
174
|
+
cleanupInterval;
|
|
175
|
+
constructor(maxSize = 1000, cleanupIntervalMs = 60000){
|
|
176
|
+
this.maxSize = maxSize;
|
|
177
|
+
// Clean up expired entries periodically
|
|
178
|
+
this.cleanupInterval = setInterval(()=>{
|
|
179
|
+
this.cleanup();
|
|
180
|
+
}, cleanupIntervalMs);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Get cache entry
|
|
184
|
+
*/ get(key) {
|
|
185
|
+
const entry = this.cache.get(key);
|
|
186
|
+
if (entry && Date.now() - entry.timestamp < entry.ttl) {
|
|
187
|
+
return entry;
|
|
188
|
+
}
|
|
189
|
+
if (entry) {
|
|
190
|
+
this.cache.delete(key);
|
|
191
|
+
}
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Set cache entry
|
|
196
|
+
*/ set(key, data, ttl = 5000) {
|
|
197
|
+
// Remove oldest entries if cache is full
|
|
198
|
+
if (this.cache.size >= this.maxSize) {
|
|
199
|
+
const oldestKey = this.cache.keys().next().value;
|
|
200
|
+
this.cache.delete(oldestKey);
|
|
201
|
+
}
|
|
202
|
+
this.cache.set(key, {
|
|
203
|
+
data,
|
|
204
|
+
timestamp: Date.now(),
|
|
205
|
+
ttl
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Delete cache entry
|
|
210
|
+
*/ delete(key) {
|
|
211
|
+
return this.cache.delete(key);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Clear cache
|
|
215
|
+
*/ clear() {
|
|
216
|
+
this.cache.clear();
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Get cache size
|
|
220
|
+
*/ size() {
|
|
221
|
+
return this.cache.size;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Get cache statistics
|
|
225
|
+
*/ getStats() {
|
|
226
|
+
const entries = Array.from(this.cache.entries()).map(([key, entry])=>({
|
|
227
|
+
key,
|
|
228
|
+
age: Date.now() - entry.timestamp,
|
|
229
|
+
ttl: entry.ttl,
|
|
230
|
+
size: JSON.stringify(entry.data).length
|
|
231
|
+
}));
|
|
232
|
+
return {
|
|
233
|
+
size: this.cache.size,
|
|
234
|
+
maxSize: this.maxSize,
|
|
235
|
+
entries
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Clean up expired entries
|
|
240
|
+
*/ cleanup() {
|
|
241
|
+
const now = Date.now();
|
|
242
|
+
const keysToDelete = [];
|
|
243
|
+
for (const [key, entry] of this.cache.entries()){
|
|
244
|
+
if (now - entry.timestamp >= entry.ttl) {
|
|
245
|
+
keysToDelete.push(key);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
for (const key of keysToDelete){
|
|
249
|
+
this.cache.delete(key);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Destroy cache store
|
|
254
|
+
*/ destroy() {
|
|
255
|
+
if (this.cleanupInterval) {
|
|
256
|
+
clearInterval(this.cleanupInterval);
|
|
257
|
+
}
|
|
258
|
+
this.clear();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/web/api/middleware/cache.ts"],"names":["cacheMiddleware","cache","defaultTtl","req","res","next","method","cacheKey","generateCacheKey","cached","get","Date","now","timestamp","ttl","setHeader","Math","floor","etag","json","data","originalJson","statusCode","getCacheTtl","generateETag","set","call","url","URL","originalUrl","headers","host","queryParams","URLSearchParams","search","sort","queryString","toString","path","pathname","userId","user","id","includes","crypto","require","hash","createHash","update","JSON","stringify","digest","conditionalRequest","ifNoneMatch","invalidateCache","pattern","getInvalidationPattern","key","keys","delete","warmCache","warmupFn","size","error","console","MemoryCache","Map","maxSize","cleanupInterval","cleanupIntervalMs","setInterval","cleanup","entry","undefined","oldestKey","value","clear","getStats","entries","Array","from","map","age","length","keysToDelete","push","destroy","clearInterval"],"mappings":"AAAA;;;;;;CAMC,GAcD;;CAEC,GACD,OAAO,SAASA,gBACdC,KAA8B,EAC9BC,aAAqB,KAAK,YAAY;AAAb;IAEzB,OAAO,CAACC,KAAcC,KAAeC;QACnC,0BAA0B;QAC1B,IAAIF,IAAIG,MAAM,KAAK,OAAO;YACxB,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