clawsec 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +560 -0
- package/dist/bin/clawsec.d.ts +7 -0
- package/dist/bin/clawsec.d.ts.map +1 -0
- package/dist/bin/clawsec.js +12 -0
- package/dist/bin/clawsec.js.map +1 -0
- package/dist/src/actions/block.d.ts +22 -0
- package/dist/src/actions/block.d.ts.map +1 -0
- package/dist/src/actions/block.js +83 -0
- package/dist/src/actions/block.js.map +1 -0
- package/dist/src/actions/confirm.d.ts +35 -0
- package/dist/src/actions/confirm.d.ts.map +1 -0
- package/dist/src/actions/confirm.js +156 -0
- package/dist/src/actions/confirm.js.map +1 -0
- package/dist/src/actions/executor.d.ts +64 -0
- package/dist/src/actions/executor.d.ts.map +1 -0
- package/dist/src/actions/executor.js +114 -0
- package/dist/src/actions/executor.js.map +1 -0
- package/dist/src/actions/index.d.ts +13 -0
- package/dist/src/actions/index.d.ts.map +1 -0
- package/dist/src/actions/index.js +15 -0
- package/dist/src/actions/index.js.map +1 -0
- package/dist/src/actions/log.d.ts +19 -0
- package/dist/src/actions/log.d.ts.map +1 -0
- package/dist/src/actions/log.js +63 -0
- package/dist/src/actions/log.js.map +1 -0
- package/dist/src/actions/types.d.ts +85 -0
- package/dist/src/actions/types.d.ts.map +1 -0
- package/dist/src/actions/types.js +78 -0
- package/dist/src/actions/types.js.map +1 -0
- package/dist/src/actions/warn.d.ts +22 -0
- package/dist/src/actions/warn.d.ts.map +1 -0
- package/dist/src/actions/warn.js +84 -0
- package/dist/src/actions/warn.js.map +1 -0
- package/dist/src/approval/agent-confirm.d.ts +104 -0
- package/dist/src/approval/agent-confirm.d.ts.map +1 -0
- package/dist/src/approval/agent-confirm.js +173 -0
- package/dist/src/approval/agent-confirm.js.map +1 -0
- package/dist/src/approval/index.d.ts +14 -0
- package/dist/src/approval/index.d.ts.map +1 -0
- package/dist/src/approval/index.js +9 -0
- package/dist/src/approval/index.js.map +1 -0
- package/dist/src/approval/native.d.ts +56 -0
- package/dist/src/approval/native.d.ts.map +1 -0
- package/dist/src/approval/native.js +196 -0
- package/dist/src/approval/native.js.map +1 -0
- package/dist/src/approval/store.d.ts +88 -0
- package/dist/src/approval/store.d.ts.map +1 -0
- package/dist/src/approval/store.js +192 -0
- package/dist/src/approval/store.js.map +1 -0
- package/dist/src/approval/types.d.ts +119 -0
- package/dist/src/approval/types.d.ts.map +1 -0
- package/dist/src/approval/types.js +6 -0
- package/dist/src/approval/types.js.map +1 -0
- package/dist/src/approval/webhook.d.ts +170 -0
- package/dist/src/approval/webhook.d.ts.map +1 -0
- package/dist/src/approval/webhook.js +362 -0
- package/dist/src/approval/webhook.js.map +1 -0
- package/dist/src/cli/commands/audit.d.ts +43 -0
- package/dist/src/cli/commands/audit.d.ts.map +1 -0
- package/dist/src/cli/commands/audit.js +115 -0
- package/dist/src/cli/commands/audit.js.map +1 -0
- package/dist/src/cli/commands/feedback.d.ts +27 -0
- package/dist/src/cli/commands/feedback.d.ts.map +1 -0
- package/dist/src/cli/commands/feedback.js +228 -0
- package/dist/src/cli/commands/feedback.js.map +1 -0
- package/dist/src/cli/commands/index.d.ts +11 -0
- package/dist/src/cli/commands/index.d.ts.map +1 -0
- package/dist/src/cli/commands/index.js +13 -0
- package/dist/src/cli/commands/index.js.map +1 -0
- package/dist/src/cli/commands/status.d.ts +20 -0
- package/dist/src/cli/commands/status.d.ts.map +1 -0
- package/dist/src/cli/commands/status.js +122 -0
- package/dist/src/cli/commands/status.js.map +1 -0
- package/dist/src/cli/commands/test.d.ts +23 -0
- package/dist/src/cli/commands/test.d.ts.map +1 -0
- package/dist/src/cli/commands/test.js +134 -0
- package/dist/src/cli/commands/test.js.map +1 -0
- package/dist/src/cli/commands/types.d.ts +81 -0
- package/dist/src/cli/commands/types.d.ts.map +1 -0
- package/dist/src/cli/commands/types.js +6 -0
- package/dist/src/cli/commands/types.js.map +1 -0
- package/dist/src/cli/index.d.ts +17 -0
- package/dist/src/cli/index.d.ts.map +1 -0
- package/dist/src/cli/index.js +267 -0
- package/dist/src/cli/index.js.map +1 -0
- package/dist/src/config/defaults.d.ts +20 -0
- package/dist/src/config/defaults.d.ts.map +1 -0
- package/dist/src/config/defaults.js +123 -0
- package/dist/src/config/defaults.js.map +1 -0
- package/dist/src/config/index.d.ts +8 -0
- package/dist/src/config/index.d.ts.map +1 -0
- package/dist/src/config/index.js +41 -0
- package/dist/src/config/index.js.map +1 -0
- package/dist/src/config/loader.d.ts +99 -0
- package/dist/src/config/loader.d.ts.map +1 -0
- package/dist/src/config/loader.js +242 -0
- package/dist/src/config/loader.js.map +1 -0
- package/dist/src/config/schema.d.ts +627 -0
- package/dist/src/config/schema.d.ts.map +1 -0
- package/dist/src/config/schema.js +585 -0
- package/dist/src/config/schema.js.map +1 -0
- package/dist/src/detectors/destructive/cloud-detector.d.ts +51 -0
- package/dist/src/detectors/destructive/cloud-detector.d.ts.map +1 -0
- package/dist/src/detectors/destructive/cloud-detector.js +556 -0
- package/dist/src/detectors/destructive/cloud-detector.js.map +1 -0
- package/dist/src/detectors/destructive/code-detector.d.ts +59 -0
- package/dist/src/detectors/destructive/code-detector.d.ts.map +1 -0
- package/dist/src/detectors/destructive/code-detector.js +558 -0
- package/dist/src/detectors/destructive/code-detector.js.map +1 -0
- package/dist/src/detectors/destructive/index.d.ts +54 -0
- package/dist/src/detectors/destructive/index.d.ts.map +1 -0
- package/dist/src/detectors/destructive/index.js +168 -0
- package/dist/src/detectors/destructive/index.js.map +1 -0
- package/dist/src/detectors/destructive/shell-detector.d.ts +43 -0
- package/dist/src/detectors/destructive/shell-detector.d.ts.map +1 -0
- package/dist/src/detectors/destructive/shell-detector.js +302 -0
- package/dist/src/detectors/destructive/shell-detector.js.map +1 -0
- package/dist/src/detectors/destructive/types.d.ts +143 -0
- package/dist/src/detectors/destructive/types.d.ts.map +1 -0
- package/dist/src/detectors/destructive/types.js +6 -0
- package/dist/src/detectors/destructive/types.js.map +1 -0
- package/dist/src/detectors/exfiltration/cloud-detector.d.ts +51 -0
- package/dist/src/detectors/exfiltration/cloud-detector.d.ts.map +1 -0
- package/dist/src/detectors/exfiltration/cloud-detector.js +427 -0
- package/dist/src/detectors/exfiltration/cloud-detector.js.map +1 -0
- package/dist/src/detectors/exfiltration/http-detector.d.ts +47 -0
- package/dist/src/detectors/exfiltration/http-detector.d.ts.map +1 -0
- package/dist/src/detectors/exfiltration/http-detector.js +429 -0
- package/dist/src/detectors/exfiltration/http-detector.js.map +1 -0
- package/dist/src/detectors/exfiltration/index.d.ts +44 -0
- package/dist/src/detectors/exfiltration/index.d.ts.map +1 -0
- package/dist/src/detectors/exfiltration/index.js +118 -0
- package/dist/src/detectors/exfiltration/index.js.map +1 -0
- package/dist/src/detectors/exfiltration/network-detector.d.ts +55 -0
- package/dist/src/detectors/exfiltration/network-detector.d.ts.map +1 -0
- package/dist/src/detectors/exfiltration/network-detector.js +504 -0
- package/dist/src/detectors/exfiltration/network-detector.js.map +1 -0
- package/dist/src/detectors/exfiltration/types.d.ts +139 -0
- package/dist/src/detectors/exfiltration/types.d.ts.map +1 -0
- package/dist/src/detectors/exfiltration/types.js +6 -0
- package/dist/src/detectors/exfiltration/types.js.map +1 -0
- package/dist/src/detectors/purchase/domain-detector.d.ts +44 -0
- package/dist/src/detectors/purchase/domain-detector.d.ts.map +1 -0
- package/dist/src/detectors/purchase/domain-detector.js +296 -0
- package/dist/src/detectors/purchase/domain-detector.js.map +1 -0
- package/dist/src/detectors/purchase/form-detector.d.ts +27 -0
- package/dist/src/detectors/purchase/form-detector.d.ts.map +1 -0
- package/dist/src/detectors/purchase/form-detector.js +344 -0
- package/dist/src/detectors/purchase/form-detector.js.map +1 -0
- package/dist/src/detectors/purchase/index.d.ts +65 -0
- package/dist/src/detectors/purchase/index.d.ts.map +1 -0
- package/dist/src/detectors/purchase/index.js +216 -0
- package/dist/src/detectors/purchase/index.js.map +1 -0
- package/dist/src/detectors/purchase/spend-tracker.d.ts +132 -0
- package/dist/src/detectors/purchase/spend-tracker.d.ts.map +1 -0
- package/dist/src/detectors/purchase/spend-tracker.js +313 -0
- package/dist/src/detectors/purchase/spend-tracker.js.map +1 -0
- package/dist/src/detectors/purchase/types.d.ts +139 -0
- package/dist/src/detectors/purchase/types.d.ts.map +1 -0
- package/dist/src/detectors/purchase/types.js +6 -0
- package/dist/src/detectors/purchase/types.js.map +1 -0
- package/dist/src/detectors/purchase/url-detector.d.ts +31 -0
- package/dist/src/detectors/purchase/url-detector.d.ts.map +1 -0
- package/dist/src/detectors/purchase/url-detector.js +292 -0
- package/dist/src/detectors/purchase/url-detector.js.map +1 -0
- package/dist/src/detectors/secrets/api-key-detector.d.ts +30 -0
- package/dist/src/detectors/secrets/api-key-detector.d.ts.map +1 -0
- package/dist/src/detectors/secrets/api-key-detector.js +297 -0
- package/dist/src/detectors/secrets/api-key-detector.js.map +1 -0
- package/dist/src/detectors/secrets/index.d.ts +43 -0
- package/dist/src/detectors/secrets/index.d.ts.map +1 -0
- package/dist/src/detectors/secrets/index.js +261 -0
- package/dist/src/detectors/secrets/index.js.map +1 -0
- package/dist/src/detectors/secrets/pii-detector.d.ts +54 -0
- package/dist/src/detectors/secrets/pii-detector.d.ts.map +1 -0
- package/dist/src/detectors/secrets/pii-detector.js +286 -0
- package/dist/src/detectors/secrets/pii-detector.js.map +1 -0
- package/dist/src/detectors/secrets/token-detector.d.ts +51 -0
- package/dist/src/detectors/secrets/token-detector.d.ts.map +1 -0
- package/dist/src/detectors/secrets/token-detector.js +233 -0
- package/dist/src/detectors/secrets/token-detector.js.map +1 -0
- package/dist/src/detectors/secrets/types.d.ts +157 -0
- package/dist/src/detectors/secrets/types.d.ts.map +1 -0
- package/dist/src/detectors/secrets/types.js +6 -0
- package/dist/src/detectors/secrets/types.js.map +1 -0
- package/dist/src/detectors/website/category-detector.d.ts +22 -0
- package/dist/src/detectors/website/category-detector.d.ts.map +1 -0
- package/dist/src/detectors/website/category-detector.js +162 -0
- package/dist/src/detectors/website/category-detector.js.map +1 -0
- package/dist/src/detectors/website/index.d.ts +53 -0
- package/dist/src/detectors/website/index.d.ts.map +1 -0
- package/dist/src/detectors/website/index.js +232 -0
- package/dist/src/detectors/website/index.js.map +1 -0
- package/dist/src/detectors/website/pattern-matcher.d.ts +33 -0
- package/dist/src/detectors/website/pattern-matcher.d.ts.map +1 -0
- package/dist/src/detectors/website/pattern-matcher.js +121 -0
- package/dist/src/detectors/website/pattern-matcher.js.map +1 -0
- package/dist/src/detectors/website/types.d.ts +105 -0
- package/dist/src/detectors/website/types.d.ts.map +1 -0
- package/dist/src/detectors/website/types.js +6 -0
- package/dist/src/detectors/website/types.js.map +1 -0
- package/dist/src/engine/analyzer.d.ts +87 -0
- package/dist/src/engine/analyzer.d.ts.map +1 -0
- package/dist/src/engine/analyzer.js +427 -0
- package/dist/src/engine/analyzer.js.map +1 -0
- package/dist/src/engine/cache.d.ts +80 -0
- package/dist/src/engine/cache.d.ts.map +1 -0
- package/dist/src/engine/cache.js +167 -0
- package/dist/src/engine/cache.js.map +1 -0
- package/dist/src/engine/index.d.ts +11 -0
- package/dist/src/engine/index.d.ts.map +1 -0
- package/dist/src/engine/index.js +11 -0
- package/dist/src/engine/index.js.map +1 -0
- package/dist/src/engine/llm-client.d.ts +210 -0
- package/dist/src/engine/llm-client.d.ts.map +1 -0
- package/dist/src/engine/llm-client.js +506 -0
- package/dist/src/engine/llm-client.js.map +1 -0
- package/dist/src/engine/types.d.ts +163 -0
- package/dist/src/engine/types.d.ts.map +1 -0
- package/dist/src/engine/types.js +21 -0
- package/dist/src/engine/types.js.map +1 -0
- package/dist/src/feedback/index.d.ts +9 -0
- package/dist/src/feedback/index.d.ts.map +1 -0
- package/dist/src/feedback/index.js +8 -0
- package/dist/src/feedback/index.js.map +1 -0
- package/dist/src/feedback/learner.d.ts +222 -0
- package/dist/src/feedback/learner.d.ts.map +1 -0
- package/dist/src/feedback/learner.js +401 -0
- package/dist/src/feedback/learner.js.map +1 -0
- package/dist/src/feedback/store.d.ts +113 -0
- package/dist/src/feedback/store.d.ts.map +1 -0
- package/dist/src/feedback/store.js +228 -0
- package/dist/src/feedback/store.js.map +1 -0
- package/dist/src/feedback/types.d.ts +126 -0
- package/dist/src/feedback/types.d.ts.map +1 -0
- package/dist/src/feedback/types.js +6 -0
- package/dist/src/feedback/types.js.map +1 -0
- package/dist/src/hooks/before-agent-start/handler.d.ts +37 -0
- package/dist/src/hooks/before-agent-start/handler.d.ts.map +1 -0
- package/dist/src/hooks/before-agent-start/handler.js +109 -0
- package/dist/src/hooks/before-agent-start/handler.js.map +1 -0
- package/dist/src/hooks/before-agent-start/index.d.ts +8 -0
- package/dist/src/hooks/before-agent-start/index.d.ts.map +1 -0
- package/dist/src/hooks/before-agent-start/index.js +7 -0
- package/dist/src/hooks/before-agent-start/index.js.map +1 -0
- package/dist/src/hooks/before-agent-start/prompts.d.ts +48 -0
- package/dist/src/hooks/before-agent-start/prompts.d.ts.map +1 -0
- package/dist/src/hooks/before-agent-start/prompts.js +103 -0
- package/dist/src/hooks/before-agent-start/prompts.js.map +1 -0
- package/dist/src/hooks/before-tool-call/handler.d.ts +42 -0
- package/dist/src/hooks/before-tool-call/handler.d.ts.map +1 -0
- package/dist/src/hooks/before-tool-call/handler.js +226 -0
- package/dist/src/hooks/before-tool-call/handler.js.map +1 -0
- package/dist/src/hooks/before-tool-call/index.d.ts +7 -0
- package/dist/src/hooks/before-tool-call/index.d.ts.map +1 -0
- package/dist/src/hooks/before-tool-call/index.js +6 -0
- package/dist/src/hooks/before-tool-call/index.js.map +1 -0
- package/dist/src/hooks/tool-result-persist/filter.d.ts +72 -0
- package/dist/src/hooks/tool-result-persist/filter.d.ts.map +1 -0
- package/dist/src/hooks/tool-result-persist/filter.js +305 -0
- package/dist/src/hooks/tool-result-persist/filter.js.map +1 -0
- package/dist/src/hooks/tool-result-persist/handler.d.ts +49 -0
- package/dist/src/hooks/tool-result-persist/handler.d.ts.map +1 -0
- package/dist/src/hooks/tool-result-persist/handler.js +217 -0
- package/dist/src/hooks/tool-result-persist/handler.js.map +1 -0
- package/dist/src/hooks/tool-result-persist/index.d.ts +11 -0
- package/dist/src/hooks/tool-result-persist/index.d.ts.map +1 -0
- package/dist/src/hooks/tool-result-persist/index.js +11 -0
- package/dist/src/hooks/tool-result-persist/index.js.map +1 -0
- package/dist/src/index.d.ts +256 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +222 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/notifications/discord.d.ts +10 -0
- package/dist/src/notifications/discord.d.ts.map +1 -0
- package/dist/src/notifications/discord.js +218 -0
- package/dist/src/notifications/discord.js.map +1 -0
- package/dist/src/notifications/index.d.ts +37 -0
- package/dist/src/notifications/index.d.ts.map +1 -0
- package/dist/src/notifications/index.js +68 -0
- package/dist/src/notifications/index.js.map +1 -0
- package/dist/src/notifications/slack.d.ts +10 -0
- package/dist/src/notifications/slack.d.ts.map +1 -0
- package/dist/src/notifications/slack.js +218 -0
- package/dist/src/notifications/slack.js.map +1 -0
- package/dist/src/notifications/telegram.d.ts +10 -0
- package/dist/src/notifications/telegram.d.ts.map +1 -0
- package/dist/src/notifications/telegram.js +242 -0
- package/dist/src/notifications/telegram.js.map +1 -0
- package/dist/src/notifications/types.d.ts +119 -0
- package/dist/src/notifications/types.d.ts.map +1 -0
- package/dist/src/notifications/types.js +6 -0
- package/dist/src/notifications/types.js.map +1 -0
- package/dist/src/proxy/index.d.ts +8 -0
- package/dist/src/proxy/index.d.ts.map +1 -0
- package/dist/src/proxy/index.js +9 -0
- package/dist/src/proxy/index.js.map +1 -0
- package/dist/src/proxy/middleware.d.ts +55 -0
- package/dist/src/proxy/middleware.d.ts.map +1 -0
- package/dist/src/proxy/middleware.js +215 -0
- package/dist/src/proxy/middleware.js.map +1 -0
- package/dist/src/proxy/server.d.ts +57 -0
- package/dist/src/proxy/server.d.ts.map +1 -0
- package/dist/src/proxy/server.js +298 -0
- package/dist/src/proxy/server.js.map +1 -0
- package/dist/src/proxy/types.d.ts +136 -0
- package/dist/src/proxy/types.d.ts.map +1 -0
- package/dist/src/proxy/types.js +6 -0
- package/dist/src/proxy/types.js.map +1 -0
- package/dist/src/sanitization/index.d.ts +10 -0
- package/dist/src/sanitization/index.d.ts.map +1 -0
- package/dist/src/sanitization/index.js +9 -0
- package/dist/src/sanitization/index.js.map +1 -0
- package/dist/src/sanitization/patterns.d.ts +51 -0
- package/dist/src/sanitization/patterns.d.ts.map +1 -0
- package/dist/src/sanitization/patterns.js +266 -0
- package/dist/src/sanitization/patterns.js.map +1 -0
- package/dist/src/sanitization/scanner.d.ts +29 -0
- package/dist/src/sanitization/scanner.d.ts.map +1 -0
- package/dist/src/sanitization/scanner.js +328 -0
- package/dist/src/sanitization/scanner.js.map +1 -0
- package/dist/src/sanitization/types.d.ts +57 -0
- package/dist/src/sanitization/types.d.ts.map +1 -0
- package/dist/src/sanitization/types.js +5 -0
- package/dist/src/sanitization/types.js.map +1 -0
- package/openclaw.plugin.json +114 -0
- package/package.json +63 -0
- package/rules/builtin/README.md +139 -0
- package/rules/builtin/ai-services.yaml +70 -0
- package/rules/builtin/api-keys.yaml +64 -0
- package/rules/builtin/authentication.yaml +56 -0
- package/rules/builtin/aws-security.yaml +57 -0
- package/rules/builtin/azure-security.yaml +58 -0
- package/rules/builtin/cicd-security.yaml +64 -0
- package/rules/builtin/cloud-storage.yaml +64 -0
- package/rules/builtin/container-registry.yaml +55 -0
- package/rules/builtin/crypto-wallets.yaml +71 -0
- package/rules/builtin/database-nosql.yaml +58 -0
- package/rules/builtin/database-sql.yaml +62 -0
- package/rules/builtin/development-env.yaml +67 -0
- package/rules/builtin/docker.yaml +57 -0
- package/rules/builtin/filesystem.yaml +71 -0
- package/rules/builtin/financial-pci.yaml +61 -0
- package/rules/builtin/gcp-security.yaml +57 -0
- package/rules/builtin/git-operations.yaml +68 -0
- package/rules/builtin/healthcare-hipaa.yaml +64 -0
- package/rules/builtin/kubernetes.yaml +60 -0
- package/rules/builtin/messaging-services.yaml +53 -0
- package/rules/builtin/minimal.yaml +47 -0
- package/rules/builtin/mobile-development.yaml +61 -0
- package/rules/builtin/monitoring.yaml +63 -0
- package/rules/builtin/network-security.yaml +57 -0
- package/rules/builtin/package-managers.yaml +74 -0
- package/rules/builtin/payment-processing.yaml +66 -0
- package/rules/builtin/pii-protection.yaml +48 -0
- package/rules/builtin/production-strict.yaml +55 -0
- package/rules/builtin/secrets-management.yaml +63 -0
- package/rules/builtin/serverless.yaml +74 -0
- package/rules/builtin/ssh-security.yaml +66 -0
- package/rules/builtin/terraform.yaml +51 -0
- package/rules/builtin/web-security.yaml +62 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spend Tracker
|
|
3
|
+
* Monitors per-transaction and daily spending limits for purchase protection
|
|
4
|
+
*/
|
|
5
|
+
import type { SpendLimits } from '../../config/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Record of a tracked spend transaction
|
|
8
|
+
*/
|
|
9
|
+
export interface SpendRecord {
|
|
10
|
+
/** Amount of the transaction */
|
|
11
|
+
amount: number;
|
|
12
|
+
/** Unix timestamp when the transaction was recorded */
|
|
13
|
+
timestamp: number;
|
|
14
|
+
/** Unique identifier for the transaction */
|
|
15
|
+
transactionId: string;
|
|
16
|
+
/** Domain where the transaction occurred */
|
|
17
|
+
domain?: string;
|
|
18
|
+
/** Whether the transaction was approved */
|
|
19
|
+
approved: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Result of a spend limit check
|
|
23
|
+
*/
|
|
24
|
+
export interface SpendLimitResult {
|
|
25
|
+
/** Whether the transaction is allowed */
|
|
26
|
+
allowed: boolean;
|
|
27
|
+
/** Which limit was exceeded, if any */
|
|
28
|
+
exceededLimit?: 'perTransaction' | 'daily';
|
|
29
|
+
/** Current total spent today */
|
|
30
|
+
currentDailyTotal: number;
|
|
31
|
+
/** Remaining amount allowed today */
|
|
32
|
+
remainingDaily: number;
|
|
33
|
+
/** Human-readable message */
|
|
34
|
+
message?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Interface for the spend tracker
|
|
38
|
+
*/
|
|
39
|
+
export interface ISpendTracker {
|
|
40
|
+
/** Record a transaction (after approval) */
|
|
41
|
+
record(amount: number, metadata?: {
|
|
42
|
+
transactionId?: string;
|
|
43
|
+
domain?: string;
|
|
44
|
+
}): void;
|
|
45
|
+
/** Check if a transaction would exceed limits */
|
|
46
|
+
checkLimits(amount: number, limits: SpendLimits): SpendLimitResult;
|
|
47
|
+
/** Get current daily total */
|
|
48
|
+
getDailyTotal(): number;
|
|
49
|
+
/** Get recent transactions */
|
|
50
|
+
getTransactions(since?: number): SpendRecord[];
|
|
51
|
+
/** Reset (for testing) */
|
|
52
|
+
reset(): void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Extract amount from a string value
|
|
56
|
+
* @param value String that may contain an amount
|
|
57
|
+
* @returns Parsed amount or null if not found
|
|
58
|
+
*/
|
|
59
|
+
export declare function extractAmount(value: string): number | null;
|
|
60
|
+
/**
|
|
61
|
+
* Extract amount from tool input
|
|
62
|
+
* Searches common field names for price/amount values
|
|
63
|
+
* @param toolInput Tool input object
|
|
64
|
+
* @returns Extracted amount or null
|
|
65
|
+
*/
|
|
66
|
+
export declare function extractAmountFromInput(toolInput: Record<string, unknown>): number | null;
|
|
67
|
+
/**
|
|
68
|
+
* SpendTracker implementation
|
|
69
|
+
* Tracks spending transactions and enforces limits
|
|
70
|
+
*/
|
|
71
|
+
export declare class SpendTracker implements ISpendTracker {
|
|
72
|
+
private transactions;
|
|
73
|
+
private readonly cleanupIntervalMs;
|
|
74
|
+
private lastCleanup;
|
|
75
|
+
/**
|
|
76
|
+
* Create a new SpendTracker
|
|
77
|
+
* @param cleanupIntervalMs How often to run cleanup (default: 1 hour)
|
|
78
|
+
*/
|
|
79
|
+
constructor(cleanupIntervalMs?: number);
|
|
80
|
+
/**
|
|
81
|
+
* Record a transaction
|
|
82
|
+
* @param amount Transaction amount
|
|
83
|
+
* @param metadata Optional metadata (transactionId, domain)
|
|
84
|
+
*/
|
|
85
|
+
record(amount: number, metadata?: {
|
|
86
|
+
transactionId?: string;
|
|
87
|
+
domain?: string;
|
|
88
|
+
}): void;
|
|
89
|
+
/**
|
|
90
|
+
* Check if a transaction would exceed limits
|
|
91
|
+
* @param amount Transaction amount
|
|
92
|
+
* @param limits Spend limits to check against
|
|
93
|
+
* @returns Result indicating if allowed and any exceeded limits
|
|
94
|
+
*/
|
|
95
|
+
checkLimits(amount: number, limits: SpendLimits): SpendLimitResult;
|
|
96
|
+
/**
|
|
97
|
+
* Get total amount spent today
|
|
98
|
+
* @returns Sum of today's approved transactions
|
|
99
|
+
*/
|
|
100
|
+
getDailyTotal(): number;
|
|
101
|
+
/**
|
|
102
|
+
* Get transactions since a given timestamp
|
|
103
|
+
* @param since Unix timestamp (default: start of today)
|
|
104
|
+
* @returns Array of transactions since the given time
|
|
105
|
+
*/
|
|
106
|
+
getTransactions(since?: number): SpendRecord[];
|
|
107
|
+
/**
|
|
108
|
+
* Reset all tracked transactions (for testing)
|
|
109
|
+
*/
|
|
110
|
+
reset(): void;
|
|
111
|
+
/**
|
|
112
|
+
* Run cleanup if enough time has passed
|
|
113
|
+
*/
|
|
114
|
+
private maybeCleanup;
|
|
115
|
+
/**
|
|
116
|
+
* Remove transactions older than 24 hours
|
|
117
|
+
*/
|
|
118
|
+
private cleanup;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Create a new SpendTracker instance
|
|
122
|
+
*/
|
|
123
|
+
export declare function createSpendTracker(): SpendTracker;
|
|
124
|
+
/**
|
|
125
|
+
* Get the global spend tracker instance
|
|
126
|
+
*/
|
|
127
|
+
export declare function getGlobalSpendTracker(): SpendTracker;
|
|
128
|
+
/**
|
|
129
|
+
* Reset the global spend tracker (for testing)
|
|
130
|
+
*/
|
|
131
|
+
export declare function resetGlobalSpendTracker(): void;
|
|
132
|
+
//# sourceMappingURL=spend-tracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spend-tracker.d.ts","sourceRoot":"","sources":["../../../../src/detectors/purchase/spend-tracker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,SAAS,EAAE,MAAM,CAAC;IAClB,4CAA4C;IAC5C,aAAa,EAAE,MAAM,CAAC;IACtB,4CAA4C;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,yCAAyC;IACzC,OAAO,EAAE,OAAO,CAAC;IACjB,uCAAuC;IACvC,aAAa,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC;IAC3C,gCAAgC;IAChC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qCAAqC;IACrC,cAAc,EAAE,MAAM,CAAC;IACvB,6BAA6B;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,4CAA4C;IAC5C,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACrF,iDAAiD;IACjD,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,gBAAgB,CAAC;IACnE,8BAA8B;IAC9B,aAAa,IAAI,MAAM,CAAC;IACxB,8BAA8B;IAC9B,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,WAAW,EAAE,CAAC;IAC/C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
|
|
5
|
+
/**
|
|
6
|
+
* Amount patterns for detecting prices in text
|
|
7
|
+
*/
|
|
8
|
+
const AMOUNT_PATTERNS = [
|
|
9
|
+
// Currency with dollar sign: $100, $100.00, $1,000.00
|
|
10
|
+
/\$\s*([0-9]{1,3}(?:,?[0-9]{3})*(?:\.[0-9]{2})?)/,
|
|
11
|
+
// Currency with other symbols: €100, £100, ¥1000 (handle large numbers for yen)
|
|
12
|
+
/[€£¥]\s*([0-9]+(?:,?[0-9]{3})*(?:\.[0-9]{2})?)/,
|
|
13
|
+
// Labeled amounts: amount=100, price=99.99, total=50
|
|
14
|
+
/(?:amount|price|total|cost|value)\s*[=:]\s*([0-9]{1,3}(?:,?[0-9]{3})*(?:\.[0-9]{2})?)/i,
|
|
15
|
+
// USD/EUR labeled: 100 USD, 99.99 EUR
|
|
16
|
+
/([0-9]{1,3}(?:,?[0-9]{3})*(?:\.[0-9]{2})?)\s*(?:USD|EUR|GBP|CAD|AUD)/i,
|
|
17
|
+
// Plain decimal numbers (lower confidence): 99.99
|
|
18
|
+
/^([0-9]{1,6}\.[0-9]{2})$/,
|
|
19
|
+
];
|
|
20
|
+
/**
|
|
21
|
+
* Extract amount from a string value
|
|
22
|
+
* @param value String that may contain an amount
|
|
23
|
+
* @returns Parsed amount or null if not found
|
|
24
|
+
*/
|
|
25
|
+
export function extractAmount(value) {
|
|
26
|
+
if (!value || typeof value !== 'string') {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const cleanValue = value.trim();
|
|
30
|
+
for (const pattern of AMOUNT_PATTERNS) {
|
|
31
|
+
const match = cleanValue.match(pattern);
|
|
32
|
+
if (match && match[1]) {
|
|
33
|
+
// Remove commas and parse
|
|
34
|
+
const numStr = match[1].replace(/,/g, '');
|
|
35
|
+
const num = parseFloat(numStr);
|
|
36
|
+
if (!isNaN(num) && num > 0) {
|
|
37
|
+
return num;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Try direct parse if it looks like a number
|
|
42
|
+
if (/^[0-9]+(?:\.[0-9]+)?$/.test(cleanValue)) {
|
|
43
|
+
const num = parseFloat(cleanValue);
|
|
44
|
+
if (!isNaN(num) && num > 0) {
|
|
45
|
+
return num;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Extract amount from tool input
|
|
52
|
+
* Searches common field names for price/amount values
|
|
53
|
+
* @param toolInput Tool input object
|
|
54
|
+
* @returns Extracted amount or null
|
|
55
|
+
*/
|
|
56
|
+
export function extractAmountFromInput(toolInput) {
|
|
57
|
+
// Priority field names to check
|
|
58
|
+
const amountFields = [
|
|
59
|
+
'amount',
|
|
60
|
+
'price',
|
|
61
|
+
'total',
|
|
62
|
+
'cost',
|
|
63
|
+
'value',
|
|
64
|
+
'payment_amount',
|
|
65
|
+
'paymentAmount',
|
|
66
|
+
'transaction_amount',
|
|
67
|
+
'transactionAmount',
|
|
68
|
+
'subtotal',
|
|
69
|
+
'grand_total',
|
|
70
|
+
'grandTotal',
|
|
71
|
+
];
|
|
72
|
+
// Check priority fields first
|
|
73
|
+
for (const field of amountFields) {
|
|
74
|
+
const value = toolInput[field];
|
|
75
|
+
if (value !== undefined && value !== null) {
|
|
76
|
+
if (typeof value === 'number' && value > 0) {
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
if (typeof value === 'string') {
|
|
80
|
+
const parsed = extractAmount(value);
|
|
81
|
+
if (parsed !== null) {
|
|
82
|
+
return parsed;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Check URL query parameters
|
|
88
|
+
const url = toolInput.url;
|
|
89
|
+
if (typeof url === 'string') {
|
|
90
|
+
try {
|
|
91
|
+
const urlObj = new URL(url.startsWith('http') ? url : `https://${url}`);
|
|
92
|
+
for (const field of amountFields) {
|
|
93
|
+
const param = urlObj.searchParams.get(field);
|
|
94
|
+
if (param) {
|
|
95
|
+
const parsed = extractAmount(param);
|
|
96
|
+
if (parsed !== null) {
|
|
97
|
+
return parsed;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// Invalid URL, ignore
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Check nested form data
|
|
107
|
+
const formData = toolInput.data || toolInput.body || toolInput.formData;
|
|
108
|
+
if (formData && typeof formData === 'object') {
|
|
109
|
+
const result = extractAmountFromInput(formData);
|
|
110
|
+
if (result !== null) {
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Check fields array (Playwright form fields)
|
|
115
|
+
const fields = toolInput.fields;
|
|
116
|
+
if (Array.isArray(fields)) {
|
|
117
|
+
for (const field of fields) {
|
|
118
|
+
if (field && typeof field === 'object') {
|
|
119
|
+
const name = field.name;
|
|
120
|
+
const value = field.value;
|
|
121
|
+
if (typeof name === 'string' && amountFields.includes(name.toLowerCase())) {
|
|
122
|
+
if (typeof value === 'number' && value > 0) {
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
if (typeof value === 'string') {
|
|
126
|
+
const parsed = extractAmount(value);
|
|
127
|
+
if (parsed !== null) {
|
|
128
|
+
return parsed;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// Scan all string values in the input for currency patterns (last resort)
|
|
136
|
+
for (const [key, value] of Object.entries(toolInput)) {
|
|
137
|
+
// Skip non-string values and known non-amount fields
|
|
138
|
+
if (typeof value !== 'string')
|
|
139
|
+
continue;
|
|
140
|
+
if (['url', 'path', 'href', 'selector', 'ref', 'element'].includes(key))
|
|
141
|
+
continue;
|
|
142
|
+
// Look for explicit currency patterns only
|
|
143
|
+
const currencyMatch = value.match(/\$\s*([0-9]{1,3}(?:,?[0-9]{3})*(?:\.[0-9]{2})?)/);
|
|
144
|
+
if (currencyMatch && currencyMatch[1]) {
|
|
145
|
+
const parsed = extractAmount(value);
|
|
146
|
+
if (parsed !== null) {
|
|
147
|
+
return parsed;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Generate a unique transaction ID
|
|
155
|
+
*/
|
|
156
|
+
function generateTransactionId() {
|
|
157
|
+
const timestamp = Date.now().toString(36);
|
|
158
|
+
const random = Math.random().toString(36).substring(2, 8);
|
|
159
|
+
return `txn_${timestamp}_${random}`;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get the start of today (midnight in local timezone)
|
|
163
|
+
*/
|
|
164
|
+
function getStartOfDay(timestamp = Date.now()) {
|
|
165
|
+
const date = new Date(timestamp);
|
|
166
|
+
date.setHours(0, 0, 0, 0);
|
|
167
|
+
return date.getTime();
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* SpendTracker implementation
|
|
171
|
+
* Tracks spending transactions and enforces limits
|
|
172
|
+
*/
|
|
173
|
+
export class SpendTracker {
|
|
174
|
+
transactions = [];
|
|
175
|
+
cleanupIntervalMs;
|
|
176
|
+
lastCleanup = Date.now();
|
|
177
|
+
/**
|
|
178
|
+
* Create a new SpendTracker
|
|
179
|
+
* @param cleanupIntervalMs How often to run cleanup (default: 1 hour)
|
|
180
|
+
*/
|
|
181
|
+
constructor(cleanupIntervalMs = 60 * 60 * 1000) {
|
|
182
|
+
this.cleanupIntervalMs = cleanupIntervalMs;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Record a transaction
|
|
186
|
+
* @param amount Transaction amount
|
|
187
|
+
* @param metadata Optional metadata (transactionId, domain)
|
|
188
|
+
*/
|
|
189
|
+
record(amount, metadata) {
|
|
190
|
+
// Run cleanup if needed
|
|
191
|
+
this.maybeCleanup();
|
|
192
|
+
const record = {
|
|
193
|
+
amount,
|
|
194
|
+
timestamp: Date.now(),
|
|
195
|
+
transactionId: metadata?.transactionId || generateTransactionId(),
|
|
196
|
+
domain: metadata?.domain,
|
|
197
|
+
approved: true,
|
|
198
|
+
};
|
|
199
|
+
this.transactions.push(record);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Check if a transaction would exceed limits
|
|
203
|
+
* @param amount Transaction amount
|
|
204
|
+
* @param limits Spend limits to check against
|
|
205
|
+
* @returns Result indicating if allowed and any exceeded limits
|
|
206
|
+
*/
|
|
207
|
+
checkLimits(amount, limits) {
|
|
208
|
+
// Run cleanup if needed
|
|
209
|
+
this.maybeCleanup();
|
|
210
|
+
const dailyTotal = this.getDailyTotal();
|
|
211
|
+
const remainingDaily = Math.max(0, limits.daily - dailyTotal);
|
|
212
|
+
// Check per-transaction limit first
|
|
213
|
+
if (amount > limits.perTransaction) {
|
|
214
|
+
return {
|
|
215
|
+
allowed: false,
|
|
216
|
+
exceededLimit: 'perTransaction',
|
|
217
|
+
currentDailyTotal: dailyTotal,
|
|
218
|
+
remainingDaily,
|
|
219
|
+
message: `Transaction amount $${amount.toFixed(2)} exceeds per-transaction limit of $${limits.perTransaction.toFixed(2)}`,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
// Check if adding this amount would exceed daily limit
|
|
223
|
+
if (dailyTotal + amount > limits.daily) {
|
|
224
|
+
return {
|
|
225
|
+
allowed: false,
|
|
226
|
+
exceededLimit: 'daily',
|
|
227
|
+
currentDailyTotal: dailyTotal,
|
|
228
|
+
remainingDaily,
|
|
229
|
+
message: `Transaction amount $${amount.toFixed(2)} would exceed daily limit of $${limits.daily.toFixed(2)} (current total: $${dailyTotal.toFixed(2)})`,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
// Transaction is allowed
|
|
233
|
+
return {
|
|
234
|
+
allowed: true,
|
|
235
|
+
currentDailyTotal: dailyTotal,
|
|
236
|
+
remainingDaily: remainingDaily - amount,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Get total amount spent today
|
|
241
|
+
* @returns Sum of today's approved transactions
|
|
242
|
+
*/
|
|
243
|
+
getDailyTotal() {
|
|
244
|
+
const startOfDay = getStartOfDay();
|
|
245
|
+
return this.transactions
|
|
246
|
+
.filter((t) => t.timestamp >= startOfDay && t.approved)
|
|
247
|
+
.reduce((sum, t) => sum + t.amount, 0);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Get transactions since a given timestamp
|
|
251
|
+
* @param since Unix timestamp (default: start of today)
|
|
252
|
+
* @returns Array of transactions since the given time
|
|
253
|
+
*/
|
|
254
|
+
getTransactions(since) {
|
|
255
|
+
const cutoff = since ?? getStartOfDay();
|
|
256
|
+
return this.transactions
|
|
257
|
+
.filter((t) => t.timestamp >= cutoff)
|
|
258
|
+
.sort((a, b) => b.timestamp - a.timestamp);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Reset all tracked transactions (for testing)
|
|
262
|
+
*/
|
|
263
|
+
reset() {
|
|
264
|
+
this.transactions = [];
|
|
265
|
+
this.lastCleanup = Date.now();
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Run cleanup if enough time has passed
|
|
269
|
+
*/
|
|
270
|
+
maybeCleanup() {
|
|
271
|
+
const now = Date.now();
|
|
272
|
+
if (now - this.lastCleanup >= this.cleanupIntervalMs) {
|
|
273
|
+
this.cleanup();
|
|
274
|
+
this.lastCleanup = now;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Remove transactions older than 24 hours
|
|
279
|
+
*/
|
|
280
|
+
cleanup() {
|
|
281
|
+
const cutoff = Date.now() - 24 * 60 * 60 * 1000;
|
|
282
|
+
this.transactions = this.transactions.filter((t) => t.timestamp >= cutoff);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Create a new SpendTracker instance
|
|
287
|
+
*/
|
|
288
|
+
export function createSpendTracker() {
|
|
289
|
+
return new SpendTracker();
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Singleton instance for the global spend tracker
|
|
293
|
+
*/
|
|
294
|
+
let globalSpendTracker = null;
|
|
295
|
+
/**
|
|
296
|
+
* Get the global spend tracker instance
|
|
297
|
+
*/
|
|
298
|
+
export function getGlobalSpendTracker() {
|
|
299
|
+
if (!globalSpendTracker) {
|
|
300
|
+
globalSpendTracker = new SpendTracker();
|
|
301
|
+
}
|
|
302
|
+
return globalSpendTracker;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Reset the global spend tracker (for testing)
|
|
306
|
+
*/
|
|
307
|
+
export function resetGlobalSpendTracker() {
|
|
308
|
+
if (globalSpendTracker) {
|
|
309
|
+
globalSpendTracker.reset();
|
|
310
|
+
}
|
|
311
|
+
globalSpendTracker = null;
|
|
312
|
+
}
|
|
313
|
+
//# sourceMappingURL=spend-tracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spend-tracker.js","sourceRoot":"","sources":["../../../../src/detectors/purchase/spend-tracker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoDH;;GAEG;AACH,MAAM,eAAe,GAAG;IACtB,sDAAsD;IACtD,iDAAiD;IACjD,gFAAgF;IAChF,gDAAgD;IAChD,qDAAqD;IACrD,wFAAwF;IACxF,sCAAsC;IACtC,uEAAuE;IACvE,kDAAkD;IAClD,0BAA0B;CAC3B,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAEhC,KAAK,MAAM,OAAO,IAAI,eAAe,EAAE,CAAC;QACtC,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC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GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,IAAI,MAAM,CAAC,CAAC;IAC7E,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,IAAI,YAAY,EAAE,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,IAAI,kBAAkB,GAAwB,IAAI,CAAC;AAEnD;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACnC,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACxB,kBAAkB,GAAG,IAAI,YAAY,EAAE,CAAC;IAC1C,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB;IACrC,IAAI,kBAAkB,EAAE,CAAC;QACvB,kBAAkB,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IACD,kBAAkB,GAAG,IAAI,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Purchase Detector Types
|
|
3
|
+
* Type definitions for the purchase/transaction detection system
|
|
4
|
+
*/
|
|
5
|
+
import type { Severity, Action } from '../../config/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Detection context passed to detectors
|
|
8
|
+
*/
|
|
9
|
+
export interface DetectionContext {
|
|
10
|
+
/** Name of the tool being invoked */
|
|
11
|
+
toolName: string;
|
|
12
|
+
/** Input parameters to the tool */
|
|
13
|
+
toolInput: Record<string, unknown>;
|
|
14
|
+
/** URL being accessed (for browser/navigation tools) */
|
|
15
|
+
url?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Result of a detection operation
|
|
19
|
+
*/
|
|
20
|
+
export interface DetectionResult {
|
|
21
|
+
/** Whether a purchase/transaction was detected */
|
|
22
|
+
detected: boolean;
|
|
23
|
+
/** Category of the detection */
|
|
24
|
+
category: 'purchase';
|
|
25
|
+
/** Severity level of the detection */
|
|
26
|
+
severity: Severity;
|
|
27
|
+
/** Confidence score from 0 to 1 */
|
|
28
|
+
confidence: number;
|
|
29
|
+
/** Human-readable reason for the detection */
|
|
30
|
+
reason: string;
|
|
31
|
+
/** Additional metadata about the detection */
|
|
32
|
+
metadata?: {
|
|
33
|
+
/** Domain that triggered the detection */
|
|
34
|
+
domain?: string;
|
|
35
|
+
/** URL that triggered the detection */
|
|
36
|
+
url?: string;
|
|
37
|
+
/** Form fields that triggered the detection */
|
|
38
|
+
formFields?: string[];
|
|
39
|
+
/** Pattern that matched */
|
|
40
|
+
matchedPattern?: string;
|
|
41
|
+
/** Detected amount from the transaction */
|
|
42
|
+
amount?: number;
|
|
43
|
+
/** Spend limit that was exceeded */
|
|
44
|
+
exceededLimit?: 'perTransaction' | 'daily';
|
|
45
|
+
/** Current daily total at time of detection */
|
|
46
|
+
currentDailyTotal?: number;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Configuration for the purchase detector
|
|
51
|
+
*/
|
|
52
|
+
export interface PurchaseDetectorConfig {
|
|
53
|
+
/** Whether the detector is enabled */
|
|
54
|
+
enabled: boolean;
|
|
55
|
+
/** Severity level to assign to detections */
|
|
56
|
+
severity: Severity;
|
|
57
|
+
/** Action to take when purchase is detected */
|
|
58
|
+
action: Action;
|
|
59
|
+
/** Domain configuration */
|
|
60
|
+
domains?: {
|
|
61
|
+
/** Mode for domain filtering */
|
|
62
|
+
mode: 'blocklist' | 'allowlist';
|
|
63
|
+
/** Domains to block */
|
|
64
|
+
blocklist: string[];
|
|
65
|
+
};
|
|
66
|
+
/** Spending limits configuration */
|
|
67
|
+
spendLimits?: {
|
|
68
|
+
/** Maximum amount per transaction */
|
|
69
|
+
perTransaction: number;
|
|
70
|
+
/** Maximum daily spending amount */
|
|
71
|
+
daily: number;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Interface for the main purchase detector
|
|
76
|
+
*/
|
|
77
|
+
export interface PurchaseDetector {
|
|
78
|
+
/**
|
|
79
|
+
* Detect purchase/transaction attempts
|
|
80
|
+
* @param context Detection context with tool information
|
|
81
|
+
* @returns Detection result
|
|
82
|
+
*/
|
|
83
|
+
detect(context: DetectionContext): Promise<DetectionResult>;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Interface for sub-detectors (domain, URL, form)
|
|
87
|
+
*/
|
|
88
|
+
export interface SubDetector {
|
|
89
|
+
/**
|
|
90
|
+
* Check if the given context matches this detector's patterns
|
|
91
|
+
* @param context Detection context
|
|
92
|
+
* @returns Detection result or null if no match
|
|
93
|
+
*/
|
|
94
|
+
detect(context: DetectionContext): DetectionResult | null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Domain match result with confidence
|
|
98
|
+
*/
|
|
99
|
+
export interface DomainMatchResult {
|
|
100
|
+
/** Whether a match was found */
|
|
101
|
+
matched: boolean;
|
|
102
|
+
/** The domain that matched */
|
|
103
|
+
domain?: string;
|
|
104
|
+
/** The pattern that matched */
|
|
105
|
+
pattern?: string;
|
|
106
|
+
/** Match type */
|
|
107
|
+
matchType?: 'exact' | 'glob' | 'keyword';
|
|
108
|
+
/** Confidence score */
|
|
109
|
+
confidence: number;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* URL match result with confidence
|
|
113
|
+
*/
|
|
114
|
+
export interface UrlMatchResult {
|
|
115
|
+
/** Whether a match was found */
|
|
116
|
+
matched: boolean;
|
|
117
|
+
/** The URL that matched */
|
|
118
|
+
url?: string;
|
|
119
|
+
/** The pattern that matched */
|
|
120
|
+
pattern?: string;
|
|
121
|
+
/** Match type */
|
|
122
|
+
matchType?: 'path' | 'api';
|
|
123
|
+
/** Confidence score */
|
|
124
|
+
confidence: number;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Form field match result
|
|
128
|
+
*/
|
|
129
|
+
export interface FormFieldMatchResult {
|
|
130
|
+
/** Whether a match was found */
|
|
131
|
+
matched: boolean;
|
|
132
|
+
/** Fields that matched */
|
|
133
|
+
fields?: string[];
|
|
134
|
+
/** Patterns that matched */
|
|
135
|
+
patterns?: string[];
|
|
136
|
+
/** Confidence score */
|
|
137
|
+
confidence: number;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/detectors/purchase/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,qCAAqC;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,wDAAwD;IACxD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,kDAAkD;IAClD,QAAQ,EAAE,OAAO,CAAC;IAClB,gCAAgC;IAChC,QAAQ,EAAE,UAAU,CAAC;IACrB,sCAAsC;IACtC,QAAQ,EAAE,QAAQ,CAAC;IACnB,mCAAmC;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,QAAQ,CAAC,EAAE;QACT,0CAA0C;QAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,uCAAuC;QACvC,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,+CAA+C;QAC/C,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;QACtB,2BAA2B;QAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,2CAA2C;QAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,oCAAoC;QACpC,aAAa,CAAC,EAAE,gBAAgB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;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iBAAiB;IACjB,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC3B,uBAAuB;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,gCAAgC;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,0BAA0B;IAC1B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,4BAA4B;IAC5B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,uBAAuB;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/detectors/purchase/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL Pattern Detector
|
|
3
|
+
* Detects purchase-related URL paths and API endpoints
|
|
4
|
+
*/
|
|
5
|
+
import type { UrlMatchResult, DetectionContext, DetectionResult, SubDetector } from './types.js';
|
|
6
|
+
import type { Severity } from '../../config/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* Extract path from URL
|
|
9
|
+
*/
|
|
10
|
+
export declare function extractPath(url: string): string | null;
|
|
11
|
+
/**
|
|
12
|
+
* Check URL path against known payment paths
|
|
13
|
+
*/
|
|
14
|
+
export declare function matchUrlPath(url: string): UrlMatchResult;
|
|
15
|
+
/**
|
|
16
|
+
* URL pattern detector class
|
|
17
|
+
*/
|
|
18
|
+
export declare class UrlDetector implements SubDetector {
|
|
19
|
+
private severity;
|
|
20
|
+
constructor(severity?: Severity);
|
|
21
|
+
/**
|
|
22
|
+
* Extract URL from tool context
|
|
23
|
+
*/
|
|
24
|
+
private extractUrl;
|
|
25
|
+
detect(context: DetectionContext): DetectionResult | null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create a URL detector with the given configuration
|
|
29
|
+
*/
|
|
30
|
+
export declare function createUrlDetector(severity?: Severity): UrlDetector;
|
|
31
|
+
//# sourceMappingURL=url-detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url-detector.d.ts","sourceRoot":"","sources":["../../../../src/detectors/purchase/url-detector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACjG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AA0HtD;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAuBtD;AAUD;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CA6ExD;AAED;;GAEG;AACH,qBAAa,WAAY,YAAW,WAAW;IAC7C,OAAO,CAAC,QAAQ,CAAW;gBAEf,QAAQ,GAAE,QAAqB;IAI3C;;OAEG;IACH,OAAO,CAAC,UAAU;IAiClB,MAAM,CAAC,OAAO,EAAE,gBAAgB,GAAG,eAAe,GAAG,IAAI;CA4B1D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,GAAE,QAAqB,GAAG,WAAW,CAE9E"}
|