web-agent-bridge 3.0.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +51 -0
  2. package/README.ar.md +79 -0
  3. package/README.md +104 -4
  4. package/package.json +2 -1
  5. package/public/.well-known/ai-plugin.json +28 -0
  6. package/public/agent-workspace.html +3 -1
  7. package/public/ai.html +5 -3
  8. package/public/api.html +412 -0
  9. package/public/browser.html +4 -2
  10. package/public/cookies.html +4 -2
  11. package/public/dashboard.html +5 -3
  12. package/public/demo.html +1770 -1
  13. package/public/docs.html +6 -4
  14. package/public/growth.html +463 -0
  15. package/public/index.html +982 -738
  16. package/public/llms-full.txt +52 -1
  17. package/public/llms.txt +39 -0
  18. package/public/login.html +6 -4
  19. package/public/premium-dashboard.html +7 -5
  20. package/public/premium.html +6 -4
  21. package/public/privacy.html +4 -2
  22. package/public/register.html +6 -4
  23. package/public/score.html +263 -0
  24. package/public/terms.html +4 -2
  25. package/sdk/index.js +7 -1
  26. package/sdk/package.json +12 -1
  27. package/server/index.js +427 -375
  28. package/server/middleware/rateLimits.js +3 -3
  29. package/server/migrations/006_growth_suite.sql +138 -0
  30. package/server/routes/agent-workspace.js +162 -0
  31. package/server/routes/demo-showcase.js +332 -0
  32. package/server/routes/discovery.js +18 -7
  33. package/server/routes/gateway.js +157 -0
  34. package/server/routes/growth.js +962 -0
  35. package/server/routes/universal.js +9 -1
  36. package/server/routes/wab-api.js +16 -6
  37. package/server/services/api-key-engine.js +261 -0
  38. package/server/services/lfd.js +22 -3
  39. package/server/services/modules/affiliate-intelligence.js +93 -0
  40. package/server/services/modules/agent-firewall.js +90 -0
  41. package/server/services/modules/bounty.js +89 -0
  42. package/server/services/modules/collective-bargaining.js +92 -0
  43. package/server/services/modules/dark-pattern.js +66 -0
  44. package/server/services/modules/gov-intelligence.js +45 -0
  45. package/server/services/modules/neural.js +55 -0
  46. package/server/services/modules/notary.js +49 -0
  47. package/server/services/modules/price-time-machine.js +86 -0
  48. package/server/services/modules/protocol.js +104 -0
  49. package/server/services/premium.js +1 -1
  50. package/server/services/price-intelligence.js +2 -1
  51. package/server/services/vision.js +2 -2
@@ -0,0 +1,92 @@
1
+ /**
2
+ * WAB Collective Bargaining (04-collective-bargaining) — PUBLIC JOIN API, PRIVATE MATCHING ENGINE
3
+ * Groups buyers to negotiate bulk discounts.
4
+ * Join interface is open, matching engine is closed.
5
+ *
6
+ * Powered by WAB — Web Agent Bridge
7
+ * https://www.webagentbridge.com
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ const crypto = require('crypto');
13
+
14
+ const demandPools = new Map();
15
+ const NEGOTIATION_THRESHOLDS = {
16
+ electronics: { minBuyers: 10, targetDiscount: 0.15 },
17
+ travel: { minBuyers: 5, targetDiscount: 0.20 },
18
+ fashion: { minBuyers: 20, targetDiscount: 0.25 },
19
+ software: { minBuyers: 50, targetDiscount: 0.30 },
20
+ default: { minBuyers: 15, targetDiscount: 0.15 },
21
+ };
22
+
23
+ let matchingEngine;
24
+ try { matchingEngine = require('./bargaining-engine'); } catch { matchingEngine = null; }
25
+
26
+ function createRouter(express) {
27
+ const router = express.Router();
28
+
29
+ router.post('/join', (req, res) => {
30
+ const { platform, product_id, product_name, category, current_price, currency, max_price } = req.body;
31
+ if (!platform || !product_id || !current_price) {
32
+ return res.status(400).json({ error: 'platform, product_id, and current_price required' });
33
+ }
34
+
35
+ const poolKey = `${platform}:${product_id}`;
36
+ if (!demandPools.has(poolKey)) {
37
+ const cat = category || 'default';
38
+ const threshold = NEGOTIATION_THRESHOLDS[cat] || NEGOTIATION_THRESHOLDS.default;
39
+ demandPools.set(poolKey, {
40
+ id: 'POOL-' + crypto.randomBytes(8).toString('hex').toUpperCase(),
41
+ platform, product_id, product_name: product_name || product_id,
42
+ category: cat, current_price: parseFloat(current_price), currency: currency || 'USD',
43
+ target_price: parseFloat((current_price * (1 - threshold.targetDiscount)).toFixed(2)),
44
+ target_discount_pct: Math.round(threshold.targetDiscount * 100),
45
+ min_buyers: threshold.minBuyers, members: 0, status: 'OPEN',
46
+ created_at: new Date().toISOString(),
47
+ });
48
+ }
49
+
50
+ const pool = demandPools.get(poolKey);
51
+ if (pool.status !== 'OPEN') return res.status(400).json({ error: 'Pool is not open' });
52
+ pool.members++;
53
+
54
+ if (matchingEngine && pool.members >= pool.min_buyers) {
55
+ const deal = matchingEngine.negotiate(pool);
56
+ pool.status = deal ? 'DEAL_REACHED' : 'NEGOTIATING';
57
+ }
58
+
59
+ res.json({
60
+ success: true, pool_id: pool.id, member_count: pool.members, status: pool.status,
61
+ progress_pct: Math.min(100, Math.round(pool.members / pool.min_buyers * 100)),
62
+ members_needed: Math.max(0, pool.min_buyers - pool.members),
63
+ target_price: pool.target_price, target_discount_pct: pool.target_discount_pct,
64
+ });
65
+ });
66
+
67
+ router.get('/pools', (req, res) => {
68
+ const pools = Array.from(demandPools.values()).map(p => ({
69
+ pool_id: p.id, platform: p.platform, product_name: p.product_name,
70
+ current_price: p.current_price, target_price: p.target_price,
71
+ members: p.members, min_buyers: p.min_buyers, status: p.status,
72
+ progress_pct: Math.min(100, Math.round(p.members / p.min_buyers * 100)),
73
+ }));
74
+ res.json({ total: pools.length, pools: pools.filter(p => p.status === 'OPEN').slice(0, 50) });
75
+ });
76
+
77
+ router.get('/pool/:id', (req, res) => {
78
+ const pool = Array.from(demandPools.values()).find(p => p.id === req.params.id);
79
+ if (!pool) return res.status(404).json({ error: 'Pool not found' });
80
+ res.json(pool);
81
+ });
82
+
83
+ router.get('/stats', (req, res) => {
84
+ let totalMembers = 0, activePoolsCount = 0;
85
+ for (const p of demandPools.values()) { totalMembers += p.members; if (p.status === 'OPEN') activePoolsCount++; }
86
+ res.json({ total_pools: demandPools.size, active_pools: activePoolsCount, total_participants: totalMembers });
87
+ });
88
+
89
+ return router;
90
+ }
91
+
92
+ module.exports = { createRouter };
@@ -0,0 +1,66 @@
1
+ /**
2
+ * WAB Dark Pattern Detector (03-dark-pattern) — FULLY CLOSED
3
+ * DSA compliance engine detects all 17 OECD dark patterns.
4
+ * All detection rules are proprietary.
5
+ *
6
+ * Powered by WAB — Web Agent Bridge
7
+ * https://www.webagentbridge.com
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ let darkPatternEngine;
13
+ try { darkPatternEngine = require('./dark-pattern-engine'); } catch { darkPatternEngine = null; }
14
+
15
+ function createRouter(express) {
16
+ const router = express.Router();
17
+
18
+ router.post('/audit', async (req, res) => {
19
+ const { url: targetUrl } = req.body;
20
+ if (!targetUrl) return res.status(400).json({ error: 'url required' });
21
+ if (!darkPatternEngine) return res.status(503).json({ error: 'Dark pattern engine not available', code: 'MODULE_UNAVAILABLE' });
22
+ try {
23
+ const report = await darkPatternEngine.generateReport(targetUrl);
24
+ res.json(report);
25
+ } catch (e) { res.status(500).json({ error: e.message }); }
26
+ });
27
+
28
+ router.post('/scan', (req, res) => {
29
+ const { html, page_url } = req.body;
30
+ if (!html) return res.status(400).json({ error: 'html content required' });
31
+ if (!darkPatternEngine) return res.status(503).json({ error: 'Dark pattern engine not available', code: 'MODULE_UNAVAILABLE' });
32
+ const result = darkPatternEngine.scanContent(html, page_url);
33
+ res.json(result);
34
+ });
35
+
36
+ router.get('/patterns', (req, res) => {
37
+ res.json({ total: 17, categories: [
38
+ { id: 'DP001', name: 'False Urgency', severity: 'HIGH', dsa_article: 'Article 25(1)(a)' },
39
+ { id: 'DP002', name: 'Scarcity Manipulation', severity: 'HIGH', dsa_article: 'Article 25(1)(a)' },
40
+ { id: 'DP003', name: 'Hidden Costs', severity: 'CRITICAL', dsa_article: 'Article 25(1)(b)' },
41
+ { id: 'DP004', name: 'Trick Question', severity: 'HIGH', dsa_article: 'Article 25(1)(c)' },
42
+ { id: 'DP005', name: 'Roach Motel', severity: 'CRITICAL', dsa_article: 'Article 25(1)(d)' },
43
+ { id: 'DP006', name: 'Confirmshaming', severity: 'MEDIUM', dsa_article: 'Article 25(1)(a)' },
44
+ { id: 'DP007', name: 'Forced Continuity', severity: 'CRITICAL', dsa_article: 'Article 25(1)(b)' },
45
+ { id: 'DP008', name: 'Misdirection', severity: 'MEDIUM', dsa_article: 'Article 25(1)(a)' },
46
+ { id: 'DP009', name: 'Disguised Ads', severity: 'HIGH', dsa_article: 'Article 26' },
47
+ { id: 'DP010', name: 'Nagging', severity: 'LOW', dsa_article: 'Article 25(1)(a)' },
48
+ { id: 'DP011', name: 'Basket Sneaking', severity: 'CRITICAL', dsa_article: 'Article 25(1)(b)' },
49
+ { id: 'DP012', name: 'Bait and Switch', severity: 'CRITICAL', dsa_article: 'Article 25(1)(b)' },
50
+ { id: 'DP013', name: 'Privacy Zuckering', severity: 'HIGH', dsa_article: 'Article 25(1)(c)' },
51
+ { id: 'DP014', name: 'Fake Social Proof', severity: 'HIGH', dsa_article: 'Article 25(1)(a)' },
52
+ { id: 'DP015', name: 'Interface Interference', severity: 'MEDIUM', dsa_article: 'Article 25(1)(a)' },
53
+ { id: 'DP016', name: 'Drip Pricing', severity: 'HIGH', dsa_article: 'Article 25(1)(b)' },
54
+ { id: 'DP017', name: 'Disguised Subscription', severity: 'CRITICAL', dsa_article: 'Article 25(1)(b)' },
55
+ ]});
56
+ });
57
+
58
+ router.get('/stats', (req, res) => {
59
+ if (!darkPatternEngine) return res.json({ status: 'engine_not_loaded', patterns_tracked: 17 });
60
+ res.json(darkPatternEngine.getStats());
61
+ });
62
+
63
+ return router;
64
+ }
65
+
66
+ module.exports = { createRouter };
@@ -0,0 +1,45 @@
1
+ /**
2
+ * WAB Gov Intelligence (05-gov-intelligence) — FULLY CLOSED
3
+ * Regulatory compliance and government intelligence database.
4
+ * All data and logic is proprietary.
5
+ *
6
+ * Powered by WAB — Web Agent Bridge
7
+ * https://www.webagentbridge.com
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ let govEngine;
13
+ try { govEngine = require('./gov-engine'); } catch { govEngine = null; }
14
+
15
+ function createRouter(express) {
16
+ const router = express.Router();
17
+
18
+ router.get('/check/:domain', (req, res) => {
19
+ if (!govEngine) return res.status(503).json({ error: 'Gov intelligence engine not available', code: 'MODULE_UNAVAILABLE' });
20
+ const result = govEngine.checkDomain(req.params.domain);
21
+ res.json(result);
22
+ });
23
+
24
+ router.get('/regulations', (req, res) => {
25
+ const { country, sector } = req.query;
26
+ if (!govEngine) return res.status(503).json({ error: 'Gov intelligence engine not available', code: 'MODULE_UNAVAILABLE' });
27
+ res.json(govEngine.getRegulations(country, sector));
28
+ });
29
+
30
+ router.post('/compliance-report', (req, res) => {
31
+ const { domain, country } = req.body;
32
+ if (!domain) return res.status(400).json({ error: 'domain required' });
33
+ if (!govEngine) return res.status(503).json({ error: 'Gov intelligence engine not available', code: 'MODULE_UNAVAILABLE' });
34
+ res.json(govEngine.generateComplianceReport(domain, country));
35
+ });
36
+
37
+ router.get('/stats', (req, res) => {
38
+ if (!govEngine) return res.json({ status: 'offline' });
39
+ res.json(govEngine.getStats());
40
+ });
41
+
42
+ return router;
43
+ }
44
+
45
+ module.exports = { createRouter };
@@ -0,0 +1,55 @@
1
+ /**
2
+ * WAB Neural Engine (07-neural) — FULLY CLOSED
3
+ * Local AI inference engine. All logic is proprietary.
4
+ * Only the API interface is exposed here.
5
+ *
6
+ * Powered by WAB — Web Agent Bridge
7
+ * https://www.webagentbridge.com
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ let neuralEngine;
13
+ try { neuralEngine = require('./neural-engine'); } catch { neuralEngine = null; }
14
+
15
+ function createRouter(express) {
16
+ const router = express.Router();
17
+
18
+ router.post('/analyze-url', (req, res) => {
19
+ const { url: targetUrl } = req.body;
20
+ if (!targetUrl) return res.status(400).json({ error: 'url required' });
21
+ if (!neuralEngine) return res.status(503).json({ error: 'Neural engine not available', code: 'MODULE_UNAVAILABLE' });
22
+ const result = neuralEngine.analyzeUrl(targetUrl);
23
+ res.json(result);
24
+ });
25
+
26
+ router.post('/classify', (req, res) => {
27
+ const { content, categories } = req.body;
28
+ if (!content) return res.status(400).json({ error: 'content required' });
29
+ if (!neuralEngine) return res.status(503).json({ error: 'Neural engine not available', code: 'MODULE_UNAVAILABLE' });
30
+ const result = neuralEngine.classify(content, categories);
31
+ res.json(result);
32
+ });
33
+
34
+ router.post('/embeddings', (req, res) => {
35
+ const { text } = req.body;
36
+ if (!text) return res.status(400).json({ error: 'text required' });
37
+ if (!neuralEngine) return res.status(503).json({ error: 'Neural engine not available', code: 'MODULE_UNAVAILABLE' });
38
+ const result = neuralEngine.embed(text);
39
+ res.json(result);
40
+ });
41
+
42
+ router.get('/models', (req, res) => {
43
+ if (!neuralEngine) return res.json({ models: [], message: 'Neural engine not loaded' });
44
+ res.json(neuralEngine.listModels());
45
+ });
46
+
47
+ router.get('/stats', (req, res) => {
48
+ if (!neuralEngine) return res.json({ status: 'offline' });
49
+ res.json(neuralEngine.getStats());
50
+ });
51
+
52
+ return router;
53
+ }
54
+
55
+ module.exports = { createRouter };
@@ -0,0 +1,49 @@
1
+ /**
2
+ * WAB Notary (02-notary) — FULLY CLOSED
3
+ * Cryptographic certificate system for price discrimination evidence.
4
+ * Signing algorithm is proprietary.
5
+ *
6
+ * Powered by WAB — Web Agent Bridge
7
+ * https://www.webagentbridge.com
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ let notaryEngine;
13
+ try { notaryEngine = require('./notary-engine'); } catch { notaryEngine = null; }
14
+
15
+ function createRouter(express) {
16
+ const router = express.Router();
17
+
18
+ router.post('/price', (req, res) => {
19
+ const { platform, productId, priceShown } = req.body;
20
+ if (!platform || !productId || priceShown === undefined) {
21
+ return res.status(400).json({ error: 'platform, productId, and priceShown required' });
22
+ }
23
+ if (!notaryEngine) return res.status(503).json({ error: 'Notary engine not available', code: 'MODULE_UNAVAILABLE' });
24
+ const cert = notaryEngine.issuePriceCertificate(req.body);
25
+ res.status(201).json(cert);
26
+ });
27
+
28
+ router.post('/transaction', (req, res) => {
29
+ if (!notaryEngine) return res.status(503).json({ error: 'Notary engine not available', code: 'MODULE_UNAVAILABLE' });
30
+ const cert = notaryEngine.issueTransactionCertificate(req.body);
31
+ res.status(201).json(cert);
32
+ });
33
+
34
+ router.get('/verify/:certId', (req, res) => {
35
+ if (!notaryEngine) return res.status(503).json({ error: 'Notary engine not available', code: 'MODULE_UNAVAILABLE' });
36
+ const result = notaryEngine.verifyCertificate(req.params.certId);
37
+ if (!result) return res.status(404).json({ error: 'Certificate not found' });
38
+ res.json(result);
39
+ });
40
+
41
+ router.get('/stats', (req, res) => {
42
+ if (!notaryEngine) return res.json({ status: 'offline' });
43
+ res.json(notaryEngine.getStats());
44
+ });
45
+
46
+ return router;
47
+ }
48
+
49
+ module.exports = { createRouter };
@@ -0,0 +1,86 @@
1
+ /**
2
+ * WAB Price Time Machine (06-price-time-machine) — PUBLIC API, PRIVATE ENGINE
3
+ * Historical price tracking and fake discount detection.
4
+ * API is open, database and detection algorithm are closed.
5
+ *
6
+ * Powered by WAB — Web Agent Bridge
7
+ * https://www.webagentbridge.com
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ const crypto = require('crypto');
13
+
14
+ const priceStore = new Map();
15
+ const alertStore = new Map();
16
+
17
+ let priceEngine;
18
+ try { priceEngine = require('./price-engine'); } catch { priceEngine = null; }
19
+
20
+ function createRouter(express) {
21
+ const router = express.Router();
22
+
23
+ router.post('/track', (req, res) => {
24
+ const { platform, product_id, product_name, price, currency, url: productUrl } = req.body;
25
+ if (!platform || !product_id || price === undefined) {
26
+ return res.status(400).json({ error: 'platform, product_id, and price are required' });
27
+ }
28
+
29
+ const key = `${platform}:${product_id}`;
30
+ if (!priceStore.has(key)) priceStore.set(key, { entries: [], metadata: { platform, product_id, product_name, currency: currency || 'USD', url: productUrl } });
31
+ const record = priceStore.get(key);
32
+ record.entries.push({ price: parseFloat(price), timestamp: Date.now(), date: new Date().toISOString() });
33
+ if (record.entries.length > 5000) record.entries.splice(0, record.entries.length - 5000);
34
+
35
+ const prices = record.entries.map(e => e.price);
36
+ const avg = prices.reduce((a, b) => a + b, 0) / prices.length;
37
+ const min = Math.min(...prices);
38
+ const max = Math.max(...prices);
39
+
40
+ let fakeDiscount = null;
41
+ if (priceEngine) {
42
+ fakeDiscount = priceEngine.detectFakeDiscount(record.entries);
43
+ }
44
+
45
+ res.json({
46
+ tracked: true, product_id, platform, current_price: price, data_points: record.entries.length,
47
+ statistics: { average: parseFloat(avg.toFixed(2)), min, max, range_pct: parseFloat(((max - min) / avg * 100).toFixed(1)) },
48
+ fake_discount: fakeDiscount,
49
+ });
50
+ });
51
+
52
+ router.get('/history/:platform/:productId', (req, res) => {
53
+ const key = `${req.params.platform}:${req.params.productId}`;
54
+ const record = priceStore.get(key);
55
+ if (!record) return res.status(404).json({ error: 'No price history for this product' });
56
+ const days = parseInt(req.query.days) || 30;
57
+ const cutoff = Date.now() - days * 86400000;
58
+ const filtered = record.entries.filter(e => e.timestamp >= cutoff);
59
+ res.json({ ...record.metadata, period_days: days, data_points: filtered.length, history: filtered });
60
+ });
61
+
62
+ router.get('/compare', (req, res) => {
63
+ const { product_name } = req.query;
64
+ if (!product_name) return res.status(400).json({ error: 'product_name query param required' });
65
+ const results = [];
66
+ const search = product_name.toLowerCase();
67
+ for (const [key, record] of priceStore) {
68
+ if (record.metadata.product_name && record.metadata.product_name.toLowerCase().includes(search)) {
69
+ const prices = record.entries.map(e => e.price);
70
+ results.push({ platform: record.metadata.platform, product_id: record.metadata.product_id, product_name: record.metadata.product_name,
71
+ current_price: prices[prices.length - 1], lowest_price: Math.min(...prices), highest_price: Math.max(...prices), data_points: prices.length });
72
+ }
73
+ }
74
+ res.json({ query: product_name, results: results.sort((a, b) => a.current_price - b.current_price) });
75
+ });
76
+
77
+ router.get('/stats', (req, res) => {
78
+ let totalPoints = 0;
79
+ for (const r of priceStore.values()) totalPoints += r.entries.length;
80
+ res.json({ products_tracked: priceStore.size, total_data_points: totalPoints, alerts_active: alertStore.size });
81
+ });
82
+
83
+ return router;
84
+ }
85
+
86
+ module.exports = { createRouter };
@@ -0,0 +1,104 @@
1
+ /**
2
+ * WAB Protocol Validator (08-protocol) — OPEN SOURCE
3
+ * Validates wab.json trust protocol files.
4
+ * This module is fully open to become a web standard.
5
+ *
6
+ * Powered by WAB — Web Agent Bridge
7
+ * https://www.webagentbridge.com
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ const https = require('https');
13
+ const http = require('http');
14
+
15
+ const WAB_PROTOCOL_SCHEMA = {
16
+ required: ['wab_version', 'site', 'permissions'],
17
+ optional: ['pricing', 'returns', 'trust', 'accessibility', 'dark_patterns_policy'],
18
+ permissions_fields: ['ai_agents', 'price_comparison', 'automated_checkout', 'data_export'],
19
+ };
20
+
21
+ function validateWabJson(wabJson) {
22
+ const errors = [];
23
+ const warnings = [];
24
+ let score = 100;
25
+
26
+ if (!wabJson || typeof wabJson !== 'object') return { valid: false, score: 0, errors: ['Invalid JSON structure'] };
27
+
28
+ for (const field of WAB_PROTOCOL_SCHEMA.required) {
29
+ if (!wabJson[field]) { errors.push(`Missing required field: ${field}`); score -= 20; }
30
+ }
31
+
32
+ if (wabJson.wab_version && !/^\d+\.\d+(\.\d+)?$/.test(wabJson.wab_version)) {
33
+ errors.push('Invalid wab_version format. Expected semver (e.g., "1.0.0")'); score -= 10;
34
+ }
35
+
36
+ if (wabJson.permissions) {
37
+ const p = wabJson.permissions;
38
+ if (typeof p.ai_agents !== 'undefined' && typeof p.ai_agents !== 'boolean' && typeof p.ai_agents !== 'string') {
39
+ warnings.push('permissions.ai_agents should be boolean or policy string');
40
+ }
41
+ }
42
+
43
+ for (const field of WAB_PROTOCOL_SCHEMA.optional) {
44
+ if (wabJson[field]) score = Math.min(100, score + 3);
45
+ }
46
+
47
+ return {
48
+ valid: errors.length === 0, score: Math.max(0, score), errors, warnings,
49
+ fields_present: Object.keys(wabJson),
50
+ completeness: `${Object.keys(wabJson).length} fields`,
51
+ protocol_version: wabJson.wab_version || 'unknown',
52
+ };
53
+ }
54
+
55
+ async function fetchAndValidate(domain) {
56
+ const wabUrl = `https://${domain}/wab.json`;
57
+ return new Promise((resolve) => {
58
+ const protocol = wabUrl.startsWith('https') ? https : http;
59
+ const req = protocol.get(wabUrl, { timeout: 8000, headers: { 'User-Agent': 'WAB-Protocol-Validator/1.0' } }, (res) => {
60
+ if (res.statusCode !== 200) {
61
+ return resolve({ found: false, domain, url: wabUrl, error: `HTTP ${res.statusCode}`, recommendation: 'Add a wab.json file to your site root' });
62
+ }
63
+ let data = '';
64
+ res.on('data', c => data += c);
65
+ res.on('end', () => {
66
+ try {
67
+ const json = JSON.parse(data);
68
+ const result = validateWabJson(json);
69
+ resolve({ found: true, domain, url: wabUrl, ...result, raw: json });
70
+ } catch { resolve({ found: false, domain, url: wabUrl, error: 'Invalid JSON in wab.json' }); }
71
+ });
72
+ });
73
+ req.on('error', () => resolve({ found: false, domain, url: wabUrl, error: 'Could not reach domain' }));
74
+ req.on('timeout', () => { req.destroy(); resolve({ found: false, domain, url: wabUrl, error: 'Request timed out' }); });
75
+ });
76
+ }
77
+
78
+ function createRouter(express) {
79
+ const router = express.Router();
80
+
81
+ router.post('/validate', (req, res) => {
82
+ const { wab_json } = req.body;
83
+ if (!wab_json) return res.status(400).json({ error: 'wab_json object is required' });
84
+ res.json(validateWabJson(wab_json));
85
+ });
86
+
87
+ router.get('/check/:domain', async (req, res) => {
88
+ const result = await fetchAndValidate(req.params.domain);
89
+ res.json(result);
90
+ });
91
+
92
+ router.get('/schema', (req, res) => {
93
+ res.json({ version: '1.0', schema: WAB_PROTOCOL_SCHEMA, example: {
94
+ wab_version: '1.0.0', site: { name: 'Example Store', domain: 'example.com', type: 'e-commerce' },
95
+ permissions: { ai_agents: true, price_comparison: true, automated_checkout: false, data_export: true },
96
+ pricing: { transparency: 'full', currency: 'USD', includes_tax: false },
97
+ dark_patterns_policy: { commitment: 'none', last_audit: '2026-01-01' },
98
+ }});
99
+ });
100
+
101
+ return router;
102
+ }
103
+
104
+ module.exports = { createRouter, validateWabJson, fetchAndValidate };
@@ -1392,7 +1392,7 @@ function generateCdnUrl(siteId, customDomain) {
1392
1392
  if (customDomain) {
1393
1393
  return `https://${customDomain}/bridge/${siteId}/ai-agent-bridge.js`;
1394
1394
  }
1395
- return `https://cdn.webagentbridge.com/bridge/${siteId}/ai-agent-bridge.js`;
1395
+ return `https://webagentbridge.com/bridge/${siteId}/ai-agent-bridge.js`;
1396
1396
  }
1397
1397
 
1398
1398
  // ═══════════════════════════════════════════════════════════════════════
@@ -15,7 +15,8 @@
15
15
  const crypto = require('crypto');
16
16
  const { db } = require('../models/db');
17
17
  const scraper = require('./universal-scraper');
18
- const { getWabBridgeInfo } = require('./fairness-engine');
18
+ let getWabBridgeInfo;
19
+ try { ({ getWabBridgeInfo } = require('./fairness-engine')); } catch { getWabBridgeInfo = () => null; }
19
20
 
20
21
  // ─── Schema ──────────────────────────────────────────────────────────
21
22
 
@@ -1070,10 +1070,10 @@ function getDomExtractionScript() {
1070
1070
  'aria-labelledby','aria-checked','data-action','checked','disabled'].forEach(function(a){
1071
1071
  if(el.hasAttribute(a))n.attributes[a]=el.getAttribute(a);
1072
1072
  });if(el.checked)n.attributes.checked='checked';
1073
- if(LAY.has(t)||INT.has(t)){n.children=[];for(var c of el.children){var cn=ext(c,d+1);if(cn)n.children.push(cn);}}
1073
+ if(LAY.has(t)||INT.has(t)){n.children=[];var ch=Array.from(el.children);for(var j=0;j<ch.length;j++){var cn=ext(ch[j],d+1);if(cn)n.children.push(cn);}}
1074
1074
  return n;
1075
1075
  }
1076
- function sel(el){if(el.id)return'#'+CSS.escape(el.id);var p=[];var c=el;
1076
+ function sel(el){if(!el||!el.tagName)return'unknown';if(el.id)return'#'+CSS.escape(el.id);var p=[];var c=el;
1077
1077
  for(var i=0;i<4&&c&&c!==document.body;i++){var s=c.tagName.toLowerCase();
1078
1078
  if(c.id){p.unshift('#'+CSS.escape(c.id));break;}
1079
1079
  if(c.className&&typeof c.className==='string'){var cl=c.className.trim().split(/\\s+/).slice(0,2).map(function(x){return'.'+CSS.escape(x);}).join('');if(cl)s+=cl;}