web-agent-bridge 1.1.1 → 1.1.2

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 (66) hide show
  1. package/LICENSE +21 -21
  2. package/README.ar.md +446 -446
  3. package/README.md +844 -844
  4. package/bin/cli.js +80 -80
  5. package/bin/wab.js +80 -80
  6. package/docs/DEPLOY.md +118 -118
  7. package/docs/SPEC.md +1540 -1540
  8. package/examples/bidi-agent.js +119 -119
  9. package/examples/mcp-agent.js +94 -94
  10. package/examples/puppeteer-agent.js +108 -108
  11. package/examples/vision-agent.js +171 -171
  12. package/package.json +78 -78
  13. package/public/admin/dashboard.html +848 -848
  14. package/public/admin/login.html +84 -84
  15. package/public/cookies.html +208 -208
  16. package/public/css/styles.css +1235 -1235
  17. package/public/dashboard.html +704 -704
  18. package/public/docs.html +585 -585
  19. package/public/index.html +332 -332
  20. package/public/js/auth-nav.js +31 -31
  21. package/public/js/auth-redirect.js +12 -12
  22. package/public/js/cookie-consent.js +56 -56
  23. package/public/js/ws-client.js +74 -74
  24. package/public/login.html +83 -83
  25. package/public/privacy.html +295 -295
  26. package/public/register.html +103 -103
  27. package/public/terms.html +254 -254
  28. package/script/ai-agent-bridge.js +1513 -1513
  29. package/sdk/README.md +55 -55
  30. package/sdk/index.js +203 -203
  31. package/sdk/package.json +14 -14
  32. package/server/config/secrets.js +92 -92
  33. package/server/index.js +181 -181
  34. package/server/middleware/adminAuth.js +30 -30
  35. package/server/middleware/auth.js +41 -41
  36. package/server/middleware/rateLimits.js +24 -24
  37. package/server/migrations/001_add_analytics_indexes.sql +7 -7
  38. package/server/models/adapters/index.js +33 -33
  39. package/server/models/adapters/mysql.js +183 -183
  40. package/server/models/adapters/postgresql.js +172 -172
  41. package/server/models/adapters/sqlite.js +7 -7
  42. package/server/models/db.js +561 -561
  43. package/server/routes/admin.js +247 -247
  44. package/server/routes/api.js +138 -138
  45. package/server/routes/auth.js +51 -51
  46. package/server/routes/billing.js +45 -45
  47. package/server/routes/discovery.js +329 -329
  48. package/server/routes/license.js +240 -240
  49. package/server/routes/noscript.js +543 -543
  50. package/server/routes/wab-api.js +476 -476
  51. package/server/services/email.js +204 -204
  52. package/server/services/fairness.js +420 -420
  53. package/server/services/stripe.js +192 -192
  54. package/server/utils/cache.js +125 -125
  55. package/server/utils/migrate.js +81 -81
  56. package/server/utils/secureFields.js +50 -50
  57. package/server/ws.js +101 -101
  58. package/wab-mcp-adapter/README.md +136 -136
  59. package/wab-mcp-adapter/index.js +555 -555
  60. package/wab-mcp-adapter/package.json +17 -17
  61. package/public/css/premium.css +0 -317
  62. package/public/premium-dashboard.html +0 -2075
  63. package/public/premium.html +0 -791
  64. package/server/migrations/002_premium_features.sql +0 -418
  65. package/server/routes/premium.js +0 -724
  66. package/server/services/premium.js +0 -1680
@@ -1,31 +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
- })();
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
+ })();
@@ -1,12 +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
- })();
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
+ })();
@@ -1,56 +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
- })();
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
+ })();
@@ -1,74 +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
- }
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
@@ -1,83 +1,83 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Sign In — Web Agent Bridge</title>
7
- <link rel="preconnect" href="https://fonts.googleapis.com">
8
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
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
- <link rel="stylesheet" href="/css/styles.css">
11
- <script src="/js/auth-redirect.js"></script>
12
- </head>
13
- <body>
14
- <div class="auth-page">
15
- <div class="auth-card fade-in">
16
- <div style="text-align:center; margin-bottom:32px;">
17
- <a href="/" class="navbar-brand" style="justify-content:center;">
18
- <div class="brand-icon">⚡</div>
19
- <span>WAB</span>
20
- </a>
21
- </div>
22
- <h1 style="text-align:center;">Welcome back</h1>
23
- <p class="subtitle" style="text-align:center;">Sign in to your account</p>
24
-
25
- <div class="alert alert-error" id="errorAlert"></div>
26
-
27
- <form id="loginForm">
28
- <div class="form-group">
29
- <label for="email">Email</label>
30
- <input type="email" id="email" class="form-input" placeholder="you@example.com" required>
31
- </div>
32
- <div class="form-group">
33
- <label for="password">Password</label>
34
- <input type="password" id="password" class="form-input" placeholder="Your password" required>
35
- </div>
36
- <button type="submit" class="btn btn-primary btn-lg">Sign In</button>
37
- </form>
38
-
39
- <div class="auth-footer">
40
- Don't have an account? <a href="/register">Create one</a>
41
- </div>
42
- </div>
43
- </div>
44
-
45
- <script>
46
- if (localStorage.getItem('wab_token')) {
47
- window.location.replace(typeof wabGetPostAuthRedirect === 'function' ? wabGetPostAuthRedirect() : '/dashboard');
48
- }
49
-
50
- document.getElementById('loginForm').addEventListener('submit', async (e) => {
51
- e.preventDefault();
52
- const errorEl = document.getElementById('errorAlert');
53
- errorEl.style.display = 'none';
54
-
55
- const email = document.getElementById('email').value;
56
- const password = document.getElementById('password').value;
57
-
58
- try {
59
- const res = await fetch('/api/auth/login', {
60
- method: 'POST',
61
- headers: { 'Content-Type': 'application/json' },
62
- body: JSON.stringify({ email, password })
63
- });
64
- const data = await res.json();
65
-
66
- if (!res.ok) {
67
- errorEl.textContent = data.error || 'Login failed';
68
- errorEl.style.display = 'block';
69
- return;
70
- }
71
-
72
- localStorage.setItem('wab_token', data.token);
73
- localStorage.setItem('wab_user', JSON.stringify(data.user));
74
- window.location.href = typeof wabGetPostAuthRedirect === 'function' ? wabGetPostAuthRedirect() : '/dashboard';
75
- } catch (err) {
76
- errorEl.textContent = 'Connection error. Please try again.';
77
- errorEl.style.display = 'block';
78
- }
79
- });
80
- </script>
81
- <script src="/js/cookie-consent.js"></script>
82
- </body>
83
- </html>
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Sign In — Web Agent Bridge</title>
7
+ <link rel="preconnect" href="https://fonts.googleapis.com">
8
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
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
+ <link rel="stylesheet" href="/css/styles.css">
11
+ <script src="/js/auth-redirect.js"></script>
12
+ </head>
13
+ <body>
14
+ <div class="auth-page">
15
+ <div class="auth-card fade-in">
16
+ <div style="text-align:center; margin-bottom:32px;">
17
+ <a href="/" class="navbar-brand" style="justify-content:center;">
18
+ <div class="brand-icon">⚡</div>
19
+ <span>WAB</span>
20
+ </a>
21
+ </div>
22
+ <h1 style="text-align:center;">Welcome back</h1>
23
+ <p class="subtitle" style="text-align:center;">Sign in to your account</p>
24
+
25
+ <div class="alert alert-error" id="errorAlert"></div>
26
+
27
+ <form id="loginForm">
28
+ <div class="form-group">
29
+ <label for="email">Email</label>
30
+ <input type="email" id="email" class="form-input" placeholder="you@example.com" required>
31
+ </div>
32
+ <div class="form-group">
33
+ <label for="password">Password</label>
34
+ <input type="password" id="password" class="form-input" placeholder="Your password" required>
35
+ </div>
36
+ <button type="submit" class="btn btn-primary btn-lg">Sign In</button>
37
+ </form>
38
+
39
+ <div class="auth-footer">
40
+ Don't have an account? <a href="/register">Create one</a>
41
+ </div>
42
+ </div>
43
+ </div>
44
+
45
+ <script>
46
+ if (localStorage.getItem('wab_token')) {
47
+ window.location.replace(typeof wabGetPostAuthRedirect === 'function' ? wabGetPostAuthRedirect() : '/dashboard');
48
+ }
49
+
50
+ document.getElementById('loginForm').addEventListener('submit', async (e) => {
51
+ e.preventDefault();
52
+ const errorEl = document.getElementById('errorAlert');
53
+ errorEl.style.display = 'none';
54
+
55
+ const email = document.getElementById('email').value;
56
+ const password = document.getElementById('password').value;
57
+
58
+ try {
59
+ const res = await fetch('/api/auth/login', {
60
+ method: 'POST',
61
+ headers: { 'Content-Type': 'application/json' },
62
+ body: JSON.stringify({ email, password })
63
+ });
64
+ const data = await res.json();
65
+
66
+ if (!res.ok) {
67
+ errorEl.textContent = data.error || 'Login failed';
68
+ errorEl.style.display = 'block';
69
+ return;
70
+ }
71
+
72
+ localStorage.setItem('wab_token', data.token);
73
+ localStorage.setItem('wab_user', JSON.stringify(data.user));
74
+ window.location.href = typeof wabGetPostAuthRedirect === 'function' ? wabGetPostAuthRedirect() : '/dashboard';
75
+ } catch (err) {
76
+ errorEl.textContent = 'Connection error. Please try again.';
77
+ errorEl.style.display = 'block';
78
+ }
79
+ });
80
+ </script>
81
+ <script src="/js/cookie-consent.js"></script>
82
+ </body>
83
+ </html>