web-agent-bridge 3.3.0 → 3.4.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.
- package/LICENSE +12 -0
- package/README.ar.md +18 -0
- package/README.md +198 -1664
- package/bin/wab-init.js +223 -0
- package/examples/azure-dns-wab.js +83 -0
- package/examples/cloudflare-wab-dns.js +121 -0
- package/examples/cpanel-wab-dns.js +114 -0
- package/examples/dns-discovery-agent.js +166 -0
- package/examples/gcp-dns-wab.js +76 -0
- package/examples/governance-agent.js +169 -0
- package/examples/plesk-wab-dns.js +103 -0
- package/examples/route53-wab-dns.js +144 -0
- package/examples/safe-mode-agent.js +96 -0
- package/examples/wab-sign.js +74 -0
- package/examples/wab-verify.js +60 -0
- package/package.json +5 -5
- package/public/.well-known/wab.json +28 -0
- package/public/activate.html +368 -0
- package/public/adoption-metrics.html +188 -0
- package/public/api.html +1 -1
- package/public/azure-dns-integration.html +289 -0
- package/public/cloudflare-integration.html +380 -0
- package/public/cpanel-integration.html +398 -0
- package/public/css/styles.css +28 -0
- package/public/dashboard.html +1 -0
- package/public/dns.html +101 -172
- package/public/docs.html +1 -0
- package/public/gcp-dns-integration.html +318 -0
- package/public/growth.html +4 -2
- package/public/index.html +227 -31
- package/public/integrations.html +1 -1
- package/public/js/activate.js +145 -0
- package/public/js/auth-nav.js +34 -0
- package/public/js/dns.js +438 -0
- package/public/openapi.json +89 -0
- package/public/plesk-integration.html +375 -0
- package/public/premium.html +1 -1
- package/public/provider-onboarding.html +172 -0
- package/public/provider-sandbox.html +134 -0
- package/public/providers.html +359 -0
- package/public/registrar-integrations.html +141 -0
- package/public/robots.txt +12 -0
- package/public/route53-integration.html +531 -0
- package/public/shieldqr.html +231 -0
- package/public/sitemap.xml +6 -0
- package/public/wab-trust.html +200 -0
- package/public/wab-vs-protocols.html +210 -0
- package/public/whitepaper.html +449 -0
- package/sdk/auto-discovery.js +288 -0
- package/sdk/governance.js +262 -0
- package/sdk/index.js +13 -0
- package/sdk/package.json +2 -2
- package/sdk/safe-mode.js +221 -0
- package/server/index.js +144 -5
- package/server/migrations/007_governance.sql +106 -0
- package/server/migrations/008_plans.sql +144 -0
- package/server/migrations/009_shieldqr.sql +30 -0
- package/server/migrations/010_extended_trust.sql +33 -0
- package/server/models/adapters/mysql.js +1 -1
- package/server/models/adapters/postgresql.js +1 -1
- package/server/models/db.js +60 -1
- package/server/routes/admin-plans.js +76 -0
- package/server/routes/admin-premium.js +4 -2
- package/server/routes/admin-shieldqr.js +90 -0
- package/server/routes/admin-trust-monitor.js +83 -0
- package/server/routes/admin.js +289 -1
- package/server/routes/billing.js +16 -4
- package/server/routes/discovery.js +1933 -2
- package/server/routes/governance.js +208 -0
- package/server/routes/plans.js +33 -0
- package/server/routes/providers.js +650 -0
- package/server/routes/shieldqr.js +88 -0
- package/server/services/email.js +29 -0
- package/server/services/governance.js +466 -0
- package/server/services/plans.js +214 -0
- package/server/services/premium.js +1 -1
- package/server/services/provider-clients.js +740 -0
- package/server/services/shieldqr.js +322 -0
- package/server/services/ssl-inspector.js +42 -0
- package/server/services/ssl-monitor.js +167 -0
- package/server/services/stripe.js +18 -5
- package/server/services/vision.js +1 -1
- package/server/services/wab-crypto.js +178 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Official WAB DNS Discovery consumer (multi-site).
|
|
6
|
+
*
|
|
7
|
+
* Proves the full value chain per domain:
|
|
8
|
+
* 1) discover via _wab TXT
|
|
9
|
+
* 2) fetch wab.json endpoint
|
|
10
|
+
* 3) call agent endpoints (/api/wab/discover, /api/wab/ping)
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* node examples/dns-discovery-agent.js webagentbridge.com example.com
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const { verify } = require('../packages/dns-verify/src');
|
|
17
|
+
const { safeFetch } = require('../server/utils/safe-fetch');
|
|
18
|
+
|
|
19
|
+
function sanitizeDomain(raw) {
|
|
20
|
+
return String(raw || '')
|
|
21
|
+
.trim()
|
|
22
|
+
.toLowerCase()
|
|
23
|
+
.replace(/^https?:\/\//, '')
|
|
24
|
+
.replace(/\/.*$/, '')
|
|
25
|
+
.replace(/:\d+$/, '')
|
|
26
|
+
.replace(/^www\./, '');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function parseEndpoint(record) {
|
|
30
|
+
if (!record || !record.parsed) return null;
|
|
31
|
+
return record.parsed.endpoint || null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function logStep(ok, label, detail) {
|
|
35
|
+
const icon = ok ? 'OK' : 'NO';
|
|
36
|
+
const extra = detail ? ` - ${detail}` : '';
|
|
37
|
+
console.log(`[${icon}] ${label}${extra}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function runDomain(domain) {
|
|
41
|
+
console.log('\n=== ' + domain + ' ===');
|
|
42
|
+
|
|
43
|
+
const result = {
|
|
44
|
+
domain,
|
|
45
|
+
dns: null,
|
|
46
|
+
endpoint: null,
|
|
47
|
+
wabJson: null,
|
|
48
|
+
discover: null,
|
|
49
|
+
ping: null,
|
|
50
|
+
ok: false,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const proof = await verify(domain, { timeoutMs: 6000 }).catch((err) => ({
|
|
54
|
+
ok: false,
|
|
55
|
+
records: [{ type: '_wab', error: err.message }],
|
|
56
|
+
}));
|
|
57
|
+
|
|
58
|
+
const wabRecord = (proof.records || []).find((r) => r.type === '_wab') || null;
|
|
59
|
+
result.dns = wabRecord;
|
|
60
|
+
logStep(!!(wabRecord && wabRecord.ok), 'DNS discovery', wabRecord && (wabRecord.error || wabRecord.fqdn));
|
|
61
|
+
|
|
62
|
+
const endpoint = parseEndpoint(wabRecord);
|
|
63
|
+
result.endpoint = endpoint;
|
|
64
|
+
if (!endpoint) {
|
|
65
|
+
logStep(false, 'wab.json endpoint', 'missing endpoint= in _wab record');
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
logStep(true, 'wab.json endpoint', endpoint);
|
|
69
|
+
|
|
70
|
+
const endpointUrl = new URL(endpoint);
|
|
71
|
+
const allowList = [domain, '*.' + domain, endpointUrl.hostname, '*.' + endpointUrl.hostname]
|
|
72
|
+
.filter((v, i, a) => a.indexOf(v) === i);
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
const wabRes = await safeFetch(endpointUrl.toString(), { headers: { accept: 'application/json' } }, {
|
|
76
|
+
requireHttps: true,
|
|
77
|
+
allowList,
|
|
78
|
+
timeoutMs: 8000,
|
|
79
|
+
maxBytes: 1024 * 1024,
|
|
80
|
+
allowedContentTypes: ['application/json', 'application/ld+json', 'text/plain'],
|
|
81
|
+
});
|
|
82
|
+
const wabJson = await wabRes.json();
|
|
83
|
+
result.wabJson = wabJson;
|
|
84
|
+
logStep(wabRes.ok, 'Fetch wab.json', wabRes.status + ' ' + (wabJson.provider && wabJson.provider.name || 'unknown provider'));
|
|
85
|
+
} catch (err) {
|
|
86
|
+
logStep(false, 'Fetch wab.json', err.message);
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const origin = endpointUrl.origin;
|
|
91
|
+
const discoverUrl = origin + '/api/wab/discover';
|
|
92
|
+
const fallbackDiscoverUrl = origin + '/agent-bridge.json';
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const discoverRes = await safeFetch(discoverUrl, { headers: { accept: 'application/json' } }, {
|
|
96
|
+
requireHttps: true,
|
|
97
|
+
allowList,
|
|
98
|
+
timeoutMs: 8000,
|
|
99
|
+
maxBytes: 1024 * 1024,
|
|
100
|
+
allowedContentTypes: ['application/json'],
|
|
101
|
+
});
|
|
102
|
+
if (discoverRes.ok) {
|
|
103
|
+
const discoverJson = await discoverRes.json();
|
|
104
|
+
result.discover = discoverJson;
|
|
105
|
+
logStep(true, 'Agent discover', 'GET /api/wab/discover');
|
|
106
|
+
} else {
|
|
107
|
+
const fallbackRes = await safeFetch(fallbackDiscoverUrl, { headers: { accept: 'application/json' } }, {
|
|
108
|
+
requireHttps: true,
|
|
109
|
+
allowList,
|
|
110
|
+
timeoutMs: 8000,
|
|
111
|
+
maxBytes: 1024 * 1024,
|
|
112
|
+
allowedContentTypes: ['application/json'],
|
|
113
|
+
});
|
|
114
|
+
const fallbackJson = await fallbackRes.json().catch(() => ({}));
|
|
115
|
+
if (fallbackRes.ok) {
|
|
116
|
+
result.discover = fallbackJson;
|
|
117
|
+
logStep(true, 'Agent discover', `fallback /agent-bridge.json (discover HTTP ${discoverRes.status})`);
|
|
118
|
+
} else {
|
|
119
|
+
logStep(false, 'Agent discover', `discover HTTP ${discoverRes.status}; fallback HTTP ${fallbackRes.status}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
} catch (err) {
|
|
123
|
+
logStep(false, 'Agent discover', err.message);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
const pingRes = await safeFetch(origin + '/api/wab/ping', { headers: { accept: 'application/json' } }, {
|
|
128
|
+
requireHttps: true,
|
|
129
|
+
allowList,
|
|
130
|
+
timeoutMs: 8000,
|
|
131
|
+
maxBytes: 512 * 1024,
|
|
132
|
+
allowedContentTypes: ['application/json'],
|
|
133
|
+
});
|
|
134
|
+
const pingJson = await pingRes.json();
|
|
135
|
+
result.ping = pingJson;
|
|
136
|
+
logStep(pingRes.ok, 'Agent execute', 'GET /api/wab/ping => pong=' + !!(pingJson.result && pingJson.result.pong));
|
|
137
|
+
} catch (err) {
|
|
138
|
+
logStep(false, 'Agent execute', err.message);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
result.ok = !!(result.dns && result.dns.ok && result.wabJson && result.ping);
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function main() {
|
|
146
|
+
const domains = process.argv.slice(2).map(sanitizeDomain).filter(Boolean);
|
|
147
|
+
if (domains.length === 0) {
|
|
148
|
+
console.error('Usage: node examples/dns-discovery-agent.js <domain1> [domain2] [...]');
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const outputs = [];
|
|
153
|
+
for (const domain of domains) {
|
|
154
|
+
outputs.push(await runDomain(domain));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const passed = outputs.filter((o) => o.ok).length;
|
|
158
|
+
console.log('\nSummary: ' + passed + '/' + outputs.length + ' domains passed full flow');
|
|
159
|
+
|
|
160
|
+
if (passed !== outputs.length) process.exitCode = 2;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
main().catch((err) => {
|
|
164
|
+
console.error('Fatal:', err && err.stack || err);
|
|
165
|
+
process.exit(1);
|
|
166
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* gcp-dns-wab.js — enable/disable WAB DNS Discovery TXT record on Google Cloud DNS.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* node gcp-dns-wab.js enable example.com my-project example-com
|
|
7
|
+
* node gcp-dns-wab.js disable example.com my-project example-com
|
|
8
|
+
* node gcp-dns-wab.js status example.com
|
|
9
|
+
*
|
|
10
|
+
* Auth: uses Application Default Credentials (run `gcloud auth application-default login`)
|
|
11
|
+
* or set GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json
|
|
12
|
+
*
|
|
13
|
+
* Required: @google-cloud/dns
|
|
14
|
+
* npm install @google-cloud/dns
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
'use strict';
|
|
18
|
+
|
|
19
|
+
const fetch = (() => { try { return require('node-fetch'); } catch { return globalThis.fetch; } })();
|
|
20
|
+
const { DNS } = require('@google-cloud/dns');
|
|
21
|
+
|
|
22
|
+
const [,, action, domain, projectId, zoneName] = process.argv;
|
|
23
|
+
const WAB_BASE = process.env.WAB_BASE_URL || 'https://www.webagentbridge.com';
|
|
24
|
+
const ENDPOINT = process.env.WAB_ENDPOINT || `https://${domain}/.well-known/wab.json`;
|
|
25
|
+
|
|
26
|
+
if (!action || !domain) { console.error('Usage: node gcp-dns-wab.js <enable|disable|status> <domain> [projectId] [zoneName]'); process.exit(1); }
|
|
27
|
+
if (!['enable','disable','status'].includes(action)) { console.error('Action must be: enable | disable | status'); process.exit(1); }
|
|
28
|
+
if (action !== 'status' && (!projectId || !zoneName)) { console.error('projectId and zoneName required for enable/disable'); process.exit(1); }
|
|
29
|
+
|
|
30
|
+
async function getRecordTemplate() {
|
|
31
|
+
const j = await (await fetch(`${WAB_BASE}/api/discovery/provider/record-template?domain=${encodeURIComponent(domain)}&endpoint=${encodeURIComponent(ENDPOINT)}`)).json();
|
|
32
|
+
if (!j.record || !j.record.value) throw new Error('Could not fetch WAB record template');
|
|
33
|
+
const v = j.record.value;
|
|
34
|
+
return v.startsWith('"') ? v : `"${v}"`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function main() {
|
|
38
|
+
console.log(`[WAB] Action: ${action} | Domain: ${domain}`);
|
|
39
|
+
|
|
40
|
+
if (action === 'status') {
|
|
41
|
+
const j = await (await fetch(`${WAB_BASE}/api/discovery/provider/status?domain=${encodeURIComponent(domain)}`)).json();
|
|
42
|
+
console.log(`[WAB] Status: ${j.status}`);
|
|
43
|
+
console.log(JSON.stringify(j, null, 2));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const dns = new DNS({ projectId });
|
|
48
|
+
const zone = dns.zone(zoneName);
|
|
49
|
+
const fqdn = `_wab.${domain}.`;
|
|
50
|
+
|
|
51
|
+
const [existing] = await zone.getRecords({ type: 'TXT', name: fqdn });
|
|
52
|
+
console.log(`[GCP] Existing _wab TXT records: ${existing.length}`);
|
|
53
|
+
|
|
54
|
+
if (action === 'enable') {
|
|
55
|
+
const txtVal = await getRecordTemplate();
|
|
56
|
+
console.log(`[WAB] TXT value: ${txtVal}`);
|
|
57
|
+
const newRecord = zone.record('txt', { name: fqdn, ttl: 3600, data: txtVal });
|
|
58
|
+
if (existing.length) {
|
|
59
|
+
const [change] = await zone.createChange({ delete: existing, add: newRecord });
|
|
60
|
+
console.log(`[GCP] Replaced (change id=${change.id}, status=${change.metadata.status})`);
|
|
61
|
+
} else {
|
|
62
|
+
const [change] = await zone.createChange({ add: newRecord });
|
|
63
|
+
console.log(`[GCP] Created (change id=${change.id}, status=${change.metadata.status})`);
|
|
64
|
+
}
|
|
65
|
+
console.log('[WAB] WAB Discovery ENABLED.');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (action === 'disable') {
|
|
69
|
+
if (!existing.length) { console.log('[GCP] No _wab record found — already disabled.'); return; }
|
|
70
|
+
const [change] = await zone.createChange({ delete: existing });
|
|
71
|
+
console.log(`[GCP] Deleted (change id=${change.id}, status=${change.metadata.status})`);
|
|
72
|
+
console.log('[WAB] WAB Discovery DISABLED.');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
main().catch(err => { console.error('[ERROR]', err.message); process.exit(1); });
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* WAB Governance Demo
|
|
4
|
+
* ───────────────────
|
|
5
|
+
* Walks through the full Layer-3 governance pipeline:
|
|
6
|
+
*
|
|
7
|
+
* 1) register agent → get one-time token
|
|
8
|
+
* 2) define permission boundaries (Stripe read-only + refund <$50 + ClickUp write)
|
|
9
|
+
* 3) try a forbidden action → DENIED
|
|
10
|
+
* 4) try an allowed action → ALLOWED + audited
|
|
11
|
+
* 5) try a high-value refund → APPROVAL_REQUIRED → human approves → executed
|
|
12
|
+
* 6) verify audit chain → tamper-evident
|
|
13
|
+
* 7) kill switch → all subsequent actions DENIED
|
|
14
|
+
*
|
|
15
|
+
* Run:
|
|
16
|
+
* node examples/governance-agent.js
|
|
17
|
+
* WAB_API=http://localhost:3000 node examples/governance-agent.js
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
'use strict';
|
|
21
|
+
|
|
22
|
+
const { WABGovernance } = require('../sdk');
|
|
23
|
+
|
|
24
|
+
const API = process.env.WAB_API || 'http://localhost:3000';
|
|
25
|
+
|
|
26
|
+
const c = {
|
|
27
|
+
reset: '\x1b[0m', dim: '\x1b[2m', bold: '\x1b[1m',
|
|
28
|
+
green: '\x1b[32m', red: '\x1b[31m', yellow: '\x1b[33m',
|
|
29
|
+
blue: '\x1b[34m', cyan: '\x1b[36m', magenta: '\x1b[35m',
|
|
30
|
+
};
|
|
31
|
+
const log = (msg) => console.log(msg);
|
|
32
|
+
const head = (n, msg) => log(`\n${c.bold}${c.cyan}── ${n}. ${msg} ──${c.reset}`);
|
|
33
|
+
const ok = (m) => log(` ${c.green}✓${c.reset} ${m}`);
|
|
34
|
+
const no = (m) => log(` ${c.red}✗${c.reset} ${m}`);
|
|
35
|
+
const info = (m) => log(` ${c.dim}${m}${c.reset}`);
|
|
36
|
+
|
|
37
|
+
async function main() {
|
|
38
|
+
log(`${c.bold}${c.magenta}WAB Agent Governance Demo${c.reset} ${c.dim}(API: ${API})${c.reset}`);
|
|
39
|
+
|
|
40
|
+
// ── 1) Register a fresh agent identity
|
|
41
|
+
head(1, 'Register agent');
|
|
42
|
+
const reg = await WABGovernance.register({
|
|
43
|
+
apiBase: API,
|
|
44
|
+
displayName: 'Demo Agent — Stripe + ClickUp',
|
|
45
|
+
metadata: { demo: true, created: Date.now() },
|
|
46
|
+
});
|
|
47
|
+
ok(`agent_id = ${reg.agent_id}`);
|
|
48
|
+
ok(`agent_token (shown ONCE) = ${reg.agent_token.slice(0, 12)}…`);
|
|
49
|
+
|
|
50
|
+
const gov = new WABGovernance({
|
|
51
|
+
apiBase: API,
|
|
52
|
+
agentId: reg.agent_id,
|
|
53
|
+
agentToken: reg.agent_token,
|
|
54
|
+
// Auto-approve in this demo (a real app would post to Slack/email).
|
|
55
|
+
onApprovalRequired: async (req) => {
|
|
56
|
+
info(`[human approval] resource=${req.resource} action=${req.action} amount=${req.amount}`);
|
|
57
|
+
info('[human approval] auto-approving in demo (3s think...)');
|
|
58
|
+
await sleep(3000);
|
|
59
|
+
return 'approved';
|
|
60
|
+
},
|
|
61
|
+
approvalTimeoutMs: 30_000,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// ── 2) Define policies
|
|
65
|
+
head(2, 'Define permission boundaries');
|
|
66
|
+
await gov.definePolicy({ resource: 'stripe', action: 'read', scope: 'customers' });
|
|
67
|
+
ok('stripe:read on customers');
|
|
68
|
+
await gov.definePolicy({
|
|
69
|
+
resource: 'stripe', action: 'write', scope: 'refunds',
|
|
70
|
+
max_amount: 50, currency: 'USD', daily_cap: 200,
|
|
71
|
+
});
|
|
72
|
+
ok('stripe:write on refunds (max $50/call, $200/day)');
|
|
73
|
+
await gov.definePolicy({
|
|
74
|
+
resource: 'stripe', action: 'write', scope: 'refunds-large',
|
|
75
|
+
max_amount: 5000, currency: 'USD', requires_approval: true,
|
|
76
|
+
});
|
|
77
|
+
ok('stripe:write on refunds-large (≤$5000, REQUIRES HUMAN APPROVAL)');
|
|
78
|
+
await gov.definePolicy({
|
|
79
|
+
resource: 'clickup', action: 'write', scope: 'tasks', per_call_rate: 30,
|
|
80
|
+
});
|
|
81
|
+
ok('clickup:write on tasks (rate-limited 30/min)');
|
|
82
|
+
|
|
83
|
+
// ── 3) Forbidden action
|
|
84
|
+
head(3, 'Attempt forbidden action: gmail:write');
|
|
85
|
+
try {
|
|
86
|
+
await gov.guard({ resource: 'gmail', action: 'write', scope: 'inbox' },
|
|
87
|
+
async () => { throw new Error('should not run'); });
|
|
88
|
+
no('UNEXPECTED: action ran (governance failed)');
|
|
89
|
+
} catch (e) {
|
|
90
|
+
ok(`correctly blocked: ${e.message}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ── 4) Allowed read
|
|
94
|
+
head(4, 'Allowed action: stripe:read on customers');
|
|
95
|
+
const r = await gov.guard(
|
|
96
|
+
{ resource: 'stripe', action: 'read', scope: 'customers' },
|
|
97
|
+
async () => ({ count: 12, sample: [{ id: 'cus_abc', email: 'demo@x' }] }),
|
|
98
|
+
);
|
|
99
|
+
ok(`executed in ${r.elapsed_ms}ms — result keys: ${Object.keys(r.result).join(', ')}`);
|
|
100
|
+
|
|
101
|
+
// ── 5) Small refund: under cap, no approval
|
|
102
|
+
head(5, 'Small refund: $9.99 (under cap)');
|
|
103
|
+
const r2 = await gov.guard(
|
|
104
|
+
{ resource: 'stripe', action: 'write', scope: 'refunds',
|
|
105
|
+
amount: 9.99, currency: 'USD',
|
|
106
|
+
params: { charge: 'ch_xyz', reason: 'duplicate' } },
|
|
107
|
+
async () => ({ refund_id: 're_demo_' + Date.now(), status: 'succeeded' }),
|
|
108
|
+
);
|
|
109
|
+
ok(`refund posted: ${r2.result.refund_id}`);
|
|
110
|
+
|
|
111
|
+
// ── 6) Refund OVER per-call cap → DENIED instantly
|
|
112
|
+
head(6, 'Refund $9999 with cap=$50 → DENY');
|
|
113
|
+
try {
|
|
114
|
+
await gov.guard(
|
|
115
|
+
{ resource: 'stripe', action: 'write', scope: 'refunds',
|
|
116
|
+
amount: 9999, currency: 'USD' },
|
|
117
|
+
async () => 'should not run',
|
|
118
|
+
);
|
|
119
|
+
no('UNEXPECTED: action ran');
|
|
120
|
+
} catch (e) {
|
|
121
|
+
ok(`correctly blocked: ${e.message}`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ── 7) Large refund routed through approval gate
|
|
125
|
+
head(7, 'Large refund $499.99 → APPROVAL GATE');
|
|
126
|
+
const r3 = await gov.guard(
|
|
127
|
+
{ resource: 'stripe', action: 'write', scope: 'refunds-large',
|
|
128
|
+
amount: 499.99, currency: 'USD',
|
|
129
|
+
params: { charge: 'ch_big', reason: 'fraud_dispute' },
|
|
130
|
+
reason: 'high_value_refund_requires_review' },
|
|
131
|
+
async () => ({ refund_id: 're_big_' + Date.now(), status: 'succeeded' }),
|
|
132
|
+
);
|
|
133
|
+
ok(`approved + executed: ${r3.result.refund_id}`);
|
|
134
|
+
|
|
135
|
+
// ── 8) Audit log + chain verification
|
|
136
|
+
head(8, 'Audit log + tamper check');
|
|
137
|
+
const audit = await gov.getAudit({ limit: 20 });
|
|
138
|
+
info(`last ${audit.audit.length} events:`);
|
|
139
|
+
for (const ev of audit.audit.slice(0, 8)) {
|
|
140
|
+
const tag = ev.decision === 'deny' ? c.red : ev.decision === 'pending' ? c.yellow : c.green;
|
|
141
|
+
log(` ${tag}${(ev.decision || '·').padEnd(8)}${c.reset}` +
|
|
142
|
+
` ${(ev.event_type || '').padEnd(18)} ${ev.resource || ''}/${ev.action || ''}` +
|
|
143
|
+
` ${ev.scope ? '['+ev.scope+'] ' : ''}${ev.amount ? '$'+ev.amount : ''}`);
|
|
144
|
+
}
|
|
145
|
+
const v = await gov.verifyAudit();
|
|
146
|
+
if (v.ok) ok(`chain verified: ${v.count} entries, head=${(v.head || '').slice(0, 12)}…`);
|
|
147
|
+
else no(`chain BROKEN at id=${v.broken_at}`);
|
|
148
|
+
|
|
149
|
+
// ── 9) Kill switch
|
|
150
|
+
head(9, 'Kill switch');
|
|
151
|
+
await gov.kill('demo_complete');
|
|
152
|
+
ok('agent killed');
|
|
153
|
+
try {
|
|
154
|
+
await gov.guard({ resource: 'stripe', action: 'read', scope: 'customers' },
|
|
155
|
+
async () => 'should not run');
|
|
156
|
+
no('UNEXPECTED: action ran after kill');
|
|
157
|
+
} catch (e) {
|
|
158
|
+
ok(`post-kill action blocked: ${e.message}`);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
log(`\n${c.bold}${c.green}✓ Demo complete${c.reset}\n`);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function sleep(ms) { return new Promise((r) => setTimeout(r, ms)); }
|
|
165
|
+
|
|
166
|
+
main().catch((e) => {
|
|
167
|
+
console.error(`\n${c.red}Demo failed:${c.reset}`, e.message);
|
|
168
|
+
process.exit(1);
|
|
169
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* plesk-wab-dns.js — enable/disable WAB DNS Discovery TXT record via Plesk REST API.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* PLESK_API_KEY=… node plesk-wab-dns.js enable example.com plesk.host.com
|
|
7
|
+
* PLESK_API_KEY=… node plesk-wab-dns.js disable example.com plesk.host.com
|
|
8
|
+
* node plesk-wab-dns.js status example.com
|
|
9
|
+
*
|
|
10
|
+
* Optional env vars:
|
|
11
|
+
* PLESK_PORT=8443
|
|
12
|
+
* PLESK_USER + PLESK_PASS (basic auth instead of API key)
|
|
13
|
+
* WAB_BASE_URL (default: https://www.webagentbridge.com)
|
|
14
|
+
* NODE_TLS_REJECT_UNAUTHORIZED=0 (for self-signed cert)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
'use strict';
|
|
18
|
+
|
|
19
|
+
const fetch = (() => { try { return require('node-fetch'); } catch { return globalThis.fetch; } })();
|
|
20
|
+
|
|
21
|
+
const [,, action, domain, host] = process.argv;
|
|
22
|
+
const PORT = process.env.PLESK_PORT || '8443';
|
|
23
|
+
const APIKEY = process.env.PLESK_API_KEY;
|
|
24
|
+
const USER = process.env.PLESK_USER;
|
|
25
|
+
const PASS = process.env.PLESK_PASS;
|
|
26
|
+
const WAB_BASE = process.env.WAB_BASE_URL || 'https://www.webagentbridge.com';
|
|
27
|
+
const ENDPOINT = process.env.WAB_ENDPOINT || `https://${domain}/.well-known/wab.json`;
|
|
28
|
+
|
|
29
|
+
if (!action || !domain) { console.error('Usage: node plesk-wab-dns.js <enable|disable|status> <domain> [plesk-host]'); process.exit(1); }
|
|
30
|
+
if (!['enable','disable','status'].includes(action)) { console.error('Action must be: enable | disable | status'); process.exit(1); }
|
|
31
|
+
if (action !== 'status' && !host) { console.error('plesk-host required for enable/disable'); process.exit(1); }
|
|
32
|
+
if (action !== 'status' && !APIKEY && !(USER && PASS)) { console.error('Set PLESK_API_KEY or PLESK_USER + PLESK_PASS'); process.exit(1); }
|
|
33
|
+
|
|
34
|
+
function headers() {
|
|
35
|
+
const h = { 'Content-Type': 'application/json' };
|
|
36
|
+
if (APIKEY) h['X-API-Key'] = APIKEY;
|
|
37
|
+
else h['Authorization'] = 'Basic ' + Buffer.from(`${USER}:${PASS}`).toString('base64');
|
|
38
|
+
return h;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const base = () => `https://${host}:${PORT}/api/v2`;
|
|
42
|
+
|
|
43
|
+
async function pkReq(method, path, body) {
|
|
44
|
+
const opts = { method, headers: headers() };
|
|
45
|
+
if (body) opts.body = JSON.stringify(body);
|
|
46
|
+
const r = await fetch(`${base()}${path}`, opts);
|
|
47
|
+
const t = await r.text();
|
|
48
|
+
if (!r.ok) throw new Error(`Plesk ${r.status}: ${t.slice(0, 300)}`);
|
|
49
|
+
try { return JSON.parse(t); } catch { return t; }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function getRecordTemplate() {
|
|
53
|
+
const j = await (await fetch(`${WAB_BASE}/api/discovery/provider/record-template?domain=${encodeURIComponent(domain)}&endpoint=${encodeURIComponent(ENDPOINT)}`)).json();
|
|
54
|
+
if (!j.record || !j.record.value) throw new Error('Could not fetch WAB record template');
|
|
55
|
+
return j.record.value;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function listWab() {
|
|
59
|
+
const all = await pkReq('GET', `/dns/records?domain=${encodeURIComponent(domain)}&type=TXT`);
|
|
60
|
+
return (all || []).filter(r => {
|
|
61
|
+
const h = (r.host || '').replace(/\.$/, '');
|
|
62
|
+
return h === `_wab.${domain}` || h === '_wab';
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function main() {
|
|
67
|
+
console.log(`[WAB] Action: ${action} | Domain: ${domain}`);
|
|
68
|
+
|
|
69
|
+
if (action === 'status') {
|
|
70
|
+
const j = await (await fetch(`${WAB_BASE}/api/discovery/provider/status?domain=${encodeURIComponent(domain)}`)).json();
|
|
71
|
+
console.log(`[WAB] Status: ${j.status}`);
|
|
72
|
+
console.log(JSON.stringify(j, null, 2));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (action === 'enable') {
|
|
77
|
+
const txtVal = await getRecordTemplate();
|
|
78
|
+
console.log(`[WAB] TXT value: ${txtVal}`);
|
|
79
|
+
const existing = await listWab();
|
|
80
|
+
for (const rec of existing) {
|
|
81
|
+
console.log(`[Plesk] Deleting old record id=${rec.id}`);
|
|
82
|
+
await pkReq('DELETE', `/dns/records/${rec.id}`);
|
|
83
|
+
}
|
|
84
|
+
const out = await pkReq('POST', '/dns/records', {
|
|
85
|
+
domain, type: 'TXT', host: `_wab.${domain}`, value: txtVal,
|
|
86
|
+
});
|
|
87
|
+
console.log('[Plesk] Created TXT record');
|
|
88
|
+
console.log(JSON.stringify(out, null, 2));
|
|
89
|
+
console.log('[WAB] WAB Discovery ENABLED.');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (action === 'disable') {
|
|
93
|
+
const existing = await listWab();
|
|
94
|
+
if (!existing.length) { console.log('[Plesk] No _wab record found — already disabled.'); return; }
|
|
95
|
+
for (const rec of existing) {
|
|
96
|
+
console.log(`[Plesk] Deleting record id=${rec.id}`);
|
|
97
|
+
await pkReq('DELETE', `/dns/records/${rec.id}`);
|
|
98
|
+
}
|
|
99
|
+
console.log('[WAB] WAB Discovery DISABLED.');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
main().catch(err => { console.error('[ERROR]', err.message); process.exit(1); });
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* route53-wab-dns.js
|
|
4
|
+
* -------------------
|
|
5
|
+
* CLI tool: enable or disable WAB DNS Discovery TXT record on AWS Route 53.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* AWS_ACCESS_KEY_ID=… AWS_SECRET_ACCESS_KEY=… \
|
|
9
|
+
* node route53-wab-dns.js enable example.com [HOSTED_ZONE_ID]
|
|
10
|
+
*
|
|
11
|
+
* AWS_ACCESS_KEY_ID=… AWS_SECRET_ACCESS_KEY=… \
|
|
12
|
+
* node route53-wab-dns.js disable example.com [HOSTED_ZONE_ID]
|
|
13
|
+
*
|
|
14
|
+
* node route53-wab-dns.js status example.com
|
|
15
|
+
*
|
|
16
|
+
* Optional env vars:
|
|
17
|
+
* AWS_REGION (default: us-east-1)
|
|
18
|
+
* WAB_BASE_URL (default: https://www.webagentbridge.com)
|
|
19
|
+
* WAB_ENDPOINT (override the wab.json URL in the TXT record)
|
|
20
|
+
*
|
|
21
|
+
* Required: @aws-sdk/client-route-53
|
|
22
|
+
* npm install @aws-sdk/client-route-53
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
'use strict';
|
|
26
|
+
|
|
27
|
+
const {
|
|
28
|
+
Route53Client,
|
|
29
|
+
ChangeResourceRecordSetsCommand,
|
|
30
|
+
ListHostedZonesByNameCommand,
|
|
31
|
+
ListResourceRecordSetsCommand,
|
|
32
|
+
} = require('@aws-sdk/client-route-53');
|
|
33
|
+
|
|
34
|
+
const fetch = (() => {
|
|
35
|
+
try { return require('node-fetch'); }
|
|
36
|
+
catch { return globalThis.fetch; }
|
|
37
|
+
})();
|
|
38
|
+
|
|
39
|
+
const [,, action, domain, zoneIdArg] = process.argv;
|
|
40
|
+
|
|
41
|
+
const REGION = process.env.AWS_REGION || 'us-east-1';
|
|
42
|
+
const WAB_BASE = process.env.WAB_BASE_URL || 'https://www.webagentbridge.com';
|
|
43
|
+
const ENDPOINT = process.env.WAB_ENDPOINT || `https://${domain}/.well-known/wab.json`;
|
|
44
|
+
|
|
45
|
+
if (!action || !domain) {
|
|
46
|
+
console.error('Usage: node route53-wab-dns.js <enable|disable|status> <domain> [zone-id]');
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
if (!['enable','disable','status'].includes(action)) {
|
|
50
|
+
console.error('Action must be: enable | disable | status');
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
if (action !== 'status' && (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_SECRET_ACCESS_KEY)) {
|
|
54
|
+
console.error('Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY env variables');
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const client = new Route53Client({ region: REGION });
|
|
59
|
+
|
|
60
|
+
async function getRecordTemplate() {
|
|
61
|
+
const url = `${WAB_BASE}/api/discovery/provider/record-template?domain=${encodeURIComponent(domain)}&endpoint=${encodeURIComponent(ENDPOINT)}`;
|
|
62
|
+
const j = await (await fetch(url)).json();
|
|
63
|
+
if (!j.record || !j.record.value) throw new Error('Could not fetch WAB record template');
|
|
64
|
+
// Route 53 requires double-quoted TXT value
|
|
65
|
+
const v = j.record.value;
|
|
66
|
+
return v.startsWith('"') ? v : `"${v}"`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function resolveZoneId() {
|
|
70
|
+
if (zoneIdArg) return zoneIdArg;
|
|
71
|
+
console.log(`[R53] Resolving hosted zone for ${domain}…`);
|
|
72
|
+
const r = await client.send(new ListHostedZonesByNameCommand({ DNSName: domain, MaxItems: '1' }));
|
|
73
|
+
const zone = (r.HostedZones || []).find(z => z.Name === `${domain}.`);
|
|
74
|
+
if (!zone) throw new Error(`No hosted zone found for "${domain}"`);
|
|
75
|
+
return zone.Id.replace('/hostedzone/', '');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function getCurrentRecord(zoneId) {
|
|
79
|
+
const r = await client.send(new ListResourceRecordSetsCommand({
|
|
80
|
+
HostedZoneId: zoneId,
|
|
81
|
+
StartRecordName: `_wab.${domain}`,
|
|
82
|
+
StartRecordType: 'TXT',
|
|
83
|
+
MaxItems: '1',
|
|
84
|
+
}));
|
|
85
|
+
return (r.ResourceRecordSets || []).find(
|
|
86
|
+
rr => rr.Name === `_wab.${domain}.` && rr.Type === 'TXT'
|
|
87
|
+
) || null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function main() {
|
|
91
|
+
console.log(`[WAB] Action: ${action} | Domain: ${domain}`);
|
|
92
|
+
|
|
93
|
+
if (action === 'status') {
|
|
94
|
+
const j = await (await fetch(`${WAB_BASE}/api/discovery/provider/status?domain=${encodeURIComponent(domain)}`)).json();
|
|
95
|
+
console.log(`[WAB] Status: ${j.status}`);
|
|
96
|
+
console.log(JSON.stringify(j, null, 2));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const zoneId = await resolveZoneId();
|
|
101
|
+
console.log(`[R53] Zone ID: ${zoneId}`);
|
|
102
|
+
|
|
103
|
+
if (action === 'enable') {
|
|
104
|
+
const txtVal = await getRecordTemplate();
|
|
105
|
+
console.log(`[WAB] TXT value: ${txtVal}`);
|
|
106
|
+
|
|
107
|
+
await client.send(new ChangeResourceRecordSetsCommand({
|
|
108
|
+
HostedZoneId: zoneId,
|
|
109
|
+
ChangeBatch: {
|
|
110
|
+
Comment: 'WAB DNS Discovery enable',
|
|
111
|
+
Changes: [{
|
|
112
|
+
Action: 'UPSERT',
|
|
113
|
+
ResourceRecordSet: {
|
|
114
|
+
Name: `_wab.${domain}`,
|
|
115
|
+
Type: 'TXT',
|
|
116
|
+
TTL: 3600,
|
|
117
|
+
ResourceRecords: [{ Value: txtVal }],
|
|
118
|
+
},
|
|
119
|
+
}],
|
|
120
|
+
},
|
|
121
|
+
}));
|
|
122
|
+
console.log('[R53] UPSERT applied');
|
|
123
|
+
console.log('[WAB] WAB Discovery ENABLED. Propagation may take up to 60 s.');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (action === 'disable') {
|
|
127
|
+
const existing = await getCurrentRecord(zoneId);
|
|
128
|
+
if (!existing) {
|
|
129
|
+
console.log('[R53] No _wab TXT record found — already disabled.');
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
await client.send(new ChangeResourceRecordSetsCommand({
|
|
133
|
+
HostedZoneId: zoneId,
|
|
134
|
+
ChangeBatch: {
|
|
135
|
+
Comment: 'WAB DNS Discovery disable',
|
|
136
|
+
Changes: [{ Action: 'DELETE', ResourceRecordSet: existing }],
|
|
137
|
+
},
|
|
138
|
+
}));
|
|
139
|
+
console.log('[R53] Record deleted');
|
|
140
|
+
console.log('[WAB] WAB Discovery DISABLED.');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
main().catch(err => { console.error('[ERROR]', err.message); process.exit(1); });
|