trustbase-seller-backend 0.1.5
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/.agents/skills/wechatpay-payment-integration/SKILL.md +165 -0
- package/.agents/skills/wechatpay-payment-integration/references/APIv3/346/216/245/345/217/243/345/212/250/346/200/201/346/216/222/351/232/234.md +234 -0
- package/.agents/skills/wechatpay-payment-integration/references/wechatpay-dev-cli/344/275/277/347/224/250/350/257/264/346/230/216.md +74 -0
- package/.agents/skills/wechatpay-payment-integration/references//345/237/272/347/241/200/346/246/202/345/277/265/345/217/212/344/270/232/345/212/241/344/273/213/347/273/215.md +109 -0
- package/.agents/skills/wechatpay-payment-integration/references//345/246/202/344/275/225/347/220/206/350/247/243/347/224/250/346/210/267/351/227/256/351/242/230.md +55 -0
- package/.agents/skills/wechatpay-payment-integration/references//346/216/245/345/205/245/350/264/250/351/207/217/346/243/200/346/237/245/346/270/205/345/215/225.md +70 -0
- package/.agents/skills/wechatpay-payment-integration/references//346/226/207/346/241/243/346/243/200/347/264/242/344/270/216/351/227/256/347/255/224.md +99 -0
- package/.agents/skills/wechatpay-payment-integration/scripts/bash/extract_and_sign.sh +231 -0
- package/.agents/skills/wechatpay-payment-integration/scripts/powershell/extract_and_sign.ps1 +199 -0
- package/.agents/skills/wechatpay-payment-integration/scripts/wechatpay-resource-sync.py +646 -0
- package/.env.example +70 -0
- package/MERCHANT-EDITION.md +56 -0
- package/README.md +99 -0
- package/api/__tests__/test-utils.d.ts +33 -0
- package/api/__tests__/test-utils.d.ts.map +1 -0
- package/api/__tests__/test-utils.js +90 -0
- package/api/__tests__/test-utils.js.map +1 -0
- package/api/db/case-library-types.d.ts +47 -0
- package/api/db/case-library-types.d.ts.map +1 -0
- package/api/db/case-library-types.js +105 -0
- package/api/db/case-library-types.js.map +1 -0
- package/api/db/case-library.db.d.ts +5 -0
- package/api/db/case-library.db.d.ts.map +1 -0
- package/api/db/case-library.db.js +127 -0
- package/api/db/case-library.db.js.map +1 -0
- package/api/email.d.ts +56 -0
- package/api/email.d.ts.map +1 -0
- package/api/email.js +307 -0
- package/api/email.js.map +1 -0
- package/api/index.d.ts +22 -0
- package/api/index.d.ts.map +1 -0
- package/api/index.js +41 -0
- package/api/index.js.map +1 -0
- package/api/integration-helpers.d.ts +153 -0
- package/api/integration-helpers.d.ts.map +1 -0
- package/api/integration-helpers.js +361 -0
- package/api/integration-helpers.js.map +1 -0
- package/api/lib/case-summary.d.ts +10 -0
- package/api/lib/case-summary.d.ts.map +1 -0
- package/api/lib/case-summary.js +30 -0
- package/api/lib/case-summary.js.map +1 -0
- package/api/middleware/p2p-auth.d.ts +140 -0
- package/api/middleware/p2p-auth.d.ts.map +1 -0
- package/api/middleware/p2p-auth.js +510 -0
- package/api/middleware/p2p-auth.js.map +1 -0
- package/api/middleware/tool-policy.d.ts +47 -0
- package/api/middleware/tool-policy.d.ts.map +1 -0
- package/api/middleware/tool-policy.js +156 -0
- package/api/middleware/tool-policy.js.map +1 -0
- package/api/oauth-adapters.d.ts +192 -0
- package/api/oauth-adapters.d.ts.map +1 -0
- package/api/oauth-adapters.js +456 -0
- package/api/oauth-adapters.js.map +1 -0
- package/api/oauth-bridge.d.ts +56 -0
- package/api/oauth-bridge.d.ts.map +1 -0
- package/api/oauth-bridge.js +624 -0
- package/api/oauth-bridge.js.map +1 -0
- package/api/oauth-router.d.ts +36 -0
- package/api/oauth-router.d.ts.map +1 -0
- package/api/oauth-router.js +54 -0
- package/api/oauth-router.js.map +1 -0
- package/api/p2p-mcp.d.ts +69 -0
- package/api/p2p-mcp.d.ts.map +1 -0
- package/api/p2p-mcp.js +286 -0
- package/api/p2p-mcp.js.map +1 -0
- package/api/payment-store.d.ts +56 -0
- package/api/payment-store.d.ts.map +1 -0
- package/api/payment-store.js +163 -0
- package/api/payment-store.js.map +1 -0
- package/api/payment.d.ts +14 -0
- package/api/payment.d.ts.map +1 -0
- package/api/payment.js +216 -0
- package/api/payment.js.map +1 -0
- package/api/pwa-stats.d.ts +67 -0
- package/api/pwa-stats.d.ts.map +1 -0
- package/api/pwa-stats.js +269 -0
- package/api/pwa-stats.js.map +1 -0
- package/api/riskcontrol-adapters.d.ts +114 -0
- package/api/riskcontrol-adapters.d.ts.map +1 -0
- package/api/riskcontrol-adapters.js +210 -0
- package/api/riskcontrol-adapters.js.map +1 -0
- package/api/riskcontrol-event-whitelist.d.ts +81 -0
- package/api/riskcontrol-event-whitelist.d.ts.map +1 -0
- package/api/riskcontrol-event-whitelist.js +181 -0
- package/api/riskcontrol-event-whitelist.js.map +1 -0
- package/api/riskcontrol-rules.d.ts +105 -0
- package/api/riskcontrol-rules.d.ts.map +1 -0
- package/api/riskcontrol-rules.js +399 -0
- package/api/riskcontrol-rules.js.map +1 -0
- package/api/riskcontrol-scoring.d.ts +72 -0
- package/api/riskcontrol-scoring.d.ts.map +1 -0
- package/api/riskcontrol-scoring.js +335 -0
- package/api/riskcontrol-scoring.js.map +1 -0
- package/api/riskcontrol-service.d.ts +60 -0
- package/api/riskcontrol-service.d.ts.map +1 -0
- package/api/riskcontrol-service.js +206 -0
- package/api/riskcontrol-service.js.map +1 -0
- package/api/riskcontrol-stream.d.ts +112 -0
- package/api/riskcontrol-stream.d.ts.map +1 -0
- package/api/riskcontrol-stream.js +230 -0
- package/api/riskcontrol-stream.js.map +1 -0
- package/api/riskcontrol-v5-e2e-test.d.ts +15 -0
- package/api/riskcontrol-v5-e2e-test.d.ts.map +1 -0
- package/api/riskcontrol-v5-e2e-test.js +204 -0
- package/api/riskcontrol-v5-e2e-test.js.map +1 -0
- package/api/riskcontrol-v5-router.d.ts +48 -0
- package/api/riskcontrol-v5-router.d.ts.map +1 -0
- package/api/riskcontrol-v5-router.js +226 -0
- package/api/riskcontrol-v5-router.js.map +1 -0
- package/api/riskcontrol-webhook.d.ts +88 -0
- package/api/riskcontrol-webhook.d.ts.map +1 -0
- package/api/riskcontrol-webhook.js +326 -0
- package/api/riskcontrol-webhook.js.map +1 -0
- package/api/routes/case-library.d.ts +4 -0
- package/api/routes/case-library.d.ts.map +1 -0
- package/api/routes/case-library.js +91 -0
- package/api/routes/case-library.js.map +1 -0
- package/api/seller-earnings.d.ts +23 -0
- package/api/seller-earnings.d.ts.map +1 -0
- package/api/seller-earnings.js +258 -0
- package/api/seller-earnings.js.map +1 -0
- package/api/seller-orders.d.ts +25 -0
- package/api/seller-orders.d.ts.map +1 -0
- package/api/seller-orders.js +398 -0
- package/api/seller-orders.js.map +1 -0
- package/api/seller-products-chain.d.ts +31 -0
- package/api/seller-products-chain.d.ts.map +1 -0
- package/api/seller-products-chain.js +308 -0
- package/api/seller-products-chain.js.map +1 -0
- package/api/seller-products.d.ts +30 -0
- package/api/seller-products.d.ts.map +1 -0
- package/api/seller-products.js +453 -0
- package/api/seller-products.js.map +1 -0
- package/api/seller-reputation.d.ts +21 -0
- package/api/seller-reputation.d.ts.map +1 -0
- package/api/seller-reputation.js +204 -0
- package/api/seller-reputation.js.map +1 -0
- package/api/seller-router.d.ts +33 -0
- package/api/seller-router.d.ts.map +1 -0
- package/api/seller-router.js +53 -0
- package/api/seller-router.js.map +1 -0
- package/api/seller-settings.d.ts +23 -0
- package/api/seller-settings.d.ts.map +1 -0
- package/api/seller-settings.js +279 -0
- package/api/seller-settings.js.map +1 -0
- package/api/shipping-store.d.ts +44 -0
- package/api/shipping-store.d.ts.map +1 -0
- package/api/shipping-store.js +154 -0
- package/api/shipping-store.js.map +1 -0
- package/api/shipping.d.ts +16 -0
- package/api/shipping.d.ts.map +1 -0
- package/api/shipping.js +239 -0
- package/api/shipping.js.map +1 -0
- package/api/social-endpoint-verify.d.ts +8 -0
- package/api/social-endpoint-verify.d.ts.map +1 -0
- package/api/social-endpoint-verify.js +152 -0
- package/api/social-endpoint-verify.js.map +1 -0
- package/api/social-posts.d.ts +65 -0
- package/api/social-posts.d.ts.map +1 -0
- package/api/social-posts.js +534 -0
- package/api/social-posts.js.map +1 -0
- package/api/social-router.d.ts +36 -0
- package/api/social-router.d.ts.map +1 -0
- package/api/social-router.js +56 -0
- package/api/social-router.js.map +1 -0
- package/api/social-shares.d.ts +40 -0
- package/api/social-shares.d.ts.map +1 -0
- package/api/social-shares.js +379 -0
- package/api/social-shares.js.map +1 -0
- package/api/social-whitelist.d.ts +41 -0
- package/api/social-whitelist.d.ts.map +1 -0
- package/api/social-whitelist.js +261 -0
- package/api/social-whitelist.js.map +1 -0
- package/api/storefront-orders.d.ts +23 -0
- package/api/storefront-orders.d.ts.map +1 -0
- package/api/storefront-orders.js +349 -0
- package/api/storefront-orders.js.map +1 -0
- package/api/storefront-products.d.ts +21 -0
- package/api/storefront-products.d.ts.map +1 -0
- package/api/storefront-products.js +181 -0
- package/api/storefront-products.js.map +1 -0
- package/api/storefront-router.d.ts +33 -0
- package/api/storefront-router.d.ts.map +1 -0
- package/api/storefront-router.js +47 -0
- package/api/storefront-router.js.map +1 -0
- package/api/storefront-user.d.ts +23 -0
- package/api/storefront-user.d.ts.map +1 -0
- package/api/storefront-user.js +336 -0
- package/api/storefront-user.js.map +1 -0
- package/api/test-db-helper.d.ts +29 -0
- package/api/test-db-helper.d.ts.map +1 -0
- package/api/test-db-helper.js +107 -0
- package/api/test-db-helper.js.map +1 -0
- package/api/traffic.d.ts +22 -0
- package/api/traffic.d.ts.map +1 -0
- package/api/traffic.js +112 -0
- package/api/traffic.js.map +1 -0
- package/api/wc-credentials.d.ts +34 -0
- package/api/wc-credentials.d.ts.map +1 -0
- package/api/wc-credentials.js +296 -0
- package/api/wc-credentials.js.map +1 -0
- package/api/wc-tracker-receiver.d.ts +47 -0
- package/api/wc-tracker-receiver.d.ts.map +1 -0
- package/api/wc-tracker-receiver.js +264 -0
- package/api/wc-tracker-receiver.js.map +1 -0
- package/api/wc-v3.d.ts +40 -0
- package/api/wc-v3.d.ts.map +1 -0
- package/api/wc-v3.js +694 -0
- package/api/wc-v3.js.map +1 -0
- package/bin/tb-doctor.js +32 -0
- package/bin/tb-seller-backend.js +42 -0
- package/check.d.ts +2 -0
- package/check.d.ts.map +1 -0
- package/check.js +19 -0
- package/check.js.map +1 -0
- package/config/export-import.d.ts +108 -0
- package/config/export-import.d.ts.map +1 -0
- package/config/export-import.js +234 -0
- package/config/export-import.js.map +1 -0
- package/config/manager.d.ts +73 -0
- package/config/manager.d.ts.map +1 -0
- package/config/manager.js +246 -0
- package/config/manager.js.map +1 -0
- package/config/profile.d.ts +42 -0
- package/config/profile.d.ts.map +1 -0
- package/config/profile.js +111 -0
- package/config/profile.js.map +1 -0
- package/core/address.js +23 -0
- package/core/advanced-performance.d.ts +149 -0
- package/core/advanced-performance.d.ts.map +1 -0
- package/core/advanced-performance.js +374 -0
- package/core/advanced-performance.js.map +1 -0
- package/core/alerting.d.ts +91 -0
- package/core/alerting.d.ts.map +1 -0
- package/core/alerting.js +379 -0
- package/core/alerting.js.map +1 -0
- package/core/app-store.d.ts +77 -0
- package/core/app-store.d.ts.map +1 -0
- package/core/app-store.js +207 -0
- package/core/app-store.js.map +1 -0
- package/core/boot-env.js +39 -0
- package/core/business-scope-schema.d.ts +60 -0
- package/core/business-scope-schema.d.ts.map +1 -0
- package/core/business-scope-schema.js +165 -0
- package/core/business-scope-schema.js.map +1 -0
- package/core/cache.d.ts +53 -0
- package/core/cache.d.ts.map +1 -0
- package/core/cache.js +130 -0
- package/core/cache.js.map +1 -0
- package/core/chain-listener.d.ts +47 -0
- package/core/chain-listener.d.ts.map +1 -0
- package/core/chain-listener.js +254 -0
- package/core/chain-listener.js.map +1 -0
- package/core/chain-reject.js +107 -0
- package/core/chain-signer.js +258 -0
- package/core/cleanup.d.ts +42 -0
- package/core/cleanup.d.ts.map +1 -0
- package/core/cleanup.js +144 -0
- package/core/cleanup.js.map +1 -0
- package/core/cluster.d.ts +78 -0
- package/core/cluster.d.ts.map +1 -0
- package/core/cluster.js +215 -0
- package/core/cluster.js.map +1 -0
- package/core/community-review.d.ts +82 -0
- package/core/community-review.d.ts.map +1 -0
- package/core/community-review.js +201 -0
- package/core/community-review.js.map +1 -0
- package/core/connection-pool.d.ts +72 -0
- package/core/connection-pool.d.ts.map +1 -0
- package/core/connection-pool.js +173 -0
- package/core/connection-pool.js.map +1 -0
- package/core/consistency.d.ts +130 -0
- package/core/consistency.d.ts.map +1 -0
- package/core/consistency.js +340 -0
- package/core/consistency.js.map +1 -0
- package/core/content-ai.d.ts +303 -0
- package/core/content-ai.d.ts.map +1 -0
- package/core/content-ai.js +344 -0
- package/core/content-ai.js.map +1 -0
- package/core/content-backfill.d.ts +55 -0
- package/core/content-backfill.d.ts.map +1 -0
- package/core/content-backfill.js +174 -0
- package/core/content-backfill.js.map +1 -0
- package/core/conversion-rate-sync.d.ts +97 -0
- package/core/conversion-rate-sync.d.ts.map +1 -0
- package/core/conversion-rate-sync.js +195 -0
- package/core/conversion-rate-sync.js.map +1 -0
- package/core/coverage-backup.d.ts +87 -0
- package/core/coverage-backup.d.ts.map +1 -0
- package/core/coverage-backup.js +265 -0
- package/core/coverage-backup.js.map +1 -0
- package/core/db-installer.d.ts +108 -0
- package/core/db-installer.d.ts.map +1 -0
- package/core/db-installer.js +414 -0
- package/core/db-installer.js.map +1 -0
- package/core/device-analyzer.d.ts +96 -0
- package/core/device-analyzer.d.ts.map +1 -0
- package/core/device-analyzer.js +235 -0
- package/core/device-analyzer.js.map +1 -0
- package/core/discovery.d.ts +165 -0
- package/core/discovery.d.ts.map +1 -0
- package/core/discovery.js +363 -0
- package/core/discovery.js.map +1 -0
- package/core/distributed.d.ts +172 -0
- package/core/distributed.d.ts.map +1 -0
- package/core/distributed.js +422 -0
- package/core/distributed.js.map +1 -0
- package/core/doctor.js +249 -0
- package/core/enforcement.d.ts +57 -0
- package/core/enforcement.d.ts.map +1 -0
- package/core/enforcement.js +115 -0
- package/core/enforcement.js.map +1 -0
- package/core/error-handler.d.ts +131 -0
- package/core/error-handler.d.ts.map +1 -0
- package/core/error-handler.js +291 -0
- package/core/error-handler.js.map +1 -0
- package/core/federated-learning.d.ts +124 -0
- package/core/federated-learning.d.ts.map +1 -0
- package/core/federated-learning.js +338 -0
- package/core/federated-learning.js.map +1 -0
- package/core/fingerprint.d.ts +95 -0
- package/core/fingerprint.d.ts.map +1 -0
- package/core/fingerprint.js +313 -0
- package/core/fingerprint.js.map +1 -0
- package/core/geoip.d.ts +67 -0
- package/core/geoip.d.ts.map +1 -0
- package/core/geoip.js +174 -0
- package/core/geoip.js.map +1 -0
- package/core/gossip.d.ts +141 -0
- package/core/gossip.d.ts.map +1 -0
- package/core/gossip.js +372 -0
- package/core/gossip.js.map +1 -0
- package/core/governance.d.ts +147 -0
- package/core/governance.d.ts.map +1 -0
- package/core/governance.js +351 -0
- package/core/governance.js.map +1 -0
- package/core/indexer-enhancements.d.ts +164 -0
- package/core/indexer-enhancements.d.ts.map +1 -0
- package/core/indexer-enhancements.js +429 -0
- package/core/indexer-enhancements.js.map +1 -0
- package/core/intrusion-detection.d.ts +79 -0
- package/core/intrusion-detection.d.ts.map +1 -0
- package/core/intrusion-detection.js +322 -0
- package/core/intrusion-detection.js.map +1 -0
- package/core/lifecycle.d.ts +118 -0
- package/core/lifecycle.d.ts.map +1 -0
- package/core/lifecycle.js +310 -0
- package/core/lifecycle.js.map +1 -0
- package/core/location.d.ts +99 -0
- package/core/location.d.ts.map +1 -0
- package/core/location.js +219 -0
- package/core/location.js.map +1 -0
- package/core/maxmind-integration.d.ts +68 -0
- package/core/maxmind-integration.d.ts.map +1 -0
- package/core/maxmind-integration.js +245 -0
- package/core/maxmind-integration.js.map +1 -0
- package/core/migration.d.ts +58 -0
- package/core/migration.d.ts.map +1 -0
- package/core/migration.js +223 -0
- package/core/migration.js.map +1 -0
- package/core/monitoring.d.ts +153 -0
- package/core/monitoring.d.ts.map +1 -0
- package/core/monitoring.js +406 -0
- package/core/monitoring.js.map +1 -0
- package/core/offsite-backup.d.ts +71 -0
- package/core/offsite-backup.d.ts.map +1 -0
- package/core/offsite-backup.js +341 -0
- package/core/offsite-backup.js.map +1 -0
- package/core/order-intent-store.js +83 -0
- package/core/order-intent.js +273 -0
- package/core/paths.js +116 -0
- package/core/performance.d.ts +173 -0
- package/core/performance.d.ts.map +1 -0
- package/core/performance.js +386 -0
- package/core/performance.js.map +1 -0
- package/core/product-flag.d.ts +364 -0
- package/core/product-flag.d.ts.map +1 -0
- package/core/product-flag.js +465 -0
- package/core/product-flag.js.map +1 -0
- package/core/protection.d.ts +139 -0
- package/core/protection.d.ts.map +1 -0
- package/core/protection.js +327 -0
- package/core/protection.js.map +1 -0
- package/core/region-adapter.d.ts +152 -0
- package/core/region-adapter.d.ts.map +1 -0
- package/core/region-adapter.js +505 -0
- package/core/region-adapter.js.map +1 -0
- package/core/region-configs.d.ts +12 -0
- package/core/region-configs.d.ts.map +1 -0
- package/core/region-configs.js +907 -0
- package/core/region-configs.js.map +1 -0
- package/core/review-antifraud.d.ts +80 -0
- package/core/review-antifraud.d.ts.map +1 -0
- package/core/review-antifraud.js +193 -0
- package/core/review-antifraud.js.map +1 -0
- package/core/rules-updater.d.ts +89 -0
- package/core/rules-updater.d.ts.map +1 -0
- package/core/rules-updater.js +261 -0
- package/core/rules-updater.js.map +1 -0
- package/core/runtime-data.js +203 -0
- package/core/security.d.ts +144 -0
- package/core/security.d.ts.map +1 -0
- package/core/security.js +390 -0
- package/core/security.js.map +1 -0
- package/core/seller-identity.js +78 -0
- package/core/session-manager.d.ts +93 -0
- package/core/session-manager.d.ts.map +1 -0
- package/core/session-manager.js +262 -0
- package/core/session-manager.js.map +1 -0
- package/core/state-sync.d.ts +121 -0
- package/core/state-sync.d.ts.map +1 -0
- package/core/state-sync.js +287 -0
- package/core/state-sync.js.map +1 -0
- package/core/testing.d.ts +97 -0
- package/core/testing.d.ts.map +1 -0
- package/core/testing.js +361 -0
- package/core/testing.js.map +1 -0
- package/core/trust-score.d.ts +51 -0
- package/core/trust-score.d.ts.map +1 -0
- package/core/trust-score.js +188 -0
- package/core/trust-score.js.map +1 -0
- package/core/trustworthiness.d.ts +140 -0
- package/core/trustworthiness.d.ts.map +1 -0
- package/core/trustworthiness.js +375 -0
- package/core/trustworthiness.js.map +1 -0
- package/core/types.d.ts +258 -0
- package/core/types.d.ts.map +1 -0
- package/core/types.js +9 -0
- package/core/types.js.map +1 -0
- package/core/upgrade-manager.d.ts +114 -0
- package/core/upgrade-manager.d.ts.map +1 -0
- package/core/upgrade-manager.js +264 -0
- package/core/upgrade-manager.js.map +1 -0
- package/core/upgrader.d.ts +107 -0
- package/core/upgrader.d.ts.map +1 -0
- package/core/upgrader.js +389 -0
- package/core/upgrader.js.map +1 -0
- package/core/websocket.d.ts +78 -0
- package/core/websocket.d.ts.map +1 -0
- package/core/websocket.js +292 -0
- package/core/websocket.js.map +1 -0
- package/council/hidden-weight.d.ts +45 -0
- package/council/hidden-weight.d.ts.map +1 -0
- package/council/hidden-weight.js +135 -0
- package/council/hidden-weight.js.map +1 -0
- package/db/email-migrations.sql +31 -0
- package/db/oauth-migrate.d.ts +39 -0
- package/db/oauth-migrate.d.ts.map +1 -0
- package/db/oauth-migrate.js +201 -0
- package/db/oauth-migrate.js.map +1 -0
- package/db/oauth-migrations.sql +92 -0
- package/db/social-migrate.d.ts +12 -0
- package/db/social-migrate.d.ts.map +1 -0
- package/db/social-migrate.js +102 -0
- package/db/social-migrate.js.map +1 -0
- package/db/social-migrations.sql +94 -0
- package/db/store-migrate.d.ts +33 -0
- package/db/store-migrate.d.ts.map +1 -0
- package/db/store-migrate.js +149 -0
- package/db/store-migrate.js.map +1 -0
- package/db/store-migrations.sql +242 -0
- package/debug.d.ts +2 -0
- package/debug.d.ts.map +1 -0
- package/debug.js +18 -0
- package/debug.js.map +1 -0
- package/event-listener.d.ts +93 -0
- package/event-listener.d.ts.map +1 -0
- package/event-listener.js +321 -0
- package/event-listener.js.map +1 -0
- package/event-whitelist.d.ts +79 -0
- package/event-whitelist.d.ts.map +1 -0
- package/event-whitelist.js +533 -0
- package/event-whitelist.js.map +1 -0
- package/index.d.ts +45 -0
- package/index.d.ts.map +1 -0
- package/index.js +361 -0
- package/index.js.map +1 -0
- package/init-node.d.ts +9 -0
- package/init-node.d.ts.map +1 -0
- package/init-node.js +230 -0
- package/init-node.js.map +1 -0
- package/mcp/ai-tools.d.ts +2 -0
- package/mcp/ai-tools.d.ts.map +1 -0
- package/mcp/ai-tools.js +266 -0
- package/mcp/ai-tools.js.map +1 -0
- package/mcp/auto-dispatch-tools.d.ts +2 -0
- package/mcp/auto-dispatch-tools.d.ts.map +1 -0
- package/mcp/auto-dispatch-tools.js +348 -0
- package/mcp/auto-dispatch-tools.js.map +1 -0
- package/mcp/business-scope-tools.d.ts +11 -0
- package/mcp/business-scope-tools.d.ts.map +1 -0
- package/mcp/business-scope-tools.js +179 -0
- package/mcp/business-scope-tools.js.map +1 -0
- package/mcp/buyer-tools.d.ts +67 -0
- package/mcp/buyer-tools.d.ts.map +1 -0
- package/mcp/buyer-tools.js +445 -0
- package/mcp/buyer-tools.js.map +1 -0
- package/mcp/interfaces.d.ts +1058 -0
- package/mcp/interfaces.d.ts.map +1 -0
- package/mcp/interfaces.js +13 -0
- package/mcp/interfaces.js.map +1 -0
- package/mcp/m2m-chat-tool.d.ts +50 -0
- package/mcp/m2m-chat-tool.d.ts.map +1 -0
- package/mcp/m2m-chat-tool.js +432 -0
- package/mcp/m2m-chat-tool.js.map +1 -0
- package/mcp/migrations.d.ts +30 -0
- package/mcp/migrations.d.ts.map +1 -0
- package/mcp/migrations.js +391 -0
- package/mcp/migrations.js.map +1 -0
- package/mcp/peer-tools.d.ts +163 -0
- package/mcp/peer-tools.d.ts.map +1 -0
- package/mcp/peer-tools.js +532 -0
- package/mcp/peer-tools.js.map +1 -0
- package/mcp/plugin-management-tools.d.ts +2 -0
- package/mcp/plugin-management-tools.d.ts.map +1 -0
- package/mcp/plugin-management-tools.js +327 -0
- package/mcp/plugin-management-tools.js.map +1 -0
- package/mcp/product-type-tools.d.ts +2 -0
- package/mcp/product-type-tools.d.ts.map +1 -0
- package/mcp/product-type-tools.js +470 -0
- package/mcp/product-type-tools.js.map +1 -0
- package/mcp/security-tools.d.ts +2 -0
- package/mcp/security-tools.d.ts.map +1 -0
- package/mcp/security-tools.js +313 -0
- package/mcp/security-tools.js.map +1 -0
- package/mcp/seller-query-tools.d.ts +2 -0
- package/mcp/seller-query-tools.d.ts.map +1 -0
- package/mcp/seller-query-tools.js +179 -0
- package/mcp/seller-query-tools.js.map +1 -0
- package/mcp/server.d.ts +11 -0
- package/mcp/server.d.ts.map +1 -0
- package/mcp/server.js +68 -0
- package/mcp/server.js.map +1 -0
- package/mcp/standalone-server.d.ts +34 -0
- package/mcp/standalone-server.d.ts.map +1 -0
- package/mcp/standalone-server.js +261 -0
- package/mcp/standalone-server.js.map +1 -0
- package/mcp/tools-integration.d.ts +31 -0
- package/mcp/tools-integration.d.ts.map +1 -0
- package/mcp/tools-integration.js +288 -0
- package/mcp/tools-integration.js.map +1 -0
- package/mcp/web-panel.d.ts +18 -0
- package/mcp/web-panel.d.ts.map +1 -0
- package/mcp/web-panel.js +1657 -0
- package/mcp/web-panel.js.map +1 -0
- package/middleware/api-key-auth.d.ts +64 -0
- package/middleware/api-key-auth.d.ts.map +1 -0
- package/middleware/api-key-auth.js +255 -0
- package/middleware/api-key-auth.js.map +1 -0
- package/middleware/scope-auth.d.ts +54 -0
- package/middleware/scope-auth.d.ts.map +1 -0
- package/middleware/scope-auth.js +153 -0
- package/middleware/scope-auth.js.map +1 -0
- package/middleware/security.d.ts +48 -0
- package/middleware/security.d.ts.map +1 -0
- package/middleware/security.js +217 -0
- package/middleware/security.js.map +1 -0
- package/middleware/wallet-auth.d.ts +54 -0
- package/middleware/wallet-auth.d.ts.map +1 -0
- package/middleware/wallet-auth.js +158 -0
- package/middleware/wallet-auth.js.map +1 -0
- package/oauth/chain-revocation-sink.d.ts +24 -0
- package/oauth/chain-revocation-sink.d.ts.map +1 -0
- package/oauth/chain-revocation-sink.js +47 -0
- package/oauth/chain-revocation-sink.js.map +1 -0
- package/oauth/gossip-sync.d.ts +25 -0
- package/oauth/gossip-sync.d.ts.map +1 -0
- package/oauth/gossip-sync.js +62 -0
- package/oauth/gossip-sync.js.map +1 -0
- package/oauth/issuer-keys.d.ts +31 -0
- package/oauth/issuer-keys.d.ts.map +1 -0
- package/oauth/issuer-keys.js +117 -0
- package/oauth/issuer-keys.js.map +1 -0
- package/oauth/peer-resolver.d.ts +25 -0
- package/oauth/peer-resolver.d.ts.map +1 -0
- package/oauth/peer-resolver.js +81 -0
- package/oauth/peer-resolver.js.map +1 -0
- package/oauth/revocation-store.d.ts +58 -0
- package/oauth/revocation-store.d.ts.map +1 -0
- package/oauth/revocation-store.js +86 -0
- package/oauth/revocation-store.js.map +1 -0
- package/oauth/token-v2.d.ts +101 -0
- package/oauth/token-v2.d.ts.map +1 -0
- package/oauth/token-v2.js +167 -0
- package/oauth/token-v2.js.map +1 -0
- package/oracle/c5-glue.js +603 -0
- package/oracle/ops-console.js +623 -0
- package/oracle/oracle-sync.d.ts +29 -0
- package/oracle/oracle-sync.d.ts.map +1 -0
- package/oracle/oracle-sync.js +445 -0
- package/oracle/oracle-sync.js.map +1 -0
- package/oracle/registry.d.ts +30 -0
- package/oracle/registry.d.ts.map +1 -0
- package/oracle/registry.js +62 -0
- package/oracle/registry.js.map +1 -0
- package/p2p/availability.d.ts +188 -0
- package/p2p/availability.d.ts.map +1 -0
- package/p2p/availability.js +574 -0
- package/p2p/availability.js.map +1 -0
- package/p2p/bootstrap.d.ts +42 -0
- package/p2p/bootstrap.d.ts.map +1 -0
- package/p2p/bootstrap.js +146 -0
- package/p2p/bootstrap.js.map +1 -0
- package/p2p/buyer-client.d.ts +98 -0
- package/p2p/buyer-client.d.ts.map +1 -0
- package/p2p/buyer-client.js +199 -0
- package/p2p/buyer-client.js.map +1 -0
- package/p2p/cdn-ddns.d.ts +208 -0
- package/p2p/cdn-ddns.d.ts.map +1 -0
- package/p2p/cdn-ddns.js +500 -0
- package/p2p/cdn-ddns.js.map +1 -0
- package/p2p/cluster-sync.d.ts +115 -0
- package/p2p/cluster-sync.d.ts.map +1 -0
- package/p2p/cluster-sync.js +330 -0
- package/p2p/cluster-sync.js.map +1 -0
- package/p2p/consistency-check.d.ts +30 -0
- package/p2p/consistency-check.d.ts.map +1 -0
- package/p2p/consistency-check.js +168 -0
- package/p2p/consistency-check.js.map +1 -0
- package/p2p/endpoint-registry.d.ts +41 -0
- package/p2p/endpoint-registry.d.ts.map +1 -0
- package/p2p/endpoint-registry.js +128 -0
- package/p2p/endpoint-registry.js.map +1 -0
- package/p2p/ipv6.d.ts +120 -0
- package/p2p/ipv6.d.ts.map +1 -0
- package/p2p/ipv6.js +425 -0
- package/p2p/ipv6.js.map +1 -0
- package/p2p/protocol.d.ts +100 -0
- package/p2p/protocol.d.ts.map +1 -0
- package/p2p/protocol.js +330 -0
- package/p2p/protocol.js.map +1 -0
- package/p2p/reliability.d.ts +56 -0
- package/p2p/reliability.d.ts.map +1 -0
- package/p2p/reliability.js +240 -0
- package/p2p/reliability.js.map +1 -0
- package/p2p/seller-service.d.ts +53 -0
- package/p2p/seller-service.d.ts.map +1 -0
- package/p2p/seller-service.js +276 -0
- package/p2p/seller-service.js.map +1 -0
- package/p2p/signing.d.ts +31 -0
- package/p2p/signing.d.ts.map +1 -0
- package/p2p/signing.js +95 -0
- package/p2p/signing.js.map +1 -0
- package/package.json +73 -0
- package/payment/api.d.ts +9 -0
- package/payment/api.d.ts.map +1 -0
- package/payment/api.js +141 -0
- package/payment/api.js.map +1 -0
- package/payment/gateway.d.ts +114 -0
- package/payment/gateway.d.ts.map +1 -0
- package/payment/gateway.js +231 -0
- package/payment/gateway.js.map +1 -0
- package/payments/alipay/index.d.ts +18 -0
- package/payments/alipay/index.d.ts.map +1 -0
- package/payments/alipay/index.js +55 -0
- package/payments/alipay/index.js.map +1 -0
- package/payments/base.d.ts +13 -0
- package/payments/base.d.ts.map +1 -0
- package/payments/base.js +28 -0
- package/payments/base.js.map +1 -0
- package/payments/index.d.ts +18 -0
- package/payments/index.d.ts.map +1 -0
- package/payments/index.js +66 -0
- package/payments/index.js.map +1 -0
- package/payments/template/index.d.ts +18 -0
- package/payments/template/index.d.ts.map +1 -0
- package/payments/template/index.js +57 -0
- package/payments/template/index.js.map +1 -0
- package/payments/types.d.ts +42 -0
- package/payments/types.d.ts.map +1 -0
- package/payments/types.js +3 -0
- package/payments/types.js.map +1 -0
- package/payments/wechat/index.d.ts +18 -0
- package/payments/wechat/index.d.ts.map +1 -0
- package/payments/wechat/index.js +54 -0
- package/payments/wechat/index.js.map +1 -0
- package/peer/chain-signer.d.ts +74 -0
- package/peer/chain-signer.d.ts.map +1 -0
- package/peer/chain-signer.js +149 -0
- package/peer/chain-signer.js.map +1 -0
- package/peer/config.d.ts +71 -0
- package/peer/config.d.ts.map +1 -0
- package/peer/config.js +61 -0
- package/peer/config.js.map +1 -0
- package/peer/index.d.ts +12 -0
- package/peer/index.d.ts.map +1 -0
- package/peer/index.js +46 -0
- package/peer/index.js.map +1 -0
- package/peer/key-store.d.ts +66 -0
- package/peer/key-store.d.ts.map +1 -0
- package/peer/key-store.js +163 -0
- package/peer/key-store.js.map +1 -0
- package/peer/proto-codec.d.ts +103 -0
- package/peer/proto-codec.d.ts.map +1 -0
- package/peer/proto-codec.js +423 -0
- package/peer/proto-codec.js.map +1 -0
- package/peer/registrar.d.ts +88 -0
- package/peer/registrar.d.ts.map +1 -0
- package/peer/registrar.js +271 -0
- package/peer/registrar.js.map +1 -0
- package/peer/registry.d.ts +31 -0
- package/peer/registry.d.ts.map +1 -0
- package/peer/registry.js +143 -0
- package/peer/registry.js.map +1 -0
- package/plugins/auth.d.ts +193 -0
- package/plugins/auth.d.ts.map +1 -0
- package/plugins/auth.js +923 -0
- package/plugins/auth.js.map +1 -0
- package/plugins/manager.d.ts +37 -0
- package/plugins/manager.d.ts.map +1 -0
- package/plugins/manager.js +83 -0
- package/plugins/manager.js.map +1 -0
- package/plugins/oauth.d.ts +249 -0
- package/plugins/oauth.d.ts.map +1 -0
- package/plugins/oauth.js +979 -0
- package/plugins/oauth.js.map +1 -0
- package/plugins/p2p-message.d.ts +133 -0
- package/plugins/p2p-message.d.ts.map +1 -0
- package/plugins/p2p-message.js +443 -0
- package/plugins/p2p-message.js.map +1 -0
- package/plugins/postgresql.d.ts +54 -0
- package/plugins/postgresql.d.ts.map +1 -0
- package/plugins/postgresql.js +743 -0
- package/plugins/postgresql.js.map +1 -0
- package/plugins/relationship.d.ts +141 -0
- package/plugins/relationship.d.ts.map +1 -0
- package/plugins/relationship.js +395 -0
- package/plugins/relationship.js.map +1 -0
- package/plugins/sqlite.d.ts +200 -0
- package/plugins/sqlite.d.ts.map +1 -0
- package/plugins/sqlite.js +2412 -0
- package/plugins/sqlite.js.map +1 -0
- package/port-manager/disguise/ssh.d.ts +19 -0
- package/port-manager/disguise/ssh.d.ts.map +1 -0
- package/port-manager/disguise/ssh.js +104 -0
- package/port-manager/disguise/ssh.js.map +1 -0
- package/port-manager/port-manager.d.ts +65 -0
- package/port-manager/port-manager.d.ts.map +1 -0
- package/port-manager/port-manager.js +164 -0
- package/port-manager/port-manager.js.map +1 -0
- package/port-manager/port-scanner.d.ts +22 -0
- package/port-manager/port-scanner.d.ts.map +1 -0
- package/port-manager/port-scanner.js +187 -0
- package/port-manager/port-scanner.js.map +1 -0
- package/port-manager/types.d.ts +51 -0
- package/port-manager/types.d.ts.map +1 -0
- package/port-manager/types.js +6 -0
- package/port-manager/types.js.map +1 -0
- package/proto/amino/amino.proto +84 -0
- package/proto/cosmos/base/v1beta1/coin.proto +61 -0
- package/proto/cosmos/msg/v1/msg.proto +30 -0
- package/proto/cosmos_proto/cosmos.proto +112 -0
- package/proto/gogoproto/gogo.proto +145 -0
- package/proto/google/protobuf/descriptor.proto +1218 -0
- package/proto/trustchain/economy/v1/params.proto +133 -0
- package/proto/trustchain/economy/v1/tx.proto +162 -0
- package/proto/trustchain/marketplace/v1/params.proto +64 -0
- package/proto/trustchain/marketplace/v1/product.proto +21 -0
- package/proto/trustchain/marketplace/v1/tx.proto +131 -0
- package/proto/trustchain/order/v1/params.proto +94 -0
- package/proto/trustchain/order/v1/tx.proto +156 -0
- package/proto/trustchain/serviceprovider/v1/paymentfact.proto +32 -0
- package/proto/trustchain/serviceprovider/v1/serviceprovider.proto +38 -0
- package/proto/trustchain/serviceprovider/v1/tx.proto +106 -0
- package/proto/trustchain/subchain/v1/params.proto +26 -0
- package/proto/trustchain/subchain/v1/pool.proto +53 -0
- package/proto/trustchain/subchain/v1/tx.proto +159 -0
- package/proto/trustchain/trustcoin/v1/business_scope.proto +126 -0
- package/proto/trustchain/trustcoin/v1/genesis.proto +33 -0
- package/proto/trustchain/trustcoin/v1/params.proto +86 -0
- package/proto/trustchain/trustcoin/v1/query.proto +95 -0
- package/proto/trustchain/trustcoin/v1/tx.proto +160 -0
- package/proto/trustchain/verification/v1/params.proto +46 -0
- package/proto/trustchain/verification/v1/tx.proto +126 -0
- package/proto/trustchain/verification/v1/verification.proto +105 -0
- package/relationship-chain-api.d.ts +13 -0
- package/relationship-chain-api.d.ts.map +1 -0
- package/relationship-chain-api.js +139 -0
- package/relationship-chain-api.js.map +1 -0
- package/relationship-chain.d.ts +90 -0
- package/relationship-chain.d.ts.map +1 -0
- package/relationship-chain.js +201 -0
- package/relationship-chain.js.map +1 -0
- package/routes/agent-pay.js +419 -0
- package/routes/agent-serviceprovider.js +183 -0
- package/routes/ai.d.ts +54 -0
- package/routes/ai.d.ts.map +1 -0
- package/routes/ai.js +293 -0
- package/routes/ai.js.map +1 -0
- package/routes/api-keys.d.ts +12 -0
- package/routes/api-keys.d.ts.map +1 -0
- package/routes/api-keys.js +163 -0
- package/routes/api-keys.js.map +1 -0
- package/routes/app-store.d.ts +12 -0
- package/routes/app-store.d.ts.map +1 -0
- package/routes/app-store.js +207 -0
- package/routes/app-store.js.map +1 -0
- package/routes/auth-management.d.ts +17 -0
- package/routes/auth-management.d.ts.map +1 -0
- package/routes/auth-management.js +257 -0
- package/routes/auth-management.js.map +1 -0
- package/routes/auth.d.ts +9 -0
- package/routes/auth.d.ts.map +1 -0
- package/routes/auth.js +846 -0
- package/routes/auth.js.map +1 -0
- package/routes/brand.d.ts +3 -0
- package/routes/brand.d.ts.map +1 -0
- package/routes/brand.js +109 -0
- package/routes/brand.js.map +1 -0
- package/routes/chain-registry.d.ts +11 -0
- package/routes/chain-registry.d.ts.map +1 -0
- package/routes/chain-registry.js +51 -0
- package/routes/chain-registry.js.map +1 -0
- package/routes/chain-writes-insurance.d.ts +17 -0
- package/routes/chain-writes-insurance.d.ts.map +1 -0
- package/routes/chain-writes-insurance.js +69 -0
- package/routes/chain-writes-insurance.js.map +1 -0
- package/routes/chain-writes-pledge.d.ts +34 -0
- package/routes/chain-writes-pledge.d.ts.map +1 -0
- package/routes/chain-writes-pledge.js +206 -0
- package/routes/chain-writes-pledge.js.map +1 -0
- package/routes/chain-writes-products.d.ts +66 -0
- package/routes/chain-writes-products.d.ts.map +1 -0
- package/routes/chain-writes-products.js +394 -0
- package/routes/chain-writes-products.js.map +1 -0
- package/routes/chain-writes.d.ts +78 -0
- package/routes/chain-writes.d.ts.map +1 -0
- package/routes/chain-writes.js +658 -0
- package/routes/chain-writes.js.map +1 -0
- package/routes/chain.d.ts +10 -0
- package/routes/chain.d.ts.map +1 -0
- package/routes/chain.js +45 -0
- package/routes/chain.js.map +1 -0
- package/routes/compliance.d.ts +3 -0
- package/routes/compliance.d.ts.map +1 -0
- package/routes/compliance.js +53 -0
- package/routes/compliance.js.map +1 -0
- package/routes/council.d.ts +3 -0
- package/routes/council.d.ts.map +1 -0
- package/routes/council.js +477 -0
- package/routes/council.js.map +1 -0
- package/routes/crosschain.d.ts +11 -0
- package/routes/crosschain.d.ts.map +1 -0
- package/routes/crosschain.js +39 -0
- package/routes/crosschain.js.map +1 -0
- package/routes/device.d.ts +3 -0
- package/routes/device.d.ts.map +1 -0
- package/routes/device.js +73 -0
- package/routes/device.js.map +1 -0
- package/routes/devreward.d.ts +54 -0
- package/routes/devreward.d.ts.map +1 -0
- package/routes/devreward.js +129 -0
- package/routes/devreward.js.map +1 -0
- package/routes/economy.d.ts +50 -0
- package/routes/economy.d.ts.map +1 -0
- package/routes/economy.js +273 -0
- package/routes/economy.js.map +1 -0
- package/routes/flowback.d.ts +32 -0
- package/routes/flowback.d.ts.map +1 -0
- package/routes/flowback.js +97 -0
- package/routes/flowback.js.map +1 -0
- package/routes/insurance.d.ts +10 -0
- package/routes/insurance.d.ts.map +1 -0
- package/routes/insurance.js +70 -0
- package/routes/insurance.js.map +1 -0
- package/routes/m2m-viewer.js +195 -0
- package/routes/m2m.d.ts +10 -0
- package/routes/m2m.d.ts.map +1 -0
- package/routes/m2m.js +31 -0
- package/routes/m2m.js.map +1 -0
- package/routes/marketplace.d.ts +15 -0
- package/routes/marketplace.d.ts.map +1 -0
- package/routes/marketplace.js +396 -0
- package/routes/marketplace.js.map +1 -0
- package/routes/node-config.d.ts +6 -0
- package/routes/node-config.d.ts.map +1 -0
- package/routes/node-config.js +500 -0
- package/routes/node-config.js.map +1 -0
- package/routes/oauth-revocation.d.ts +42 -0
- package/routes/oauth-revocation.d.ts.map +1 -0
- package/routes/oauth-revocation.js +99 -0
- package/routes/oauth-revocation.js.map +1 -0
- package/routes/oauth.d.ts +17 -0
- package/routes/oauth.d.ts.map +1 -0
- package/routes/oauth.js +700 -0
- package/routes/oauth.js.map +1 -0
- package/routes/onboard.html +352 -0
- package/routes/onboard.js +435 -0
- package/routes/order.d.ts +8 -0
- package/routes/order.d.ts.map +1 -0
- package/routes/order.js +607 -0
- package/routes/order.js.map +1 -0
- package/routes/p2p-api.d.ts +33 -0
- package/routes/p2p-api.d.ts.map +1 -0
- package/routes/p2p-api.js +274 -0
- package/routes/p2p-api.js.map +1 -0
- package/routes/p2p-message.d.ts +20 -0
- package/routes/p2p-message.d.ts.map +1 -0
- package/routes/p2p-message.js +237 -0
- package/routes/p2p-message.js.map +1 -0
- package/routes/peer.d.ts +22 -0
- package/routes/peer.d.ts.map +1 -0
- package/routes/peer.js +220 -0
- package/routes/peer.js.map +1 -0
- package/routes/plugins.d.ts +4 -0
- package/routes/plugins.d.ts.map +1 -0
- package/routes/plugins.js +138 -0
- package/routes/plugins.js.map +1 -0
- package/routes/port-manager.d.ts +6 -0
- package/routes/port-manager.d.ts.map +1 -0
- package/routes/port-manager.js +212 -0
- package/routes/port-manager.js.map +1 -0
- package/routes/relationship.d.ts +7 -0
- package/routes/relationship.d.ts.map +1 -0
- package/routes/relationship.js +314 -0
- package/routes/relationship.js.map +1 -0
- package/routes/relay.d.ts +3 -0
- package/routes/relay.d.ts.map +1 -0
- package/routes/relay.js +182 -0
- package/routes/relay.js.map +1 -0
- package/routes/reputation.d.ts +10 -0
- package/routes/reputation.d.ts.map +1 -0
- package/routes/reputation.js +141 -0
- package/routes/reputation.js.map +1 -0
- package/routes/reward.d.ts +3 -0
- package/routes/reward.d.ts.map +1 -0
- package/routes/reward.js +130 -0
- package/routes/reward.js.map +1 -0
- package/routes/security-monitoring.d.ts +12 -0
- package/routes/security-monitoring.d.ts.map +1 -0
- package/routes/security-monitoring.js +373 -0
- package/routes/security-monitoring.js.map +1 -0
- package/routes/shop.d.ts +8 -0
- package/routes/shop.d.ts.map +1 -0
- package/routes/shop.js +164 -0
- package/routes/shop.js.map +1 -0
- package/routes/social.d.ts +22 -0
- package/routes/social.d.ts.map +1 -0
- package/routes/social.js +95 -0
- package/routes/social.js.map +1 -0
- package/routes/subchain.d.ts +18 -0
- package/routes/subchain.d.ts.map +1 -0
- package/routes/subchain.js +106 -0
- package/routes/subchain.js.map +1 -0
- package/routes/trustcoin.d.ts +17 -0
- package/routes/trustcoin.d.ts.map +1 -0
- package/routes/trustcoin.js +149 -0
- package/routes/trustcoin.js.map +1 -0
- package/routes/twofa.d.ts +7 -0
- package/routes/twofa.d.ts.map +1 -0
- package/routes/twofa.js +105 -0
- package/routes/twofa.js.map +1 -0
- package/routes/verification.d.ts +8 -0
- package/routes/verification.d.ts.map +1 -0
- package/routes/verification.js +234 -0
- package/routes/verification.js.map +1 -0
- package/routes/wallet.d.ts +4 -0
- package/routes/wallet.d.ts.map +1 -0
- package/routes/wallet.js +770 -0
- package/routes/wallet.js.map +1 -0
- package/run-auth.d.ts +8 -0
- package/run-auth.d.ts.map +1 -0
- package/run-auth.js +82 -0
- package/run-auth.js.map +1 -0
- package/run-p2p-message.d.ts +8 -0
- package/run-p2p-message.d.ts.map +1 -0
- package/run-p2p-message.js +82 -0
- package/run-p2p-message.js.map +1 -0
- package/run-relationship.d.ts +12 -0
- package/run-relationship.d.ts.map +1 -0
- package/run-relationship.js +182 -0
- package/run-relationship.js.map +1 -0
- package/run-unified.d.ts +13 -0
- package/run-unified.d.ts.map +1 -0
- package/run-unified.js +1067 -0
- package/run-unified.js.map +1 -0
- package/run.d.ts +12 -0
- package/run.d.ts.map +1 -0
- package/run.js +889 -0
- package/run.js.map +1 -0
- package/search/ranking.d.ts +55 -0
- package/search/ranking.d.ts.map +1 -0
- package/search/ranking.js +67 -0
- package/search/ranking.js.map +1 -0
- package/shipping/base.d.ts +15 -0
- package/shipping/base.d.ts.map +1 -0
- package/shipping/base.js +39 -0
- package/shipping/base.js.map +1 -0
- package/shipping/index.d.ts +19 -0
- package/shipping/index.d.ts.map +1 -0
- package/shipping/index.js +72 -0
- package/shipping/index.js.map +1 -0
- package/shipping/sf-express/index.d.ts +23 -0
- package/shipping/sf-express/index.d.ts.map +1 -0
- package/shipping/sf-express/index.js +71 -0
- package/shipping/sf-express/index.js.map +1 -0
- package/shipping/template/index.d.ts +20 -0
- package/shipping/template/index.d.ts.map +1 -0
- package/shipping/template/index.js +74 -0
- package/shipping/template/index.js.map +1 -0
- package/shipping/types.d.ts +71 -0
- package/shipping/types.d.ts.map +1 -0
- package/shipping/types.js +6 -0
- package/shipping/types.js.map +1 -0
- package/shipping/virtual/index.d.ts +19 -0
- package/shipping/virtual/index.d.ts.map +1 -0
- package/shipping/virtual/index.js +54 -0
- package/shipping/virtual/index.js.map +1 -0
- package/shipping/yto/index.d.ts +18 -0
- package/shipping/yto/index.d.ts.map +1 -0
- package/shipping/yto/index.js +59 -0
- package/shipping/yto/index.js.map +1 -0
- package/shipping/zto/index.d.ts +18 -0
- package/shipping/zto/index.d.ts.map +1 -0
- package/shipping/zto/index.js +59 -0
- package/shipping/zto/index.js.map +1 -0
- package/skills-lock.json +11 -0
- package/src/db/email-migrations.sql +31 -0
- package/src/db/oauth-migrations.sql +92 -0
- package/src/db/social-migrations.sql +94 -0
- package/src/db/store-migrations.sql +242 -0
- package/test-api-key-revoke.js +167 -0
- package/test-auth-register-ratelimit.js +132 -0
- package/test-auth-tv2.d.ts +2 -0
- package/test-auth-tv2.d.ts.map +1 -0
- package/test-auth-tv2.js +174 -0
- package/test-auth-tv2.js.map +1 -0
- package/test-canonsign-cross.d.ts +2 -0
- package/test-canonsign-cross.d.ts.map +1 -0
- package/test-canonsign-cross.js +32 -0
- package/test-canonsign-cross.js.map +1 -0
- package/test-chain-signer.js +127 -0
- package/test-env-truthy.js +50 -0
- package/test-onboard-contract.js +94 -0
- package/test-ops-console-boundary.js +147 -0
- package/test-oracle-glue.js +232 -0
- package/test-order-create-v394.js +358 -0
- package/test-order-intent.js +245 -0
- package/test-order-lifecycle-v394.js +528 -0
- package/test-p2p-message.d.ts +13 -0
- package/test-p2p-message.d.ts.map +1 -0
- package/test-p2p-message.js +106 -0
- package/test-p2p-message.js.map +1 -0
- package/test-relationship-chain.d.ts +13 -0
- package/test-relationship-chain.d.ts.map +1 -0
- package/test-relationship-chain.js +103 -0
- package/test-relationship-chain.js.map +1 -0
- package/test-runtime-data-path.js +217 -0
- package/test-seller-identity.js +74 -0
- package/test-signing-paths.js +104 -0
- package/test-token-v2.d.ts +2 -0
- package/test-token-v2.d.ts.map +1 -0
- package/test-token-v2.js +172 -0
- package/test-token-v2.js.map +1 -0
- package/test-wallet-auth-nonce.d.ts +12 -0
- package/test-wallet-auth-nonce.d.ts.map +1 -0
- package/test-wallet-auth-nonce.js +126 -0
- package/test-wallet-auth-nonce.js.map +1 -0
- package/test-wallet-submatch.d.ts +13 -0
- package/test-wallet-submatch.d.ts.map +1 -0
- package/test-wallet-submatch.js +86 -0
- package/test-wallet-submatch.js.map +1 -0
- package/tls/self-signed.d.ts +12 -0
- package/tls/self-signed.d.ts.map +1 -0
- package/tls/self-signed.js +63 -0
- package/tls/self-signed.js.map +1 -0
- package/tools/brand.d.ts +11 -0
- package/tools/brand.d.ts.map +1 -0
- package/tools/brand.js +75 -0
- package/tools/brand.js.map +1 -0
- package/tools/chainregistry.d.ts +18 -0
- package/tools/chainregistry.d.ts.map +1 -0
- package/tools/chainregistry.js +175 -0
- package/tools/chainregistry.js.map +1 -0
- package/tools/compliance.d.ts +14 -0
- package/tools/compliance.d.ts.map +1 -0
- package/tools/compliance.js +45 -0
- package/tools/compliance.js.map +1 -0
- package/tools/council.d.ts +17 -0
- package/tools/council.d.ts.map +1 -0
- package/tools/council.js +75 -0
- package/tools/council.js.map +1 -0
- package/tools/device.d.ts +13 -0
- package/tools/device.d.ts.map +1 -0
- package/tools/device.js +45 -0
- package/tools/device.js.map +1 -0
- package/tools/devreward.d.ts +15 -0
- package/tools/devreward.d.ts.map +1 -0
- package/tools/devreward.js +190 -0
- package/tools/devreward.js.map +1 -0
- package/tools/economy.d.ts +14 -0
- package/tools/economy.d.ts.map +1 -0
- package/tools/economy.js +172 -0
- package/tools/economy.js.map +1 -0
- package/tools/flowback.d.ts +14 -0
- package/tools/flowback.d.ts.map +1 -0
- package/tools/flowback.js +146 -0
- package/tools/flowback.js.map +1 -0
- package/tools/insurance.d.ts +13 -0
- package/tools/insurance.d.ts.map +1 -0
- package/tools/insurance.js +45 -0
- package/tools/insurance.js.map +1 -0
- package/tools/marketplace.d.ts +12 -0
- package/tools/marketplace.d.ts.map +1 -0
- package/tools/marketplace.js +124 -0
- package/tools/marketplace.js.map +1 -0
- package/tools/order.d.ts +12 -0
- package/tools/order.d.ts.map +1 -0
- package/tools/order.js +94 -0
- package/tools/order.js.map +1 -0
- package/tools/recovery.d.ts +14 -0
- package/tools/recovery.d.ts.map +1 -0
- package/tools/recovery.js +158 -0
- package/tools/recovery.js.map +1 -0
- package/tools/relay.d.ts +15 -0
- package/tools/relay.d.ts.map +1 -0
- package/tools/relay.js +152 -0
- package/tools/relay.js.map +1 -0
- package/tools/reputation.d.ts +20 -0
- package/tools/reputation.d.ts.map +1 -0
- package/tools/reputation.js +50 -0
- package/tools/reputation.js.map +1 -0
- package/tools/reputation_seller_credit.d.ts +16 -0
- package/tools/reputation_seller_credit.d.ts.map +1 -0
- package/tools/reputation_seller_credit.js +106 -0
- package/tools/reputation_seller_credit.js.map +1 -0
- package/tools/reward.d.ts +14 -0
- package/tools/reward.d.ts.map +1 -0
- package/tools/reward.js +76 -0
- package/tools/reward.js.map +1 -0
- package/tools/shop.d.ts +14 -0
- package/tools/shop.d.ts.map +1 -0
- package/tools/shop.js +95 -0
- package/tools/shop.js.map +1 -0
- package/tools/verification.d.ts +12 -0
- package/tools/verification.d.ts.map +1 -0
- package/tools/verification.js +89 -0
- package/tools/verification.js.map +1 -0
- package/types/store.d.ts +255 -0
- package/types/store.d.ts.map +1 -0
- package/types/store.js +19 -0
- package/types/store.js.map +1 -0
- package/utils/aes-gcm.d.ts +63 -0
- package/utils/aes-gcm.d.ts.map +1 -0
- package/utils/aes-gcm.js +179 -0
- package/utils/aes-gcm.js.map +1 -0
- package/utils/api-response.d.ts +51 -0
- package/utils/api-response.d.ts.map +1 -0
- package/utils/api-response.js +65 -0
- package/utils/api-response.js.map +1 -0
- package/utils/base32.d.ts +5 -0
- package/utils/base32.d.ts.map +1 -0
- package/utils/base32.js +20 -0
- package/utils/base32.js.map +1 -0
- package/utils/crypto.d.ts +77 -0
- package/utils/crypto.d.ts.map +1 -0
- package/utils/crypto.js +164 -0
- package/utils/crypto.js.map +1 -0
- package/utils/encryption.d.ts +81 -0
- package/utils/encryption.d.ts.map +1 -0
- package/utils/encryption.js +247 -0
- package/utils/encryption.js.map +1 -0
- package/utils/env.js +20 -0
- package/utils/jwt.d.ts +110 -0
- package/utils/jwt.d.ts.map +1 -0
- package/utils/jwt.js +275 -0
- package/utils/jwt.js.map +1 -0
- package/utils/qrcode-reader.d.ts +22 -0
- package/utils/qrcode-reader.d.ts.map +1 -0
- package/utils/qrcode-reader.js +90 -0
- package/utils/qrcode-reader.js.map +1 -0
- package/utils/qrcode.d.ts +26 -0
- package/utils/qrcode.d.ts.map +1 -0
- package/utils/qrcode.js +92 -0
- package/utils/qrcode.js.map +1 -0
- package/utils/totp.d.ts +3 -0
- package/utils/totp.d.ts.map +1 -0
- package/utils/totp.js +58 -0
- package/utils/totp.js.map +1 -0
- package/utils/two-factor-auth.d.ts +16 -0
- package/utils/two-factor-auth.d.ts.map +1 -0
- package/utils/two-factor-auth.js +150 -0
- package/utils/two-factor-auth.js.map +1 -0
- package/verifyer/hsm.d.ts +70 -0
- package/verifyer/hsm.d.ts.map +1 -0
- package/verifyer/hsm.js +482 -0
- package/verifyer/hsm.js.map +1 -0
- package/verifyer/index.d.ts +81 -0
- package/verifyer/index.d.ts.map +1 -0
- package/verifyer/index.js +372 -0
- package/verifyer/index.js.map +1 -0
- package/ws/peer-monitor-broadcaster.d.ts +24 -0
- package/ws/peer-monitor-broadcaster.d.ts.map +1 -0
- package/ws/peer-monitor-broadcaster.js +56 -0
- package/ws/peer-monitor-broadcaster.js.map +1 -0
package/run.js
ADDED
|
@@ -0,0 +1,889 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* run.ts - 索引器启动入口
|
|
4
|
+
*
|
|
5
|
+
* 用法: npx ts-node src/run.ts
|
|
6
|
+
*
|
|
7
|
+
* 环境变量:
|
|
8
|
+
* CHAIN_RPC_URL - 链RPC地址(默认 http://localhost:26657)
|
|
9
|
+
* CHAIN_ID - 链ID(默认 trustchain-local)
|
|
10
|
+
* INDEXER_DATA_DIR - 数据目录(默认 ./data)
|
|
11
|
+
*/
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
const index_1 = require("./index");
|
|
17
|
+
const http_1 = __importDefault(require("http"));
|
|
18
|
+
const cluster_sync_1 = require("./p2p/cluster-sync");
|
|
19
|
+
const location_1 = require("./core/location");
|
|
20
|
+
const enforcement_1 = require("./core/enforcement");
|
|
21
|
+
const consistency_check_1 = require("./p2p/consistency-check");
|
|
22
|
+
const content_backfill_1 = require("./core/content-backfill");
|
|
23
|
+
const cache_1 = require("./core/cache");
|
|
24
|
+
const cleanup_1 = require("./core/cleanup");
|
|
25
|
+
const config = {
|
|
26
|
+
dataDir: process.env.INDEXER_DATA_DIR || './data',
|
|
27
|
+
chainRpcUrl: process.env.CHAIN_RPC_URL || 'http://localhost:26657',
|
|
28
|
+
chainId: process.env.CHAIN_ID || 'trustchain-local',
|
|
29
|
+
coverageMode: 'local',
|
|
30
|
+
logLevel: 'info',
|
|
31
|
+
};
|
|
32
|
+
console.log('=== TrustCoin Indexer ===');
|
|
33
|
+
console.log(`RPC: ${config.chainRpcUrl}`);
|
|
34
|
+
console.log(`Chain: ${config.chainId}`);
|
|
35
|
+
console.log(`Data: ${config.dataDir}`);
|
|
36
|
+
console.log('========================');
|
|
37
|
+
const indexer = new index_1.TrustCoinIndexer(config);
|
|
38
|
+
const locationManager = new location_1.LocationManager();
|
|
39
|
+
let lastPartition = null;
|
|
40
|
+
// Periodic stats
|
|
41
|
+
setInterval(async () => {
|
|
42
|
+
try {
|
|
43
|
+
const stats = await indexer.getStats();
|
|
44
|
+
console.log(`[Stats] Products: ${stats.totalProducts} | Sellers: ${stats.totalSellers} | Synced: ${stats.syncedHeight}`);
|
|
45
|
+
}
|
|
46
|
+
catch { }
|
|
47
|
+
}, 30000);
|
|
48
|
+
// Periodic location partition (every 5 min)
|
|
49
|
+
setInterval(async () => {
|
|
50
|
+
try {
|
|
51
|
+
const plugin = indexer.getPlugin();
|
|
52
|
+
if (!plugin?.db)
|
|
53
|
+
return;
|
|
54
|
+
const sellers = plugin.db.prepare('SELECT address, latitude, longitude FROM sellers WHERE latitude != 0 OR longitude != 0').all();
|
|
55
|
+
if (sellers.length === 0)
|
|
56
|
+
return;
|
|
57
|
+
lastPartition = locationManager.partitionSellers(sellers);
|
|
58
|
+
const pStats = locationManager.getPartitionStats(lastPartition);
|
|
59
|
+
console.log(`[Location:Partition] Total=${pStats.total} SameCity=${pStats.sameCity} Regional=${pStats.regional} Metro=${pStats.metro} Remote=${pStats.remote} Verified=${pStats.verified} Suspicious=${pStats.suspicious}`);
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
console.error(`[Location:Partition] Error: ${e.message}`);
|
|
63
|
+
}
|
|
64
|
+
}, 5 * 60 * 1000);
|
|
65
|
+
indexer.start().then(async () => {
|
|
66
|
+
// ---- Location Discovery (PRD 16.4) ----
|
|
67
|
+
const envLat = process.env.INDEXER_LAT ? parseInt(process.env.INDEXER_LAT) : undefined;
|
|
68
|
+
const envLon = process.env.INDEXER_LON ? parseInt(process.env.INDEXER_LON) : undefined;
|
|
69
|
+
const envCity = process.env.INDEXER_CITY || undefined;
|
|
70
|
+
const { location: selfLocation, method: locMethod } = await locationManager.resolveLocation({
|
|
71
|
+
manualLocation: (envLat != null && envLon != null)
|
|
72
|
+
? { latitude: envLat, longitude: envLon, city: envCity }
|
|
73
|
+
: undefined,
|
|
74
|
+
});
|
|
75
|
+
console.log(`[Location] Resolved: ${selfLocation.latitude / 1e6},${selfLocation.longitude / 1e6} city=${selfLocation.city || '-'} method=${locMethod}`);
|
|
76
|
+
// Start HTTP API for P2P registration + queries + cluster sync
|
|
77
|
+
const HTTP_PORT = parseInt(process.env.INDEXER_HTTP_PORT || '3001');
|
|
78
|
+
const p2pRegistry = new Map();
|
|
79
|
+
const enforcement = new enforcement_1.IndexerEnforcement();
|
|
80
|
+
// ---- Cluster Sync (Layer 2/3) ----
|
|
81
|
+
const TIER = parseInt(process.env.INDEXER_TIER || '1');
|
|
82
|
+
const SEED_NODES = (process.env.INDEXER_SEEDS || '').split(',').filter(Boolean).map(s => {
|
|
83
|
+
const [addr, port] = s.split(':');
|
|
84
|
+
return { address: addr, port: parseInt(port) };
|
|
85
|
+
});
|
|
86
|
+
const indexUpdateLog = []; // in-memory buffer, persisted to DB by recordUpdate()
|
|
87
|
+
// ---- Track sellers from chain events (P0-4) ----
|
|
88
|
+
indexer.on('chain-events', (_height, events) => {
|
|
89
|
+
for (const event of events) {
|
|
90
|
+
if (event.type === 'register_account' && event.attributes?.address) {
|
|
91
|
+
enforcement.trackSeller(event.attributes.address);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
// ---- Crash Recovery Hook (PRD 16.20) ----
|
|
96
|
+
const listener = indexer.listener;
|
|
97
|
+
if (listener) {
|
|
98
|
+
listener.on('rebuild-required', (reason) => {
|
|
99
|
+
console.warn(`[Recovery] Rebuild required: ${reason}`);
|
|
100
|
+
});
|
|
101
|
+
listener.on('recovery-complete', () => {
|
|
102
|
+
console.log('[Recovery] Sync caught up, notifying cluster peers');
|
|
103
|
+
clusterSync?.broadcastUpdate({
|
|
104
|
+
type: 'seller',
|
|
105
|
+
action: 'update',
|
|
106
|
+
key: 'recovery-complete',
|
|
107
|
+
hash: '',
|
|
108
|
+
height: indexer.getPlugin().getSyncHeight(),
|
|
109
|
+
timestamp: Date.now(),
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
// ---- ConsistencyChecker for Merkle root (P1-8) ----
|
|
114
|
+
const getPluginDb = () => {
|
|
115
|
+
const plugin = indexer.getPlugin();
|
|
116
|
+
return plugin?.db || null;
|
|
117
|
+
};
|
|
118
|
+
const computeMerkleRoot = async () => {
|
|
119
|
+
const db = getPluginDb();
|
|
120
|
+
if (!db)
|
|
121
|
+
return '';
|
|
122
|
+
const checker = new consistency_check_1.ConsistencyChecker(db);
|
|
123
|
+
return checker.computeProductsMerkleRoot();
|
|
124
|
+
};
|
|
125
|
+
// ---- ContentBackfiller (P1-5) ----
|
|
126
|
+
const backfiller = new content_backfill_1.ContentBackfiller({
|
|
127
|
+
getProduct: async (skuId) => {
|
|
128
|
+
const p = await indexer.getPlugin().getProduct(skuId);
|
|
129
|
+
if (!p)
|
|
130
|
+
return null;
|
|
131
|
+
return { contentHash: p.contentHash, seller: p.seller, title: p.title };
|
|
132
|
+
},
|
|
133
|
+
updateProduct: async (product) => {
|
|
134
|
+
const existing = await indexer.getPlugin().getProduct(product.skuId);
|
|
135
|
+
if (existing) {
|
|
136
|
+
await indexer.getPlugin().updateProduct({ ...existing, ...product });
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
getProductsNeedingBackfill: async () => {
|
|
140
|
+
const db = getPluginDb();
|
|
141
|
+
if (!db)
|
|
142
|
+
return [];
|
|
143
|
+
return db.prepare("SELECT sku_id, seller, content_hash FROM products WHERE content_hash = '' OR title = '' OR title = sku_id").all();
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
if (TIER >= 2 && SEED_NODES.length > 0) {
|
|
147
|
+
clusterSync = new cluster_sync_1.ClusterSync({
|
|
148
|
+
nodeId: `${process.env.INDEXER_NODE_ID || 'node-' + Date.now()}`,
|
|
149
|
+
apiPort: HTTP_PORT,
|
|
150
|
+
tier: TIER,
|
|
151
|
+
seedNodes: SEED_NODES,
|
|
152
|
+
getLocalHeight: () => indexer.getPlugin().getSyncHeight(),
|
|
153
|
+
getLocalUpdates: async (fromHeight) => {
|
|
154
|
+
// P0-3: Query from DB when available, fallback to in-memory
|
|
155
|
+
const plugin = indexer.getPlugin();
|
|
156
|
+
if (plugin?.getIndexUpdates) {
|
|
157
|
+
return plugin.getIndexUpdates(fromHeight + 1, 500);
|
|
158
|
+
}
|
|
159
|
+
return indexUpdateLog.filter(u => u.height > fromHeight);
|
|
160
|
+
},
|
|
161
|
+
applyRemoteUpdate: async (update) => {
|
|
162
|
+
console.log(`[Cluster:Apply] ${update.action} ${update.type} ${update.key} (height=${update.height})`);
|
|
163
|
+
// Persist update to DB for durable cluster sync queries (P0-3)
|
|
164
|
+
const plugin = indexer.getPlugin();
|
|
165
|
+
if (plugin?.insertIndexUpdate) {
|
|
166
|
+
plugin.insertIndexUpdate(update);
|
|
167
|
+
}
|
|
168
|
+
// Also keep in memory for quick lookup
|
|
169
|
+
indexUpdateLog.push(update);
|
|
170
|
+
if (indexUpdateLog.length > 10000)
|
|
171
|
+
indexUpdateLog.shift();
|
|
172
|
+
// TODO: when we have full data from cluster peers (not just keys),
|
|
173
|
+
// route to plugin methods: indexProduct/updateProduct/removeProduct/updateSeller/indexReview/indexOrder
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
await clusterSync.start();
|
|
177
|
+
}
|
|
178
|
+
function recordUpdate(update) {
|
|
179
|
+
indexUpdateLog.push(update);
|
|
180
|
+
if (indexUpdateLog.length > 10000)
|
|
181
|
+
indexUpdateLog.shift();
|
|
182
|
+
// Persist to DB for durable cluster sync queries (P0-3)
|
|
183
|
+
const plugin = indexer.getPlugin();
|
|
184
|
+
if (plugin?.insertIndexUpdate) {
|
|
185
|
+
plugin.insertIndexUpdate(update);
|
|
186
|
+
}
|
|
187
|
+
clusterSync?.broadcastUpdate(update);
|
|
188
|
+
}
|
|
189
|
+
// ---- Rate Limiter (PRD 16.22) ----
|
|
190
|
+
const rateLimiter = new Map();
|
|
191
|
+
const RATE_LIMIT_PER_SEC = 10;
|
|
192
|
+
const RATE_WINDOW_MS = 1000;
|
|
193
|
+
// Clean up stale entries every 60 seconds
|
|
194
|
+
setInterval(() => {
|
|
195
|
+
const now = Date.now();
|
|
196
|
+
for (const [ip, entry] of rateLimiter) {
|
|
197
|
+
if (now - entry.windowStart > 60000)
|
|
198
|
+
rateLimiter.delete(ip);
|
|
199
|
+
}
|
|
200
|
+
}, 60000);
|
|
201
|
+
function checkRateLimit(ip) {
|
|
202
|
+
const now = Date.now();
|
|
203
|
+
let entry = rateLimiter.get(ip);
|
|
204
|
+
if (!entry || now - entry.windowStart >= RATE_WINDOW_MS) {
|
|
205
|
+
entry = { count: 1, windowStart: now };
|
|
206
|
+
rateLimiter.set(ip, entry);
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
entry.count++;
|
|
210
|
+
return entry.count <= RATE_LIMIT_PER_SEC;
|
|
211
|
+
}
|
|
212
|
+
function checkGlobalQps() {
|
|
213
|
+
const now = Date.now();
|
|
214
|
+
if (now - globalQpsWindowStart >= GLOBAL_QPS_WINDOW_MS) {
|
|
215
|
+
globalQpsCount = 1;
|
|
216
|
+
globalQpsWindowStart = now;
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
globalQpsCount++;
|
|
220
|
+
return globalQpsCount <= GLOBAL_QPS_LIMIT;
|
|
221
|
+
}
|
|
222
|
+
function checkCircuitBreaker() {
|
|
223
|
+
return Date.now() < circuitBreakerUntil;
|
|
224
|
+
}
|
|
225
|
+
function isBotUserAgent(ua) {
|
|
226
|
+
const botPatterns = /bot|crawler|spider|scraper|curl\/|wget\//i;
|
|
227
|
+
return botPatterns.test(ua);
|
|
228
|
+
}
|
|
229
|
+
// ---- Storage Cleanup (PRD 16.21) ----
|
|
230
|
+
const getPluginDbRaw = () => {
|
|
231
|
+
const plugin = indexer.getPlugin();
|
|
232
|
+
if (plugin?.db)
|
|
233
|
+
return { db: plugin.db, type: 'sqlite' };
|
|
234
|
+
if (plugin?.pool)
|
|
235
|
+
return { db: plugin.pool, type: 'postgresql' };
|
|
236
|
+
return null;
|
|
237
|
+
};
|
|
238
|
+
const cleanupTimer = (() => {
|
|
239
|
+
const dbInfo = getPluginDbRaw();
|
|
240
|
+
if (!dbInfo)
|
|
241
|
+
return null;
|
|
242
|
+
const cleanup = new cleanup_1.StorageCleanup(dbInfo.db, dbInfo.type);
|
|
243
|
+
return cleanup.scheduleDaily(3);
|
|
244
|
+
})();
|
|
245
|
+
// ---- Periodic Consistency Check (PRD 16.19) ----
|
|
246
|
+
setInterval(async () => {
|
|
247
|
+
try {
|
|
248
|
+
const db = getPluginDb();
|
|
249
|
+
if (!db)
|
|
250
|
+
return;
|
|
251
|
+
const checker = new consistency_check_1.ConsistencyChecker(db);
|
|
252
|
+
// Random sample 10 products
|
|
253
|
+
const rows = db
|
|
254
|
+
.prepare('SELECT sku_id, content_hash FROM products ORDER BY RANDOM() LIMIT 10')
|
|
255
|
+
.all();
|
|
256
|
+
if (rows.length === 0)
|
|
257
|
+
return;
|
|
258
|
+
let fixed = 0;
|
|
259
|
+
for (const row of rows) {
|
|
260
|
+
// Basic consistency: check if product has valid content_hash
|
|
261
|
+
if (!row.content_hash || row.content_hash === '') {
|
|
262
|
+
// Mark for re-backfill
|
|
263
|
+
db.prepare("UPDATE products SET content_hash = '' WHERE sku_id = ?").run(row.sku_id);
|
|
264
|
+
fixed++;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (fixed > 0) {
|
|
268
|
+
console.log(`[Consistency] Fixed ${fixed} products out of ${rows.length} sampled`);
|
|
269
|
+
cache_1.searchCache.invalidateAll();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
catch (e) {
|
|
273
|
+
console.error(`[Consistency] Check failed: ${e.message}`);
|
|
274
|
+
}
|
|
275
|
+
}, 5 * 60 * 1000);
|
|
276
|
+
const server = http_1.default.createServer(async (req, res) => {
|
|
277
|
+
// CORS
|
|
278
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
279
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, DELETE, OPTIONS');
|
|
280
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
|
281
|
+
if (req.method === 'OPTIONS') {
|
|
282
|
+
res.writeHead(204);
|
|
283
|
+
res.end();
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
// DDoS: Circuit breaker check (PRD 16.22)
|
|
287
|
+
if (checkCircuitBreaker()) {
|
|
288
|
+
res.writeHead(503, { 'Content-Type': 'application/json' });
|
|
289
|
+
res.end(JSON.stringify({ error: 'Service temporarily unavailable', retry_after: 10 }));
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
// DDoS: Global QPS limit (PRD 16.22)
|
|
293
|
+
if (!checkGlobalQps()) {
|
|
294
|
+
res.writeHead(429, { 'Content-Type': 'application/json' });
|
|
295
|
+
res.end(JSON.stringify({ error: 'Server busy', retry_after: 1 }));
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
// DDoS: User-Agent bot detection (PRD 16.22)
|
|
299
|
+
const ua = req.headers['user-agent'] || '';
|
|
300
|
+
if (isBotUserAgent(ua)) {
|
|
301
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
302
|
+
res.end(JSON.stringify({ error: 'Automated access not allowed' }));
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
// Per-IP rate limit check (PRD 16.22)
|
|
306
|
+
const clientIp = req.socket.remoteAddress?.replace('::ffff:', '') || 'unknown';
|
|
307
|
+
if (!checkRateLimit(clientIp)) {
|
|
308
|
+
res.writeHead(429, { 'Content-Type': 'application/json' });
|
|
309
|
+
res.end(JSON.stringify({ error: 'Too Many Requests', retry_after: 1 }));
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
const url = new URL(req.url || '/', `http://localhost:${HTTP_PORT}`);
|
|
313
|
+
// POST /api/register-p2p - Seller P2P registration
|
|
314
|
+
if (req.method === 'POST' && url.pathname === '/api/register-p2p') {
|
|
315
|
+
let body = '';
|
|
316
|
+
for await (const chunk of req)
|
|
317
|
+
body += chunk;
|
|
318
|
+
try {
|
|
319
|
+
const data = JSON.parse(body);
|
|
320
|
+
p2pRegistry.set(data.seller_address || data.peer_id, data);
|
|
321
|
+
enforcement.recordHeartbeat(data.seller_address || data.peer_id);
|
|
322
|
+
console.log(`[API] Registered P2P: seller=${data.seller_address} peer=${data.peer_id} quic=${data.quic_port}`);
|
|
323
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
324
|
+
res.end(JSON.stringify({ ok: true }));
|
|
325
|
+
}
|
|
326
|
+
catch (e) {
|
|
327
|
+
res.writeHead(400);
|
|
328
|
+
res.end(JSON.stringify({ error: e.message }));
|
|
329
|
+
}
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
// GET /api/seller-p2p/:address - Lookup seller P2P info
|
|
333
|
+
if (req.method === 'GET' && url.pathname.startsWith('/api/seller-p2p/')) {
|
|
334
|
+
const addr = url.pathname.split('/').pop();
|
|
335
|
+
const info = p2pRegistry.get(addr || '');
|
|
336
|
+
if (info) {
|
|
337
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
338
|
+
res.end(JSON.stringify(info));
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
res.writeHead(404);
|
|
342
|
+
res.end(JSON.stringify({ error: 'not found' }));
|
|
343
|
+
}
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
// GET /api/location - Current node location (PRD 16.4)
|
|
347
|
+
if (req.method === 'GET' && url.pathname === '/api/location') {
|
|
348
|
+
const loc = locationManager.getLocation();
|
|
349
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
350
|
+
res.end(JSON.stringify({
|
|
351
|
+
location: loc ? { latitude: loc.latitude, longitude: loc.longitude, city: loc.city, district: loc.district } : null,
|
|
352
|
+
display: loc ? `${(loc.latitude / 1e6).toFixed(4)}, ${(loc.longitude / 1e6).toFixed(4)}` : null,
|
|
353
|
+
}));
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
// GET /api/location/partition - Seller distance partition (PRD 16.4)
|
|
357
|
+
if (req.method === 'GET' && url.pathname === '/api/location/partition') {
|
|
358
|
+
if (!lastPartition) {
|
|
359
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
360
|
+
res.end(JSON.stringify({ status: 'no_data', message: 'Partition not yet computed' }));
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
const pStats = locationManager.getPartitionStats(lastPartition);
|
|
364
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
365
|
+
res.end(JSON.stringify({ stats: pStats, zones: { sameCity: lastPartition.sameCity.length, regional: lastPartition.regional.length, metro: lastPartition.metro.length, remote: lastPartition.remote.length }, method: lastPartition.method }));
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
// GET /api/location/sellers-to-index - Prioritized seller list by distance (PRD 16.4)
|
|
369
|
+
if (req.method === 'GET' && url.pathname === '/api/location/sellers-to-index') {
|
|
370
|
+
if (!lastPartition) {
|
|
371
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
372
|
+
res.end(JSON.stringify({ status: 'no_data', message: 'Partition not yet computed' }));
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
const max = parseInt(url.searchParams.get('max') || '100');
|
|
376
|
+
const sellers = locationManager.getSellersToIndex(lastPartition, max);
|
|
377
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
378
|
+
res.end(JSON.stringify({ count: sellers.length, sellers }));
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
// GET /api/stats - Indexer stats
|
|
382
|
+
if (req.method === 'GET' && url.pathname === '/api/stats') {
|
|
383
|
+
try {
|
|
384
|
+
const stats = await indexer.getStats();
|
|
385
|
+
const loc = locationManager.getLocation();
|
|
386
|
+
stats.location = loc ? { latitude: loc.latitude, longitude: loc.longitude, city: loc.city, display: `${(loc.latitude / 1e6).toFixed(4)}, ${(loc.longitude / 1e6).toFixed(4)}` } : null;
|
|
387
|
+
if (lastPartition) {
|
|
388
|
+
stats.partition = locationManager.getPartitionStats(lastPartition);
|
|
389
|
+
}
|
|
390
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
391
|
+
res.end(JSON.stringify(stats));
|
|
392
|
+
}
|
|
393
|
+
catch (e) {
|
|
394
|
+
res.writeHead(500);
|
|
395
|
+
res.end(JSON.stringify({ error: e.message }));
|
|
396
|
+
}
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
// GET /api/products - Search products (PRD 16.17) with cache + timeout
|
|
400
|
+
if (req.method === 'GET' && (url.pathname === '/api/products' || url.pathname === '/api/v1/products')) {
|
|
401
|
+
try {
|
|
402
|
+
const p = url.searchParams;
|
|
403
|
+
const query = {};
|
|
404
|
+
// keyword
|
|
405
|
+
if (p.get('keyword'))
|
|
406
|
+
query.keyword = p.get('keyword');
|
|
407
|
+
// category filter
|
|
408
|
+
if (p.get('category'))
|
|
409
|
+
query.category = p.get('category');
|
|
410
|
+
// buyer location + search radius (lat/lon in degrees, radius in km)
|
|
411
|
+
const lat = parseFloat(p.get('lat') || '');
|
|
412
|
+
const lon = parseFloat(p.get('lon') || '');
|
|
413
|
+
const radius = parseFloat(p.get('radius') || '50');
|
|
414
|
+
if (!isNaN(lat) && !isNaN(lon)) {
|
|
415
|
+
query.location = {
|
|
416
|
+
latitude: Math.round(lat * 1e6),
|
|
417
|
+
longitude: Math.round(lon * 1e6),
|
|
418
|
+
radiusKm: radius,
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
// sort: trust_score/price_asc/price_desc/distance/newest
|
|
422
|
+
const sort = p.get('sort') || '';
|
|
423
|
+
if (sort === 'trust_score')
|
|
424
|
+
query.sortBy = 'relevance';
|
|
425
|
+
else if (sort === 'price_asc')
|
|
426
|
+
query.sortBy = 'price_asc';
|
|
427
|
+
else if (sort === 'price_desc')
|
|
428
|
+
query.sortBy = 'price_desc';
|
|
429
|
+
else if (sort === 'distance')
|
|
430
|
+
query.sortBy = 'distance';
|
|
431
|
+
else if (sort === 'newest')
|
|
432
|
+
query.sortBy = 'newest';
|
|
433
|
+
// minimum seller credit
|
|
434
|
+
const sellerMinCredit = parseInt(p.get('seller_min_credit') || '');
|
|
435
|
+
if (!isNaN(sellerMinCredit))
|
|
436
|
+
query.sellerMinCredit = sellerMinCredit;
|
|
437
|
+
// pagination
|
|
438
|
+
const page = parseInt(p.get('page') || '1');
|
|
439
|
+
const pageSize = parseInt(p.get('page_size') || '20');
|
|
440
|
+
if (!isNaN(page) && page > 0)
|
|
441
|
+
query.page = page;
|
|
442
|
+
if (!isNaN(pageSize) && pageSize > 0)
|
|
443
|
+
query.pageSize = Math.min(pageSize, 100);
|
|
444
|
+
// brand & insurance filters
|
|
445
|
+
if (p.get('has_brand') === 'true' || p.get('has_brand') === '1')
|
|
446
|
+
query.hasBrand = true;
|
|
447
|
+
if (p.get('has_insurance') === 'true' || p.get('has_insurance') === '1')
|
|
448
|
+
query.hasInsurance = true;
|
|
449
|
+
// price range (optional, not in PRD but already supported)
|
|
450
|
+
const priceMin = parseInt(p.get('price_min') || '');
|
|
451
|
+
const priceMax = parseInt(p.get('price_max') || '');
|
|
452
|
+
if (!isNaN(priceMin))
|
|
453
|
+
query.priceMin = priceMin;
|
|
454
|
+
if (!isNaN(priceMax))
|
|
455
|
+
query.priceMax = priceMax;
|
|
456
|
+
// Check cache first
|
|
457
|
+
const cached = cache_1.searchCache.get(query);
|
|
458
|
+
if (cached) {
|
|
459
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'X-Cache': 'HIT' });
|
|
460
|
+
res.end(JSON.stringify(cached));
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
// Search with 5-second timeout (PRD 16.22)
|
|
464
|
+
const results = await Promise.race([
|
|
465
|
+
indexer.search(query),
|
|
466
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error('Search timeout')), 5000)),
|
|
467
|
+
]);
|
|
468
|
+
// Cache the result
|
|
469
|
+
cache_1.searchCache.set(query, results);
|
|
470
|
+
res.writeHead(200, { 'Content-Type': 'application/json', 'X-Cache': 'MISS' });
|
|
471
|
+
res.end(JSON.stringify(results));
|
|
472
|
+
consecutiveErrors = 0; // reset on success
|
|
473
|
+
}
|
|
474
|
+
catch (e) {
|
|
475
|
+
consecutiveErrors++;
|
|
476
|
+
// Circuit breaker: pause service if too many consecutive errors
|
|
477
|
+
if (consecutiveErrors > 50) {
|
|
478
|
+
circuitBreakerUntil = Date.now() + 10000;
|
|
479
|
+
console.error(`[DDoS] Circuit breaker triggered after ${consecutiveErrors} consecutive errors. Pausing for 10s.`);
|
|
480
|
+
consecutiveErrors = 0;
|
|
481
|
+
}
|
|
482
|
+
// Timeout: return partial results hint
|
|
483
|
+
if (e.message === 'Search timeout') {
|
|
484
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
485
|
+
res.end(JSON.stringify({ total: 0, results: [], meta: { queryTimeMs: 5000, indexerName: 'timeout', coverage: 'partial', timedOut: true } }));
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
res.writeHead(500);
|
|
489
|
+
res.end(JSON.stringify({ error: e.message }));
|
|
490
|
+
}
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
// ---- Cluster Sync API (Layer 2/3) ----
|
|
494
|
+
// GET /api/cluster/info - Node info for cluster discovery
|
|
495
|
+
if (req.method === 'GET' && url.pathname === '/api/cluster/info') {
|
|
496
|
+
try {
|
|
497
|
+
const stats = await indexer.getStats();
|
|
498
|
+
const merkleRoot = await computeMerkleRoot();
|
|
499
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
500
|
+
res.end(JSON.stringify({
|
|
501
|
+
tier: TIER,
|
|
502
|
+
syncedHeight: stats.syncedHeight,
|
|
503
|
+
merkleRoot,
|
|
504
|
+
nodeCount: clusterSync?.getClusterStatus().nodeCount || 0,
|
|
505
|
+
uptime: stats.uptimeSeconds,
|
|
506
|
+
}));
|
|
507
|
+
}
|
|
508
|
+
catch (e) {
|
|
509
|
+
res.writeHead(500);
|
|
510
|
+
res.end(JSON.stringify({ error: e.message }));
|
|
511
|
+
}
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
// POST /api/cluster/sync - Pull index updates
|
|
515
|
+
if (req.method === 'POST' && url.pathname === '/api/cluster/sync') {
|
|
516
|
+
let body = '';
|
|
517
|
+
for await (const chunk of req)
|
|
518
|
+
body += chunk;
|
|
519
|
+
try {
|
|
520
|
+
const req2 = JSON.parse(body);
|
|
521
|
+
const stats = await indexer.getStats();
|
|
522
|
+
// P0-3: Query from DB instead of in-memory array
|
|
523
|
+
const plugin = indexer.getPlugin();
|
|
524
|
+
const updates = plugin?.getIndexUpdates
|
|
525
|
+
? plugin.getIndexUpdates(req2.fromHeight || 0, req2.limit || 500)
|
|
526
|
+
: indexUpdateLog.filter(u => u.height >= (req2.fromHeight || 0)).slice(0, req2.limit || 500);
|
|
527
|
+
const merkleRoot = await computeMerkleRoot();
|
|
528
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
529
|
+
res.end(JSON.stringify({ updates, currentHeight: stats.syncedHeight, merkleRoot, nodeCount: clusterSync?.getClusterStatus().nodeCount || 0 }));
|
|
530
|
+
}
|
|
531
|
+
catch (e) {
|
|
532
|
+
res.writeHead(500);
|
|
533
|
+
res.end(JSON.stringify({ error: e.message }));
|
|
534
|
+
}
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
// POST /api/cluster/gossip - Receive gossip updates
|
|
538
|
+
if (req.method === 'POST' && url.pathname === '/api/cluster/gossip') {
|
|
539
|
+
let body = '';
|
|
540
|
+
for await (const chunk of req)
|
|
541
|
+
body += chunk;
|
|
542
|
+
try {
|
|
543
|
+
const msg = JSON.parse(body);
|
|
544
|
+
console.log(`[Cluster:Gossip] Received ${msg.updates?.length || 0} updates from ${msg.from} (height=${msg.height})`);
|
|
545
|
+
// Merge updates we don't have — persist to DB (P0-3)
|
|
546
|
+
const plugin = indexer.getPlugin();
|
|
547
|
+
if (msg.updates) {
|
|
548
|
+
for (const u of msg.updates) {
|
|
549
|
+
if (!indexUpdateLog.find(e => e.key === u.key && e.height === u.height)) {
|
|
550
|
+
indexUpdateLog.push(u);
|
|
551
|
+
if (plugin?.insertIndexUpdate)
|
|
552
|
+
plugin.insertIndexUpdate(u);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
557
|
+
res.end(JSON.stringify({ ok: true }));
|
|
558
|
+
}
|
|
559
|
+
catch (e) {
|
|
560
|
+
res.writeHead(400);
|
|
561
|
+
res.end(JSON.stringify({ error: e.message }));
|
|
562
|
+
}
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
// POST /api/cluster/push - Receive pushed updates
|
|
566
|
+
if (req.method === 'POST' && url.pathname === '/api/cluster/push') {
|
|
567
|
+
let body = '';
|
|
568
|
+
for await (const chunk of req)
|
|
569
|
+
body += chunk;
|
|
570
|
+
try {
|
|
571
|
+
const msg = JSON.parse(body);
|
|
572
|
+
const plugin = indexer.getPlugin();
|
|
573
|
+
if (msg.updates) {
|
|
574
|
+
for (const u of msg.updates) {
|
|
575
|
+
if (!indexUpdateLog.find(e => e.key === u.key && e.height === u.height)) {
|
|
576
|
+
indexUpdateLog.push(u);
|
|
577
|
+
if (plugin?.insertIndexUpdate)
|
|
578
|
+
plugin.insertIndexUpdate(u);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
console.log(`[Cluster:Push] Received ${msg.updates.length} updates from ${msg.from}`);
|
|
582
|
+
}
|
|
583
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
584
|
+
res.end(JSON.stringify({ ok: true }));
|
|
585
|
+
}
|
|
586
|
+
catch (e) {
|
|
587
|
+
res.writeHead(400);
|
|
588
|
+
res.end(JSON.stringify({ error: e.message }));
|
|
589
|
+
}
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
// GET /api/cluster/merkle-proof - Merkle proof for tier 3 verification
|
|
593
|
+
if (req.method === 'GET' && url.pathname === '/api/cluster/merkle-proof') {
|
|
594
|
+
const merkleRoot = await computeMerkleRoot();
|
|
595
|
+
// P0-3: Query recent updates from DB if available
|
|
596
|
+
const plugin = indexer.getPlugin();
|
|
597
|
+
const recentUpdates = plugin?.getIndexUpdates
|
|
598
|
+
? plugin.getIndexUpdates(0, 100).reverse()
|
|
599
|
+
: indexUpdateLog.slice(-100);
|
|
600
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
601
|
+
res.end(JSON.stringify({
|
|
602
|
+
root: merkleRoot,
|
|
603
|
+
entries: recentUpdates.map((u) => ({ key: u.key, hash: u.hash, height: u.height })),
|
|
604
|
+
}));
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
// GET /api/cluster/status - Cluster overview
|
|
608
|
+
if (req.method === 'GET' && url.pathname === '/api/cluster/status') {
|
|
609
|
+
const cluster = clusterSync?.getClusterStatus();
|
|
610
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
611
|
+
res.end(JSON.stringify(cluster || { nodeCount: 0, healthyNodes: 0, tier: TIER, nodes: [], pendingUpdates: 0 }));
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
// ---- Enforcement API (PRD 16.8) ----
|
|
615
|
+
// GET /api/enforcement/compliance - Seller compliance status
|
|
616
|
+
if (req.method === 'GET' && url.pathname === '/api/enforcement/compliance') {
|
|
617
|
+
try {
|
|
618
|
+
const stats = enforcement.getStats();
|
|
619
|
+
const nonCompliant = enforcement.getNonCompliantSellers();
|
|
620
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
621
|
+
res.end(JSON.stringify({ stats, nonCompliant }));
|
|
622
|
+
}
|
|
623
|
+
catch (e) {
|
|
624
|
+
res.writeHead(500);
|
|
625
|
+
res.end(JSON.stringify({ error: e.message }));
|
|
626
|
+
}
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
// POST /api/backfill/trigger - Trigger content backfill (P1-5)
|
|
630
|
+
if (req.method === 'POST' && url.pathname === '/api/backfill/trigger') {
|
|
631
|
+
const sellerP2PResolver = async (sellerAddress) => {
|
|
632
|
+
const p2pInfo = indexer.getPlugin().getSellerP2P(sellerAddress);
|
|
633
|
+
if (!p2pInfo || !p2pInfo.ip)
|
|
634
|
+
return null;
|
|
635
|
+
const port = p2pInfo.httpPort || 9527;
|
|
636
|
+
return `http://${p2pInfo.ip}:${port}`;
|
|
637
|
+
};
|
|
638
|
+
try {
|
|
639
|
+
const result = await backfiller.backfillAll(sellerP2PResolver);
|
|
640
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
641
|
+
res.end(JSON.stringify(result));
|
|
642
|
+
}
|
|
643
|
+
catch (e) {
|
|
644
|
+
res.writeHead(500);
|
|
645
|
+
res.end(JSON.stringify({ error: e.message }));
|
|
646
|
+
}
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
// ---- Search API v1 additions (PRD 16.17) ----
|
|
650
|
+
// GET /api/v1/suggest?q=keyword (also /api/suggest) — Search autocomplete
|
|
651
|
+
if (req.method === 'GET' && (url.pathname === '/api/v1/suggest' || url.pathname === '/api/suggest')) {
|
|
652
|
+
const q = url.searchParams.get('q') || '';
|
|
653
|
+
if (!q) {
|
|
654
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
655
|
+
res.end(JSON.stringify({ suggestions: [] }));
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
try {
|
|
659
|
+
const db = getPluginDb();
|
|
660
|
+
if (!db) {
|
|
661
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
662
|
+
res.end(JSON.stringify({ suggestions: [] }));
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
const rows = db.prepare("SELECT DISTINCT title FROM products WHERE title LIKE ? AND status = 'active' LIMIT 10").all(`%${q}%`);
|
|
666
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
667
|
+
res.end(JSON.stringify({ suggestions: rows.map(r => r.title) }));
|
|
668
|
+
}
|
|
669
|
+
catch (e) {
|
|
670
|
+
res.writeHead(500);
|
|
671
|
+
res.end(JSON.stringify({ error: e.message }));
|
|
672
|
+
}
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
// POST /api/v1/follow (also /api/follow) — Follow a seller
|
|
676
|
+
if (req.method === 'POST' && (url.pathname === '/api/v1/follow' || url.pathname === '/api/follow')) {
|
|
677
|
+
let body = '';
|
|
678
|
+
for await (const chunk of req)
|
|
679
|
+
body += chunk;
|
|
680
|
+
try {
|
|
681
|
+
const { buyer, seller_address } = JSON.parse(body);
|
|
682
|
+
if (!buyer || !seller_address) {
|
|
683
|
+
res.writeHead(400);
|
|
684
|
+
res.end(JSON.stringify({ error: 'buyer and seller_address required' }));
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
if (!followStore.has(buyer))
|
|
688
|
+
followStore.set(buyer, new Set());
|
|
689
|
+
followStore.get(buyer).add(seller_address);
|
|
690
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
691
|
+
res.end(JSON.stringify({ ok: true }));
|
|
692
|
+
}
|
|
693
|
+
catch (e) {
|
|
694
|
+
res.writeHead(400);
|
|
695
|
+
res.end(JSON.stringify({ error: e.message }));
|
|
696
|
+
}
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
// DELETE /api/v1/follow (also /api/follow) — Unfollow a seller
|
|
700
|
+
if (req.method === 'DELETE' && (url.pathname === '/api/v1/follow' || url.pathname === '/api/follow')) {
|
|
701
|
+
let body = '';
|
|
702
|
+
for await (const chunk of req)
|
|
703
|
+
body += chunk;
|
|
704
|
+
try {
|
|
705
|
+
const { buyer, seller_address } = JSON.parse(body);
|
|
706
|
+
if (!buyer || !seller_address) {
|
|
707
|
+
res.writeHead(400);
|
|
708
|
+
res.end(JSON.stringify({ error: 'buyer and seller_address required' }));
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
followStore.get(buyer)?.delete(seller_address);
|
|
712
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
713
|
+
res.end(JSON.stringify({ ok: true }));
|
|
714
|
+
}
|
|
715
|
+
catch (e) {
|
|
716
|
+
res.writeHead(400);
|
|
717
|
+
res.end(JSON.stringify({ error: e.message }));
|
|
718
|
+
}
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
// GET /api/v1/following (also /api/following) — Get my following list
|
|
722
|
+
if (req.method === 'GET' && (url.pathname === '/api/v1/following' || url.pathname === '/api/following')) {
|
|
723
|
+
const buyer = url.searchParams.get('buyer') || '';
|
|
724
|
+
const sellers = followStore.get(buyer);
|
|
725
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
726
|
+
res.end(JSON.stringify({ following: sellers ? Array.from(sellers) : [] }));
|
|
727
|
+
return;
|
|
728
|
+
}
|
|
729
|
+
// GET /api/v1/followers?seller=xxx (also /api/followers) — Get seller's followers
|
|
730
|
+
if (req.method === 'GET' && (url.pathname === '/api/v1/followers' || url.pathname === '/api/followers')) {
|
|
731
|
+
const seller = url.searchParams.get('seller') || '';
|
|
732
|
+
const followers = [];
|
|
733
|
+
for (const [buyer, sellers] of followStore) {
|
|
734
|
+
if (sellers.has(seller))
|
|
735
|
+
followers.push(buyer);
|
|
736
|
+
}
|
|
737
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
738
|
+
res.end(JSON.stringify({ followers }));
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
// GET /api/v1/follower_count?seller=xxx (also /api/follower_count) — Get seller's follower count
|
|
742
|
+
if (req.method === 'GET' && (url.pathname === '/api/v1/follower_count' || url.pathname === '/api/follower_count')) {
|
|
743
|
+
const seller = url.searchParams.get('seller') || '';
|
|
744
|
+
let count = 0;
|
|
745
|
+
for (const [, sellers] of followStore) {
|
|
746
|
+
if (sellers.has(seller))
|
|
747
|
+
count++;
|
|
748
|
+
}
|
|
749
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
750
|
+
res.end(JSON.stringify({ seller, follower_count: count }));
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
// GET /api/v1/follower_prices (also /api/follower_prices) — Get follower-only prices
|
|
754
|
+
if (req.method === 'GET' && (url.pathname === '/api/v1/follower_prices' || url.pathname === '/api/follower_prices')) {
|
|
755
|
+
const seller = url.searchParams.get('seller') || '';
|
|
756
|
+
const prices = followerPrices.get(seller);
|
|
757
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
758
|
+
res.end(JSON.stringify({ seller, prices: prices ? Object.fromEntries(prices) : {} }));
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
// GET /api/v1/buyer_credit?buyer=xxx (also /api/buyer_credit) — Get buyer credit score
|
|
762
|
+
if (req.method === 'GET' && (url.pathname === '/api/v1/buyer_credit' || url.pathname === '/api/buyer_credit')) {
|
|
763
|
+
const buyer = url.searchParams.get('buyer') || '';
|
|
764
|
+
const credit = buyerCreditStore.get(buyer);
|
|
765
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
766
|
+
res.end(JSON.stringify({ buyer, credit: credit || { score: 0, updatedAt: 0 } }));
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
// GET /api/v1/credit_history?buyer=xxx (also /api/credit_history) — Get buyer credit history
|
|
770
|
+
if (req.method === 'GET' && (url.pathname === '/api/v1/credit_history' || url.pathname === '/api/credit_history')) {
|
|
771
|
+
const buyer = url.searchParams.get('buyer') || '';
|
|
772
|
+
const history = creditHistoryStore.get(buyer);
|
|
773
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
774
|
+
res.end(JSON.stringify({ buyer, history: history || [] }));
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
// GET /api/v1/buyer_requirement?seller=xxx (also /api/buyer_requirement) — Get seller's buyer requirements
|
|
778
|
+
if (req.method === 'GET' && (url.pathname === '/api/v1/buyer_requirement' || url.pathname === '/api/buyer_requirement')) {
|
|
779
|
+
const seller = url.searchParams.get('seller') || '';
|
|
780
|
+
const req = sellerRequirements.get(seller);
|
|
781
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
782
|
+
res.end(JSON.stringify({ seller, requirements: req || { minCredit: 0, minOrders: 0, inviteOnly: false } }));
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
785
|
+
// GET /api/v1/can_buy?seller=xxx&product=xxx&buyer=xxx (also /api/can_buy) — Check if buyer can purchase
|
|
786
|
+
if (req.method === 'GET' && (url.pathname === '/api/v1/can_buy' || url.pathname === '/api/can_buy')) {
|
|
787
|
+
const seller = url.searchParams.get('seller') || '';
|
|
788
|
+
const buyer = url.searchParams.get('buyer') || '';
|
|
789
|
+
const requirements = sellerRequirements.get(seller);
|
|
790
|
+
const buyerCredit = buyerCreditStore.get(buyer);
|
|
791
|
+
let canBuy = true;
|
|
792
|
+
const reasons = [];
|
|
793
|
+
if (requirements) {
|
|
794
|
+
if (requirements.inviteOnly) {
|
|
795
|
+
const isFollowing = followStore.get(buyer)?.has(seller);
|
|
796
|
+
if (!isFollowing) {
|
|
797
|
+
canBuy = false;
|
|
798
|
+
reasons.push('invite_only');
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
if (requirements.minCredit > 0) {
|
|
802
|
+
const score = buyerCredit?.score || 0;
|
|
803
|
+
if (score < requirements.minCredit) {
|
|
804
|
+
canBuy = false;
|
|
805
|
+
reasons.push(`credit_too_low:${score}<${requirements.minCredit}`);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
if (requirements.minOrders > 0) {
|
|
809
|
+
// Check buyer order count from DB
|
|
810
|
+
try {
|
|
811
|
+
const db = getPluginDb();
|
|
812
|
+
if (db) {
|
|
813
|
+
const row = db.prepare('SELECT COUNT(*) as c FROM orders WHERE buyer = ?').get(buyer);
|
|
814
|
+
if ((row?.c || 0) < requirements.minOrders) {
|
|
815
|
+
canBuy = false;
|
|
816
|
+
reasons.push(`orders_too_few:${row?.c || 0}<${requirements.minOrders}`);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
catch { /* skip check */ }
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
824
|
+
res.end(JSON.stringify({ can_buy: canBuy, seller, buyer, reasons }));
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
// ---- Backward-compatible /api/v1 aliases for existing endpoints ----
|
|
828
|
+
// GET /api/v1/stats
|
|
829
|
+
if (req.method === 'GET' && url.pathname === '/api/v1/stats') {
|
|
830
|
+
try {
|
|
831
|
+
const stats = await indexer.getStats();
|
|
832
|
+
const loc = locationManager.getLocation();
|
|
833
|
+
stats.location = loc ? { latitude: loc.latitude, longitude: loc.longitude, city: loc.city, display: `${(loc.latitude / 1e6).toFixed(4)}, ${(loc.longitude / 1e6).toFixed(4)}` } : null;
|
|
834
|
+
if (lastPartition) {
|
|
835
|
+
stats.partition = locationManager.getPartitionStats(lastPartition);
|
|
836
|
+
}
|
|
837
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
838
|
+
res.end(JSON.stringify(stats));
|
|
839
|
+
}
|
|
840
|
+
catch (e) {
|
|
841
|
+
res.writeHead(500);
|
|
842
|
+
res.end(JSON.stringify({ error: e.message }));
|
|
843
|
+
}
|
|
844
|
+
return;
|
|
845
|
+
}
|
|
846
|
+
// GET /api/v1/location
|
|
847
|
+
if (req.method === 'GET' && url.pathname === '/api/v1/location') {
|
|
848
|
+
const loc = locationManager.getLocation();
|
|
849
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
850
|
+
res.end(JSON.stringify({
|
|
851
|
+
location: loc ? { latitude: loc.latitude, longitude: loc.longitude, city: loc.city, district: loc.district } : null,
|
|
852
|
+
display: loc ? `${(loc.latitude / 1e6).toFixed(4)}, ${(loc.longitude / 1e6).toFixed(4)}` : null,
|
|
853
|
+
}));
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
res.writeHead(404);
|
|
857
|
+
res.end('Not found');
|
|
858
|
+
});
|
|
859
|
+
server.listen(HTTP_PORT, () => {
|
|
860
|
+
console.log(`[API] HTTP server listening on :${HTTP_PORT}`);
|
|
861
|
+
});
|
|
862
|
+
}).catch((err) => {
|
|
863
|
+
console.error('Failed to start:', err);
|
|
864
|
+
process.exit(1);
|
|
865
|
+
});
|
|
866
|
+
let clusterSync = null;
|
|
867
|
+
// ---- Follow System (in-memory, PRD 16.17) ----
|
|
868
|
+
const followStore = new Map(); // buyer -> Set<seller>
|
|
869
|
+
// follower_prices: seller -> Map<skuId, { price, description }>
|
|
870
|
+
const followerPrices = new Map();
|
|
871
|
+
// buyer_credit: buyer -> { score, history }
|
|
872
|
+
const buyerCreditStore = new Map();
|
|
873
|
+
const creditHistoryStore = new Map();
|
|
874
|
+
// seller_requirements: seller -> { minCredit, minOrders, inviteOnly }
|
|
875
|
+
const sellerRequirements = new Map();
|
|
876
|
+
// ---- DDoS Protection State (PRD 16.22) ----
|
|
877
|
+
let globalQpsCount = 0;
|
|
878
|
+
let globalQpsWindowStart = Date.now();
|
|
879
|
+
const GLOBAL_QPS_LIMIT = 100;
|
|
880
|
+
const GLOBAL_QPS_WINDOW_MS = 1000;
|
|
881
|
+
let consecutiveErrors = 0;
|
|
882
|
+
let circuitBreakerUntil = 0; // timestamp when circuit breaker expires
|
|
883
|
+
process.on('SIGINT', async () => {
|
|
884
|
+
console.log('\nShutting down...');
|
|
885
|
+
await clusterSync?.stop();
|
|
886
|
+
await indexer.stop();
|
|
887
|
+
process.exit(0);
|
|
888
|
+
});
|
|
889
|
+
//# sourceMappingURL=run.js.map
|