web-agent-bridge 1.0.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.ar.md +1 -1
  2. package/README.md +336 -36
  3. package/docs/DEPLOY.md +118 -0
  4. package/docs/SPEC.md +1540 -0
  5. package/examples/mcp-agent.js +94 -0
  6. package/examples/vision-agent.js +12 -0
  7. package/package.json +14 -3
  8. package/public/admin/dashboard.html +848 -0
  9. package/public/admin/login.html +84 -0
  10. package/public/cookies.html +208 -0
  11. package/public/css/premium.css +317 -0
  12. package/public/dashboard.html +138 -0
  13. package/public/docs.html +5 -2
  14. package/public/index.html +54 -28
  15. package/public/js/auth-nav.js +31 -0
  16. package/public/js/auth-redirect.js +12 -0
  17. package/public/js/cookie-consent.js +56 -0
  18. package/public/js/ws-client.js +74 -0
  19. package/public/login.html +4 -2
  20. package/public/premium-dashboard.html +2075 -0
  21. package/public/premium.html +791 -0
  22. package/public/privacy.html +295 -0
  23. package/public/register.html +11 -2
  24. package/public/terms.html +254 -0
  25. package/script/ai-agent-bridge.js +253 -22
  26. package/sdk/index.js +36 -0
  27. package/server/config/secrets.js +92 -0
  28. package/server/index.js +102 -26
  29. package/server/middleware/adminAuth.js +30 -0
  30. package/server/middleware/auth.js +4 -7
  31. package/server/middleware/rateLimits.js +24 -0
  32. package/server/migrations/001_add_analytics_indexes.sql +7 -0
  33. package/server/migrations/002_premium_features.sql +418 -0
  34. package/server/models/db.js +360 -4
  35. package/server/routes/admin.js +247 -0
  36. package/server/routes/api.js +26 -9
  37. package/server/routes/billing.js +45 -0
  38. package/server/routes/discovery.js +329 -0
  39. package/server/routes/license.js +200 -11
  40. package/server/routes/noscript.js +543 -0
  41. package/server/routes/premium.js +724 -0
  42. package/server/routes/wab-api.js +476 -0
  43. package/server/services/email.js +204 -0
  44. package/server/services/fairness.js +420 -0
  45. package/server/services/premium.js +1680 -0
  46. package/server/services/stripe.js +192 -0
  47. package/server/utils/cache.js +125 -0
  48. package/server/utils/migrate.js +81 -0
  49. package/server/utils/secureFields.js +50 -0
  50. package/server/ws.js +33 -13
  51. package/wab-mcp-adapter/README.md +136 -0
  52. package/wab-mcp-adapter/index.js +555 -0
  53. package/wab-mcp-adapter/package.json +17 -0
@@ -4,6 +4,17 @@
4
4
  <meta charset="UTF-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title>Dashboard — Web Agent Bridge</title>
7
+ <script>
8
+ (function () {
9
+ try {
10
+ if (!localStorage.getItem('wab_token')) {
11
+ window.location.replace('/login?next=' + encodeURIComponent(location.pathname || '/dashboard'));
12
+ }
13
+ } catch (e) {
14
+ window.location.replace('/login?next=/dashboard');
15
+ }
16
+ })();
17
+ </script>
7
18
  <link rel="preconnect" href="https://fonts.googleapis.com">
8
19
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
9
20
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
@@ -24,6 +35,7 @@
24
35
  <a href="#" class="active" data-view="overview">📊 Overview</a>
25
36
  <a href="#" data-view="sites">🌐 My Sites</a>
26
37
  <a href="#" data-view="analytics">📈 Analytics</a>
38
+ <a href="#" data-view="billing">💳 Billing</a>
27
39
  <a href="#" data-view="settings">⚙️ Settings</a>
28
40
  <a href="/docs" style="margin-top:20px;">📖 Documentation</a>
29
41
  </nav>
@@ -107,6 +119,82 @@
107
119
  </div>
108
120
  </div>
109
121
 
122
+ <!-- ── Billing View ── -->
123
+ <div id="view-billing" class="view">
124
+ <div class="page-header">
125
+ <h1>Billing & Subscription</h1>
126
+ </div>
127
+
128
+ <div class="stats-grid" style="grid-template-columns:repeat(3,1fr);margin-bottom:24px;">
129
+ <div class="stat-card">
130
+ <div class="label">Current Plan</div>
131
+ <div class="value" id="billingPlan" style="font-size:1.4rem;">Free</div>
132
+ </div>
133
+ <div class="stat-card">
134
+ <div class="label">Status</div>
135
+ <div class="value" id="billingStatus" style="font-size:1.2rem;">—</div>
136
+ </div>
137
+ <div class="stat-card">
138
+ <div class="label">Payments</div>
139
+ <div class="value" id="billingPayments">0</div>
140
+ </div>
141
+ </div>
142
+
143
+ <!-- Pricing Cards -->
144
+ <h3 style="margin-bottom:16px;">Upgrade Your Plan</h3>
145
+ <div class="grid-3" style="display:grid;grid-template-columns:repeat(3,1fr);gap:20px;margin-bottom:32px;" id="pricingCards">
146
+ <div class="card" style="border:1px solid var(--border-color);text-align:center;padding:32px 24px;">
147
+ <h3 style="margin-bottom:8px;">Starter</h3>
148
+ <div style="font-size:2rem;font-weight:700;margin:16px 0;">$19<span style="font-size:0.9rem;font-weight:400;color:var(--text-muted);">/mo</span></div>
149
+ <ul style="text-align:left;list-style:none;padding:0;margin:0 0 24px;font-size:0.9rem;color:var(--text-secondary);">
150
+ <li style="padding:6px 0;">✓ Up to 5 sites</li>
151
+ <li style="padding:6px 0;">✓ 10,000 actions/month</li>
152
+ <li style="padding:6px 0;">✓ Automated Login</li>
153
+ <li style="padding:6px 0;">✓ Email support</li>
154
+ </ul>
155
+ <button class="btn btn-secondary" onclick="startCheckout('starter')" style="width:100%;">Select Starter</button>
156
+ </div>
157
+ <div class="card" style="border:2px solid var(--accent-blue);text-align:center;padding:32px 24px;position:relative;">
158
+ <span style="position:absolute;top:-12px;left:50%;transform:translateX(-50%);background:var(--gradient-primary);padding:4px 16px;border-radius:12px;font-size:0.75rem;font-weight:600;">POPULAR</span>
159
+ <h3 style="margin-bottom:8px;">Pro</h3>
160
+ <div style="font-size:2rem;font-weight:700;margin:16px 0;">$49<span style="font-size:0.9rem;font-weight:400;color:var(--text-muted);">/mo</span></div>
161
+ <ul style="text-align:left;list-style:none;padding:0;margin:0 0 24px;font-size:0.9rem;color:var(--text-secondary);">
162
+ <li style="padding:6px 0;">✓ Up to 20 sites</li>
163
+ <li style="padding:6px 0;">✓ 100,000 actions/month</li>
164
+ <li style="padding:6px 0;">✓ API & Data Extraction</li>
165
+ <li style="padding:6px 0;">✓ Priority support</li>
166
+ </ul>
167
+ <button class="btn btn-primary" onclick="startCheckout('pro')" style="width:100%;">Select Pro</button>
168
+ </div>
169
+ <div class="card" style="border:1px solid var(--border-color);text-align:center;padding:32px 24px;">
170
+ <h3 style="margin-bottom:8px;">Enterprise</h3>
171
+ <div style="font-size:2rem;font-weight:700;margin:16px 0;">$149<span style="font-size:0.9rem;font-weight:400;color:var(--text-muted);">/mo</span></div>
172
+ <ul style="text-align:left;list-style:none;padding:0;margin:0 0 24px;font-size:0.9rem;color:var(--text-secondary);">
173
+ <li style="padding:6px 0;">✓ Unlimited sites</li>
174
+ <li style="padding:6px 0;">✓ Unlimited actions</li>
175
+ <li style="padding:6px 0;">✓ Dedicated support</li>
176
+ <li style="padding:6px 0;">✓ Custom integrations</li>
177
+ </ul>
178
+ <button class="btn btn-secondary" onclick="startCheckout('enterprise')" style="width:100%;">Select Enterprise</button>
179
+ </div>
180
+ </div>
181
+
182
+ <div style="display:flex;gap:12px;">
183
+ <button class="btn btn-secondary" onclick="openBillingPortal()">📋 Manage Subscription</button>
184
+ </div>
185
+
186
+ <!-- Payment History -->
187
+ <h3 style="margin:32px 0 16px;">Payment History</h3>
188
+ <div class="table-wrapper">
189
+ <table>
190
+ <thead><tr><th>Amount</th><th>Status</th><th>Description</th><th>Date</th></tr></thead>
191
+ <tbody id="paymentHistory">
192
+ <tr><td colspan="4" style="text-align:center;padding:40px;color:var(--text-muted);">No payments yet</td></tr>
193
+ </tbody>
194
+ </table>
195
+ </div>
196
+ </div>
197
+
110
198
  <!-- ── Settings View ── -->
111
199
  <div id="view-settings" class="view">
112
200
  <div class="page-header">
@@ -249,6 +337,7 @@
249
337
  document.querySelectorAll('.view').forEach(v => v.classList.remove('active'));
250
338
  const el = document.getElementById(`view-${view}`);
251
339
  if (el) el.classList.add('active');
340
+ if (view === 'billing') loadBilling();
252
341
  });
253
342
  });
254
343
 
@@ -554,6 +643,54 @@
554
643
  return d.innerHTML;
555
644
  }
556
645
 
646
+ // ─── Billing ─────────────────────────────────────────────────────────
647
+ async function loadBilling() {
648
+ try {
649
+ const sRes = await fetch(`${API}/sites`, { headers: headers() });
650
+ const sData = await sRes.json();
651
+ const mySites = sData.sites || [];
652
+ const topTier = mySites.reduce((best, s) => {
653
+ const order = { enterprise: 4, pro: 3, starter: 2, free: 1 };
654
+ return (order[s.tier] || 0) > (order[best] || 0) ? s.tier : best;
655
+ }, 'free');
656
+ document.getElementById('billingPlan').textContent = topTier.charAt(0).toUpperCase() + topTier.slice(1);
657
+ document.getElementById('billingStatus').textContent = topTier !== 'free' ? '✅ Active' : 'Free Tier';
658
+ } catch (err) { console.error(err); }
659
+ }
660
+
661
+ async function startCheckout(tier) {
662
+ try {
663
+ const siteId = sites.length > 0 ? sites[0].id : null;
664
+ if (!siteId) { alert('Please add a site first before subscribing.'); return; }
665
+ const res = await fetch('/api/billing/checkout', {
666
+ method: 'POST',
667
+ headers: headers(),
668
+ body: JSON.stringify({ tier, siteId })
669
+ });
670
+ const data = await res.json();
671
+ if (data.url) {
672
+ window.location.href = data.url;
673
+ } else {
674
+ alert(data.error || 'Failed to start checkout. Please ensure Stripe is configured.');
675
+ }
676
+ } catch (err) { alert('Connection error'); }
677
+ }
678
+
679
+ async function openBillingPortal() {
680
+ try {
681
+ const res = await fetch('/api/billing/portal', {
682
+ method: 'POST',
683
+ headers: headers()
684
+ });
685
+ const data = await res.json();
686
+ if (data.url) {
687
+ window.location.href = data.url;
688
+ } else {
689
+ alert(data.error || 'Could not open billing portal.');
690
+ }
691
+ } catch (err) { alert('Connection error'); }
692
+ }
693
+
557
694
  // ─── View toggling style ────────────────────────────────────────────
558
695
  const style = document.createElement('style');
559
696
  style.textContent = '.view { display: none; } .view.active { display: block; }';
@@ -562,5 +699,6 @@
562
699
  // ─── Start ──────────────────────────────────────────────────────────
563
700
  init();
564
701
  </script>
702
+ <script src="/js/cookie-consent.js"></script>
565
703
  </body>
566
704
  </html>
package/public/docs.html CHANGED
@@ -24,8 +24,9 @@
24
24
  <li><a href="/docs" style="color:var(--text-primary);">Docs</a></li>
25
25
  </ul>
26
26
  <div class="navbar-actions">
27
- <a href="/dashboard" class="btn btn-ghost">Dashboard</a>
28
- <a href="/register" class="btn btn-primary btn-sm">Get Started</a>
27
+ <a href="/login" class="btn btn-ghost" data-wab-auth="guest">Sign In</a>
28
+ <a href="/dashboard" class="btn btn-primary btn-sm" data-wab-auth="signed-in" style="display:none">Dashboard</a>
29
+ <a href="/register" class="btn btn-primary btn-sm" data-wab-auth="guest">Get Started</a>
29
30
  </div>
30
31
  </div>
31
32
  </nav>
@@ -564,6 +565,7 @@ document.<span class="fn">addEventListener</span>(<span class="str">'wab:ready'<
564
565
  </div>
565
566
  </footer>
566
567
 
568
+ <script src="/js/auth-nav.js"></script>
567
569
  <script>
568
570
  const links = document.querySelectorAll('.docs-sidebar a');
569
571
  const observer = new IntersectionObserver((entries) => {
@@ -578,5 +580,6 @@ document.<span class="fn">addEventListener</span>(<span class="str">'wab:ready'<
578
580
 
579
581
  document.querySelectorAll('.docs-content h2[id]').forEach(h => observer.observe(h));
580
582
  </script>
583
+ <script src="/js/cookie-consent.js"></script>
581
584
  </body>
582
585
  </html>
package/public/index.html CHANGED
@@ -23,11 +23,13 @@
23
23
  <li><a href="#features">Features</a></li>
24
24
  <li><a href="#how-it-works">How It Works</a></li>
25
25
  <li><a href="#pricing">Pricing</a></li>
26
+ <li><a href="/premium">Premium</a></li>
26
27
  <li><a href="/docs">Docs</a></li>
27
28
  </ul>
28
29
  <div class="navbar-actions">
29
- <a href="/login" class="btn btn-ghost">Sign In</a>
30
- <a href="/register" class="btn btn-primary btn-sm">Get Started</a>
30
+ <a href="/login" class="btn btn-ghost" data-wab-auth="guest">Sign In</a>
31
+ <a href="/dashboard" class="btn btn-ghost" data-wab-auth="signed-in" style="display:none">Dashboard</a>
32
+ <a href="/register" class="btn btn-primary btn-sm" data-wab-auth="guest">Get Started</a>
31
33
  </div>
32
34
  <button class="mobile-menu-btn" onclick="document.querySelector('.navbar-links').classList.toggle('active')">☰</button>
33
35
  </div>
@@ -58,7 +60,7 @@
58
60
  <span class="comment">// Add the bridge to your website</span><br>
59
61
  &lt;<span class="keyword">script</span>&gt;<br>
60
62
  &nbsp;&nbsp;window.<span class="property">AIBridgeConfig</span> = {<br>
61
- &nbsp;&nbsp;&nbsp;&nbsp;<span class="property">licenseKey</span>: <span class="string">"WAB-XXXXX-XXXXX"</span>,<br>
63
+ &nbsp;&nbsp;&nbsp;&nbsp;<span class="property">siteId</span>: <span class="string">"your-site-id"</span>,<br>
62
64
  &nbsp;&nbsp;&nbsp;&nbsp;<span class="property">agentPermissions</span>: { <span class="property">click</span>: <span class="boolean">true</span>, <span class="property">fillForms</span>: <span class="boolean">true</span> }<br>
63
65
  &nbsp;&nbsp;};<br>
64
66
  &lt;/<span class="keyword">script</span>&gt;<br>
@@ -176,40 +178,57 @@ console.<span class="fn">log</span>(actions);
176
178
  <div class="section-header">
177
179
  <span class="label">Pricing</span>
178
180
  <h2>Simple, Transparent Pricing</h2>
179
- <p>Start free, upgrade when you need advanced features. Open source forever.</p>
181
+ <p>Start free, upgrade when you need advanced features. Open source core forever.</p>
180
182
  </div>
181
183
 
182
- <div class="grid-3">
184
+ <div class="grid-4">
183
185
  <div class="pricing-card">
184
186
  <div class="pricing-tier">Free</div>
185
187
  <div class="pricing-price">$0 <span>/mo</span></div>
186
- <div class="pricing-desc">Perfect for personal projects and experimentation.</div>
188
+ <div class="pricing-desc">Personal projects and experimentation.</div>
187
189
  <ul class="pricing-features">
188
190
  <li>Auto-discovery of actions</li>
189
191
  <li>Click &amp; scroll permissions</li>
190
192
  <li>Rate limiting (60/min)</li>
191
193
  <li>Basic logging</li>
192
194
  <li>1 site</li>
195
+ <li>Community support</li>
193
196
  <li class="disabled">Form filling</li>
194
- <li class="disabled">API access</li>
195
197
  <li class="disabled">Analytics dashboard</li>
196
198
  </ul>
197
199
  <a href="/register" class="btn btn-secondary" style="width:100%;">Get Started Free</a>
198
200
  </div>
199
201
 
202
+ <div class="pricing-card">
203
+ <div class="pricing-tier">Starter</div>
204
+ <div class="pricing-price">$9 <span>/mo</span></div>
205
+ <div class="pricing-desc">Small sites with basic analytics &amp; protection.</div>
206
+ <ul class="pricing-features">
207
+ <li>Everything in Free</li>
208
+ <li>Form filling &amp; submit</li>
209
+ <li>Agent Traffic Intelligence</li>
210
+ <li>Smart Actions (basic)</li>
211
+ <li>Up to 3 sites</li>
212
+ <li>Automated login support</li>
213
+ <li>Same-day email support</li>
214
+ <li class="disabled">API access</li>
215
+ </ul>
216
+ <a href="/register" class="btn btn-secondary" style="width:100%;">Start Starter</a>
217
+ </div>
218
+
200
219
  <div class="pricing-card featured">
201
220
  <div class="pricing-tier">Pro</div>
202
221
  <div class="pricing-price">$29 <span>/mo</span></div>
203
- <div class="pricing-desc">For businesses that want full AI agent integration.</div>
222
+ <div class="pricing-desc">Full power for businesses and teams.</div>
204
223
  <ul class="pricing-features">
205
- <li>Everything in Free</li>
206
- <li>Form filling &amp; submission</li>
224
+ <li>Everything in Starter</li>
207
225
  <li>Internal API access</li>
208
- <li>Advanced analytics</li>
226
+ <li>Advanced Exploit Shield</li>
227
+ <li>CRM &amp; Cloud Integrations</li>
209
228
  <li>Up to 10 sites</li>
210
- <li>Automated login support</li>
211
- <li>Data extraction</li>
212
- <li>Priority support</li>
229
+ <li>Custom Bridge Script</li>
230
+ <li>Stealth Mode Pro</li>
231
+ <li>Private CDN + 1h support</li>
213
232
  </ul>
214
233
  <a href="/register" class="btn btn-primary" style="width:100%;">Start Pro Trial</a>
215
234
  </div>
@@ -217,20 +236,26 @@ console.<span class="fn">log</span>(actions);
217
236
  <div class="pricing-card">
218
237
  <div class="pricing-tier">Enterprise</div>
219
238
  <div class="pricing-price">Custom</div>
220
- <div class="pricing-desc">Custom solutions for large-scale deployments.</div>
239
+ <div class="pricing-desc">Unlimited scale with compliance &amp; SLA.</div>
221
240
  <ul class="pricing-features">
222
241
  <li>Everything in Pro</li>
223
- <li>Unlimited sites</li>
224
- <li>Custom rate limits</li>
225
- <li>Webhook integrations</li>
242
+ <li>Unlimited sites &amp; agents</li>
243
+ <li>Multi-tenant management</li>
244
+ <li>Extended Audit &amp; Compliance</li>
245
+ <li>Virtual Sandbox</li>
226
246
  <li>SSO / SAML</li>
227
- <li>Dedicated support</li>
228
- <li>SLA guarantee</li>
247
+ <li>15-min SLA guarantee</li>
229
248
  <li>Custom development</li>
230
249
  </ul>
231
250
  <a href="mailto:sales@webagentbridge.com" class="btn btn-secondary" style="width:100%;">Contact Sales</a>
232
251
  </div>
233
252
  </div>
253
+
254
+ <div style="text-align:center;margin-top:40px;">
255
+ <a href="/premium" class="btn btn-ghost" style="color:var(--accent-purple);">
256
+ View all 12 premium services in detail &rarr;
257
+ </a>
258
+ </div>
234
259
  </div>
235
260
  </section>
236
261
 
@@ -263,9 +288,10 @@ console.<span class="fn">log</span>(actions);
263
288
  <h4>Product</h4>
264
289
  <ul>
265
290
  <li><a href="#features">Features</a></li>
291
+ <li><a href="/premium">Premium Services</a></li>
266
292
  <li><a href="#pricing">Pricing</a></li>
267
293
  <li><a href="/docs">Documentation</a></li>
268
- <li><a href="/dashboard">Dashboard</a></li>
294
+ <li data-wab-auth="signed-in" style="display:none"><a href="/dashboard">Dashboard</a></li>
269
295
  </ul>
270
296
  </div>
271
297
  <div class="footer-col">
@@ -278,22 +304,21 @@ console.<span class="fn">log</span>(actions);
278
304
  </ul>
279
305
  </div>
280
306
  <div class="footer-col">
281
- <h4>Company</h4>
307
+ <h4>Legal</h4>
282
308
  <ul>
283
- <li><a href="#">About</a></li>
284
- <li><a href="#">Blog</a></li>
285
- <li><a href="#">Contact</a></li>
286
- <li><a href="#">Privacy Policy</a></li>
309
+ <li><a href="/privacy">Privacy Policy</a></li>
310
+ <li><a href="/terms">Terms of Service</a></li>
311
+ <li><a href="/cookies">Cookie Policy</a></li>
287
312
  </ul>
288
313
  </div>
289
314
  </div>
290
315
  <div class="footer-bottom">
291
- <span>&copy; 2026 Web Agent Bridge. MIT License.</span>
292
- <span>Built with care for the AI-powered web</span>
316
+ <span>&copy; 2026 Web Agent Bridge. MIT License. Operated from the Netherlands.</span>
293
317
  </div>
294
318
  </div>
295
319
  </footer>
296
320
 
321
+ <script src="/js/auth-nav.js"></script>
297
322
  <script>
298
323
  const navbar = document.getElementById('navbar');
299
324
  window.addEventListener('scroll', () => {
@@ -302,5 +327,6 @@ console.<span class="fn">log</span>(actions);
302
327
  : 'rgba(10, 14, 26, 0.8)';
303
328
  });
304
329
  </script>
330
+ <script src="/js/cookie-consent.js"></script>
305
331
  </body>
306
332
  </html>
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Shows / hides UI by auth state using data-wab-auth="signed-in" | "guest"
3
+ * Run on DOMContentLoaded — keep dashboard links only for signed-in users.
4
+ */
5
+ (function () {
6
+ function hasToken() {
7
+ try {
8
+ return !!localStorage.getItem('wab_token');
9
+ } catch (e) {
10
+ return false;
11
+ }
12
+ }
13
+
14
+ function apply() {
15
+ var signedIn = hasToken();
16
+ document.querySelectorAll('[data-wab-auth]').forEach(function (el) {
17
+ var mode = el.getAttribute('data-wab-auth');
18
+ if (mode === 'signed-in') {
19
+ el.style.display = signedIn ? '' : 'none';
20
+ } else if (mode === 'guest') {
21
+ el.style.display = signedIn ? 'none' : '';
22
+ }
23
+ });
24
+ }
25
+
26
+ if (document.readyState === 'loading') {
27
+ document.addEventListener('DOMContentLoaded', apply);
28
+ } else {
29
+ apply();
30
+ }
31
+ })();
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Safe redirect target after login/register (?next=/path)
3
+ */
4
+ (function () {
5
+ window.wabGetPostAuthRedirect = function () {
6
+ try {
7
+ var p = new URLSearchParams(window.location.search).get('next');
8
+ if (p && p.charAt(0) === '/' && p.indexOf('//') !== 0) return p;
9
+ } catch (e) {}
10
+ return '/dashboard';
11
+ };
12
+ })();
@@ -0,0 +1,56 @@
1
+ /**
2
+ * WAB Cookie Consent Banner
3
+ * Compliant with EU ePrivacy Directive & Dutch Telecommunicatiewet Art. 11.7a
4
+ * Auto-injects a cookie consent banner if user hasn't consented yet.
5
+ */
6
+ (function () {
7
+ if (localStorage.getItem('wab_cookie_consent')) return;
8
+
9
+ var banner = document.createElement('div');
10
+ banner.id = 'wab-cookie-banner';
11
+ banner.setAttribute('role', 'dialog');
12
+ banner.setAttribute('aria-label', 'Cookie consent');
13
+ banner.innerHTML =
14
+ '<div class="wab-cookie-inner">' +
15
+ '<p>We use essential cookies (authentication tokens) to keep you signed in. ' +
16
+ 'We do not use tracking or marketing cookies. ' +
17
+ 'See our <a href="/cookies">Cookie Policy</a> and <a href="/privacy">Privacy Policy</a>.</p>' +
18
+ '<div class="wab-cookie-actions">' +
19
+ '<button id="wab-cookie-accept" class="wab-cookie-btn wab-cookie-btn-primary">Accept</button>' +
20
+ '<button id="wab-cookie-decline" class="wab-cookie-btn wab-cookie-btn-ghost">Essential Only</button>' +
21
+ '</div>' +
22
+ '</div>';
23
+
24
+ var style = document.createElement('style');
25
+ style.textContent =
26
+ '#wab-cookie-banner{position:fixed;bottom:0;left:0;right:0;z-index:10000;' +
27
+ 'background:rgba(10,14,26,0.97);border-top:1px solid rgba(59,130,246,0.2);' +
28
+ 'padding:16px 0;font-family:Inter,system-ui,sans-serif;backdrop-filter:blur(12px)}' +
29
+ '.wab-cookie-inner{max-width:960px;margin:0 auto;padding:0 24px;display:flex;' +
30
+ 'align-items:center;gap:20px;flex-wrap:wrap}' +
31
+ '.wab-cookie-inner p{flex:1;min-width:280px;color:#94a3b8;font-size:0.875rem;line-height:1.6;margin:0}' +
32
+ '.wab-cookie-inner a{color:#3b82f6;text-decoration:none}' +
33
+ '.wab-cookie-inner a:hover{text-decoration:underline}' +
34
+ '.wab-cookie-actions{display:flex;gap:10px;flex-shrink:0}' +
35
+ '.wab-cookie-btn{padding:8px 20px;border-radius:8px;font-size:0.85rem;font-weight:500;cursor:pointer;' +
36
+ 'border:none;transition:all 0.2s}' +
37
+ '.wab-cookie-btn-primary{background:#3b82f6;color:#fff}' +
38
+ '.wab-cookie-btn-primary:hover{background:#2563eb}' +
39
+ '.wab-cookie-btn-ghost{background:transparent;color:#94a3b8;border:1px solid rgba(148,163,184,0.3)}' +
40
+ '.wab-cookie-btn-ghost:hover{color:#e2e8f0;border-color:rgba(148,163,184,0.5)}' +
41
+ '@media(max-width:600px){.wab-cookie-inner{flex-direction:column;text-align:center}' +
42
+ '.wab-cookie-actions{width:100%;justify-content:center}}';
43
+
44
+ document.head.appendChild(style);
45
+ document.body.appendChild(banner);
46
+
47
+ document.getElementById('wab-cookie-accept').addEventListener('click', function () {
48
+ localStorage.setItem('wab_cookie_consent', 'all');
49
+ banner.remove();
50
+ });
51
+
52
+ document.getElementById('wab-cookie-decline').addEventListener('click', function () {
53
+ localStorage.setItem('wab_cookie_consent', 'essential');
54
+ banner.remove();
55
+ });
56
+ })();
@@ -0,0 +1,74 @@
1
+ /**
2
+ * WAB WebSocket Client with auto-reconnect and exponential backoff
3
+ * Usage:
4
+ * const ws = new WABWebSocket(token, siteId);
5
+ * ws.on('analytic', (data) => console.log(data));
6
+ * ws.connect();
7
+ */
8
+ class WABWebSocket {
9
+ constructor(token, siteId, options = {}) {
10
+ this.token = token;
11
+ this.siteId = siteId;
12
+ this.maxRetries = options.maxRetries || 10;
13
+ this.baseDelay = options.baseDelay || 1000;
14
+ this.maxDelay = options.maxDelay || 30000;
15
+ this._retries = 0;
16
+ this._ws = null;
17
+ this._listeners = {};
18
+ this._closed = false;
19
+ }
20
+
21
+ connect() {
22
+ if (this._closed) return;
23
+ const proto = location.protocol === 'https:' ? 'wss:' : 'ws:';
24
+ this._ws = new WebSocket(`${proto}//${location.host}/ws/analytics`);
25
+
26
+ this._ws.onopen = () => {
27
+ this._retries = 0;
28
+ this._ws.send(JSON.stringify({ type: 'auth', token: this.token, siteId: this.siteId }));
29
+ this._emit('connected');
30
+ };
31
+
32
+ this._ws.onmessage = (e) => {
33
+ try {
34
+ const msg = JSON.parse(e.data);
35
+ this._emit(msg.type, msg);
36
+ } catch { /* ignore malformed */ }
37
+ };
38
+
39
+ this._ws.onclose = () => {
40
+ this._emit('disconnected');
41
+ this._reconnect();
42
+ };
43
+
44
+ this._ws.onerror = () => {
45
+ this._ws.close();
46
+ };
47
+ }
48
+
49
+ _reconnect() {
50
+ if (this._closed || this._retries >= this.maxRetries) {
51
+ this._emit('max_retries');
52
+ return;
53
+ }
54
+ const delay = Math.min(this.baseDelay * Math.pow(2, this._retries), this.maxDelay);
55
+ const jitter = delay * (0.5 + Math.random() * 0.5);
56
+ this._retries++;
57
+ this._emit('reconnecting', { attempt: this._retries, delay: Math.round(jitter) });
58
+ setTimeout(() => this.connect(), jitter);
59
+ }
60
+
61
+ on(event, cb) {
62
+ if (!this._listeners[event]) this._listeners[event] = [];
63
+ this._listeners[event].push(cb);
64
+ }
65
+
66
+ _emit(event, data) {
67
+ (this._listeners[event] || []).forEach(cb => { try { cb(data); } catch {} });
68
+ }
69
+
70
+ close() {
71
+ this._closed = true;
72
+ if (this._ws) this._ws.close();
73
+ }
74
+ }
package/public/login.html CHANGED
@@ -8,6 +8,7 @@
8
8
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
9
9
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
10
10
  <link rel="stylesheet" href="/css/styles.css">
11
+ <script src="/js/auth-redirect.js"></script>
11
12
  </head>
12
13
  <body>
13
14
  <div class="auth-page">
@@ -43,7 +44,7 @@
43
44
 
44
45
  <script>
45
46
  if (localStorage.getItem('wab_token')) {
46
- window.location.href = '/dashboard';
47
+ window.location.replace(typeof wabGetPostAuthRedirect === 'function' ? wabGetPostAuthRedirect() : '/dashboard');
47
48
  }
48
49
 
49
50
  document.getElementById('loginForm').addEventListener('submit', async (e) => {
@@ -70,12 +71,13 @@
70
71
 
71
72
  localStorage.setItem('wab_token', data.token);
72
73
  localStorage.setItem('wab_user', JSON.stringify(data.user));
73
- window.location.href = '/dashboard';
74
+ window.location.href = typeof wabGetPostAuthRedirect === 'function' ? wabGetPostAuthRedirect() : '/dashboard';
74
75
  } catch (err) {
75
76
  errorEl.textContent = 'Connection error. Please try again.';
76
77
  errorEl.style.display = 'block';
77
78
  }
78
79
  });
79
80
  </script>
81
+ <script src="/js/cookie-consent.js"></script>
80
82
  </body>
81
83
  </html>