web-agent-bridge 1.1.2 → 2.0.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 (94) hide show
  1. package/LICENSE +21 -21
  2. package/README.ar.md +446 -446
  3. package/README.md +780 -844
  4. package/bin/cli.js +80 -80
  5. package/bin/wab.js +80 -80
  6. package/examples/bidi-agent.js +119 -119
  7. package/examples/mcp-agent.js +94 -94
  8. package/examples/next-app-router/README.md +44 -0
  9. package/examples/puppeteer-agent.js +108 -108
  10. package/examples/saas-dashboard/README.md +55 -0
  11. package/examples/shopify-hydrogen/README.md +74 -0
  12. package/examples/vision-agent.js +171 -171
  13. package/examples/wordpress-elementor/README.md +77 -0
  14. package/package.json +69 -78
  15. package/public/.well-known/ai-assets.json +59 -0
  16. package/public/admin/login.html +84 -84
  17. package/public/ai.html +196 -0
  18. package/public/cookies.html +208 -208
  19. package/public/css/premium.css +317 -0
  20. package/public/css/styles.css +1235 -1235
  21. package/public/dashboard.html +704 -704
  22. package/public/demo.html +259 -0
  23. package/public/docs.html +585 -585
  24. package/public/feed.xml +89 -0
  25. package/public/index.html +495 -332
  26. package/public/js/auth-nav.js +31 -31
  27. package/public/js/auth-redirect.js +12 -12
  28. package/public/js/cookie-consent.js +56 -56
  29. package/public/js/wab-demo-page.js +721 -0
  30. package/public/js/ws-client.js +74 -74
  31. package/public/llms-full.txt +309 -0
  32. package/public/llms.txt +85 -0
  33. package/public/login.html +83 -83
  34. package/public/openapi.json +580 -0
  35. package/public/premium-dashboard.html +2487 -0
  36. package/public/premium.html +791 -0
  37. package/public/privacy.html +295 -295
  38. package/public/register.html +103 -103
  39. package/public/robots.txt +87 -0
  40. package/public/script/wab-consent.d.ts +36 -0
  41. package/public/script/wab-consent.js +104 -0
  42. package/public/script/wab-schema.js +131 -0
  43. package/public/script/wab.d.ts +108 -0
  44. package/public/script/wab.min.js +234 -0
  45. package/public/sitemap.xml +93 -0
  46. package/public/terms.html +254 -254
  47. package/public/video/tutorial.mp4 +0 -0
  48. package/script/ai-agent-bridge.js +1558 -1513
  49. package/sdk/README.md +55 -55
  50. package/sdk/index.d.ts +118 -0
  51. package/sdk/index.js +257 -203
  52. package/sdk/package.json +14 -14
  53. package/sdk/schema-discovery.js +83 -0
  54. package/server/config/secrets.js +94 -92
  55. package/server/index.js +0 -9
  56. package/server/middleware/adminAuth.js +30 -30
  57. package/server/middleware/auth.js +41 -41
  58. package/server/middleware/rateLimits.js +24 -24
  59. package/server/migrations/001_add_analytics_indexes.sql +7 -7
  60. package/server/migrations/002_premium_features.sql +418 -0
  61. package/server/models/adapters/index.js +33 -33
  62. package/server/models/adapters/mysql.js +183 -183
  63. package/server/models/adapters/postgresql.js +172 -172
  64. package/server/models/adapters/sqlite.js +7 -7
  65. package/server/models/db.js +561 -561
  66. package/server/routes/admin-premium.js +671 -0
  67. package/server/routes/admin.js +247 -247
  68. package/server/routes/api.js +131 -138
  69. package/server/routes/auth.js +51 -51
  70. package/server/routes/billing.js +45 -45
  71. package/server/routes/discovery.js +406 -329
  72. package/server/routes/license.js +240 -240
  73. package/server/routes/noscript.js +543 -543
  74. package/server/routes/premium-v2.js +686 -0
  75. package/server/routes/premium.js +724 -0
  76. package/server/routes/wab-api.js +476 -476
  77. package/server/services/agent-memory.js +625 -0
  78. package/server/services/email.js +204 -204
  79. package/server/services/fairness.js +420 -420
  80. package/server/services/plugins.js +747 -0
  81. package/server/services/premium.js +1883 -0
  82. package/server/services/self-healing.js +843 -0
  83. package/server/services/stripe.js +192 -192
  84. package/server/services/swarm.js +788 -0
  85. package/server/services/vision.js +871 -0
  86. package/server/utils/cache.js +125 -125
  87. package/server/utils/migrate.js +81 -81
  88. package/server/utils/secureFields.js +50 -50
  89. package/server/ws.js +101 -101
  90. package/docs/DEPLOY.md +0 -118
  91. package/docs/SPEC.md +0 -1540
  92. package/wab-mcp-adapter/README.md +0 -136
  93. package/wab-mcp-adapter/index.js +0 -555
  94. package/wab-mcp-adapter/package.json +0 -17
@@ -1,192 +1,192 @@
1
- /**
2
- * Stripe Payment Integration Service
3
- */
4
-
5
- const {
6
- getPlatformSetting,
7
- saveStripeCustomer,
8
- getStripeCustomer,
9
- saveStripeSubscription,
10
- updateStripeSubscription,
11
- getStripeSubscriptionBySubId,
12
- savePayment,
13
- updateSiteTier,
14
- findSiteById
15
- } = require('../models/db');
16
-
17
- let stripe = null;
18
-
19
- function getStripe() {
20
- if (stripe) return stripe;
21
- const key = process.env.STRIPE_SECRET_KEY || getPlatformSetting('stripe_secret_key');
22
- if (!key) return null;
23
- stripe = require('stripe')(key);
24
- return stripe;
25
- }
26
-
27
- function getStripePrices() {
28
- return {
29
- starter: process.env.STRIPE_PRICE_STARTER || getPlatformSetting('stripe_price_starter'),
30
- pro: process.env.STRIPE_PRICE_PRO || getPlatformSetting('stripe_price_pro'),
31
- enterprise: process.env.STRIPE_PRICE_ENTERPRISE || getPlatformSetting('stripe_price_enterprise')
32
- };
33
- }
34
-
35
- async function createCheckoutSession({ userId, userEmail, siteId, tier }) {
36
- const site = findSiteById.get(siteId);
37
- if (!site || site.user_id !== userId) {
38
- throw new Error('Site not found or access denied');
39
- }
40
-
41
- const s = getStripe();
42
- if (!s) throw new Error('Stripe not configured');
43
-
44
- const prices = getStripePrices();
45
- const priceId = prices[tier];
46
- if (!priceId) throw new Error(`No price configured for tier: ${tier}`);
47
-
48
- // Get or create Stripe customer
49
- let customer = getStripeCustomer(userId);
50
- if (!customer) {
51
- const stripeCustomer = await s.customers.create({ email: userEmail, metadata: { wab_user_id: userId } });
52
- saveStripeCustomer(userId, stripeCustomer.id);
53
- customer = { stripe_customer_id: stripeCustomer.id };
54
- }
55
-
56
- const baseUrl = process.env.BASE_URL || 'https://webagentbridge.com';
57
-
58
- const session = await s.checkout.sessions.create({
59
- customer: customer.stripe_customer_id,
60
- mode: 'subscription',
61
- payment_method_types: ['card'],
62
- line_items: [{ price: priceId, quantity: 1 }],
63
- metadata: { wab_user_id: userId, wab_site_id: siteId, tier },
64
- success_url: `${baseUrl}/dashboard?payment=success&session_id={CHECKOUT_SESSION_ID}`,
65
- cancel_url: `${baseUrl}/dashboard?payment=cancelled`
66
- });
67
-
68
- return { sessionId: session.id, url: session.url };
69
- }
70
-
71
- async function createPortalSession(userId) {
72
- const s = getStripe();
73
- if (!s) throw new Error('Stripe not configured');
74
-
75
- const customer = getStripeCustomer(userId);
76
- if (!customer) throw new Error('No Stripe customer found');
77
-
78
- const baseUrl = process.env.BASE_URL || 'https://webagentbridge.com';
79
-
80
- const session = await s.billingPortal.sessions.create({
81
- customer: customer.stripe_customer_id,
82
- return_url: `${baseUrl}/dashboard`
83
- });
84
-
85
- return { url: session.url };
86
- }
87
-
88
- function handleWebhookEvent(event) {
89
- switch (event.type) {
90
- case 'checkout.session.completed': {
91
- const session = event.data.object;
92
- const { wab_user_id, wab_site_id, tier } = session.metadata || {};
93
- if (wab_user_id && wab_site_id && session.subscription) {
94
- saveStripeSubscription({
95
- userId: wab_user_id,
96
- siteId: wab_site_id,
97
- stripeSubId: session.subscription,
98
- stripePriceId: null,
99
- tier: tier || 'starter',
100
- status: 'active',
101
- periodStart: new Date().toISOString(),
102
- periodEnd: null
103
- });
104
- updateSiteTier.run(tier || 'starter', wab_site_id, wab_user_id);
105
- }
106
- break;
107
- }
108
-
109
- case 'invoice.payment_succeeded': {
110
- const invoice = event.data.object;
111
- if (invoice.subscription) {
112
- const sub = getStripeSubscriptionBySubId(invoice.subscription);
113
- if (sub) {
114
- savePayment({
115
- userId: sub.user_id,
116
- stripePaymentId: invoice.payment_intent,
117
- amount: invoice.amount_paid,
118
- currency: invoice.currency,
119
- status: 'succeeded',
120
- description: `Subscription payment - ${sub.tier}`
121
- });
122
- updateStripeSubscription(invoice.subscription, {
123
- status: 'active',
124
- periodStart: new Date(invoice.period_start * 1000).toISOString(),
125
- periodEnd: new Date(invoice.period_end * 1000).toISOString()
126
- });
127
- }
128
- }
129
- break;
130
- }
131
-
132
- case 'customer.subscription.updated': {
133
- const subscription = event.data.object;
134
- updateStripeSubscription(subscription.id, {
135
- status: subscription.status === 'active' ? 'active' : subscription.status === 'past_due' ? 'past_due' : subscription.status === 'trialing' ? 'trialing' : 'cancelled'
136
- });
137
- break;
138
- }
139
-
140
- case 'customer.subscription.deleted': {
141
- const subscription = event.data.object;
142
- const sub = getStripeSubscriptionBySubId(subscription.id);
143
- if (sub) {
144
- updateStripeSubscription(subscription.id, { status: 'cancelled' });
145
- updateSiteTier.run('free', sub.site_id, sub.user_id);
146
- }
147
- break;
148
- }
149
-
150
- case 'invoice.payment_failed': {
151
- const invoice = event.data.object;
152
- if (invoice.subscription) {
153
- updateStripeSubscription(invoice.subscription, { status: 'past_due' });
154
- }
155
- break;
156
- }
157
- }
158
- }
159
-
160
- function isStripeConfigured() {
161
- const key = process.env.STRIPE_SECRET_KEY || getPlatformSetting('stripe_secret_key');
162
- return !!key;
163
- }
164
-
165
- /**
166
- * Express webhook handler: verifies Stripe signature, then dispatches business logic.
167
- */
168
- function handleWebhookRequest(req) {
169
- const sig = req.headers['stripe-signature'];
170
- const raw = req.body;
171
- const whSecret = process.env.STRIPE_WEBHOOK_SECRET || getPlatformSetting('stripe_webhook_secret');
172
- if (!whSecret) {
173
- throw new Error('Stripe webhook secret not configured (STRIPE_WEBHOOK_SECRET or platform stripe_webhook_secret)');
174
- }
175
- if (!sig) {
176
- throw new Error('Missing Stripe-Signature header');
177
- }
178
- const s = getStripe();
179
- if (!s) throw new Error('Stripe not configured');
180
- const event = s.webhooks.constructEvent(raw, sig, whSecret);
181
- handleWebhookEvent(event);
182
- }
183
-
184
- module.exports = {
185
- getStripe,
186
- createCheckoutSession,
187
- createPortalSession,
188
- handleWebhookEvent,
189
- handleWebhookRequest,
190
- isStripeConfigured,
191
- getStripePrices
192
- };
1
+ /**
2
+ * Stripe Payment Integration Service
3
+ */
4
+
5
+ const {
6
+ getPlatformSetting,
7
+ saveStripeCustomer,
8
+ getStripeCustomer,
9
+ saveStripeSubscription,
10
+ updateStripeSubscription,
11
+ getStripeSubscriptionBySubId,
12
+ savePayment,
13
+ updateSiteTier,
14
+ findSiteById
15
+ } = require('../models/db');
16
+
17
+ let stripe = null;
18
+
19
+ function getStripe() {
20
+ if (stripe) return stripe;
21
+ const key = process.env.STRIPE_SECRET_KEY || getPlatformSetting('stripe_secret_key');
22
+ if (!key) return null;
23
+ stripe = require('stripe')(key);
24
+ return stripe;
25
+ }
26
+
27
+ function getStripePrices() {
28
+ return {
29
+ starter: process.env.STRIPE_PRICE_STARTER || getPlatformSetting('stripe_price_starter'),
30
+ pro: process.env.STRIPE_PRICE_PRO || getPlatformSetting('stripe_price_pro'),
31
+ enterprise: process.env.STRIPE_PRICE_ENTERPRISE || getPlatformSetting('stripe_price_enterprise')
32
+ };
33
+ }
34
+
35
+ async function createCheckoutSession({ userId, userEmail, siteId, tier }) {
36
+ const site = findSiteById.get(siteId);
37
+ if (!site || site.user_id !== userId) {
38
+ throw new Error('Site not found or access denied');
39
+ }
40
+
41
+ const s = getStripe();
42
+ if (!s) throw new Error('Stripe not configured');
43
+
44
+ const prices = getStripePrices();
45
+ const priceId = prices[tier];
46
+ if (!priceId) throw new Error(`No price configured for tier: ${tier}`);
47
+
48
+ // Get or create Stripe customer
49
+ let customer = getStripeCustomer(userId);
50
+ if (!customer) {
51
+ const stripeCustomer = await s.customers.create({ email: userEmail, metadata: { wab_user_id: userId } });
52
+ saveStripeCustomer(userId, stripeCustomer.id);
53
+ customer = { stripe_customer_id: stripeCustomer.id };
54
+ }
55
+
56
+ const baseUrl = process.env.BASE_URL || 'https://webagentbridge.com';
57
+
58
+ const session = await s.checkout.sessions.create({
59
+ customer: customer.stripe_customer_id,
60
+ mode: 'subscription',
61
+ payment_method_types: ['card'],
62
+ line_items: [{ price: priceId, quantity: 1 }],
63
+ metadata: { wab_user_id: userId, wab_site_id: siteId, tier },
64
+ success_url: `${baseUrl}/dashboard?payment=success&session_id={CHECKOUT_SESSION_ID}`,
65
+ cancel_url: `${baseUrl}/dashboard?payment=cancelled`
66
+ });
67
+
68
+ return { sessionId: session.id, url: session.url };
69
+ }
70
+
71
+ async function createPortalSession(userId) {
72
+ const s = getStripe();
73
+ if (!s) throw new Error('Stripe not configured');
74
+
75
+ const customer = getStripeCustomer(userId);
76
+ if (!customer) throw new Error('No Stripe customer found');
77
+
78
+ const baseUrl = process.env.BASE_URL || 'https://webagentbridge.com';
79
+
80
+ const session = await s.billingPortal.sessions.create({
81
+ customer: customer.stripe_customer_id,
82
+ return_url: `${baseUrl}/dashboard`
83
+ });
84
+
85
+ return { url: session.url };
86
+ }
87
+
88
+ function handleWebhookEvent(event) {
89
+ switch (event.type) {
90
+ case 'checkout.session.completed': {
91
+ const session = event.data.object;
92
+ const { wab_user_id, wab_site_id, tier } = session.metadata || {};
93
+ if (wab_user_id && wab_site_id && session.subscription) {
94
+ saveStripeSubscription({
95
+ userId: wab_user_id,
96
+ siteId: wab_site_id,
97
+ stripeSubId: session.subscription,
98
+ stripePriceId: null,
99
+ tier: tier || 'starter',
100
+ status: 'active',
101
+ periodStart: new Date().toISOString(),
102
+ periodEnd: null
103
+ });
104
+ updateSiteTier.run(tier || 'starter', wab_site_id, wab_user_id);
105
+ }
106
+ break;
107
+ }
108
+
109
+ case 'invoice.payment_succeeded': {
110
+ const invoice = event.data.object;
111
+ if (invoice.subscription) {
112
+ const sub = getStripeSubscriptionBySubId(invoice.subscription);
113
+ if (sub) {
114
+ savePayment({
115
+ userId: sub.user_id,
116
+ stripePaymentId: invoice.payment_intent,
117
+ amount: invoice.amount_paid,
118
+ currency: invoice.currency,
119
+ status: 'succeeded',
120
+ description: `Subscription payment - ${sub.tier}`
121
+ });
122
+ updateStripeSubscription(invoice.subscription, {
123
+ status: 'active',
124
+ periodStart: new Date(invoice.period_start * 1000).toISOString(),
125
+ periodEnd: new Date(invoice.period_end * 1000).toISOString()
126
+ });
127
+ }
128
+ }
129
+ break;
130
+ }
131
+
132
+ case 'customer.subscription.updated': {
133
+ const subscription = event.data.object;
134
+ updateStripeSubscription(subscription.id, {
135
+ status: subscription.status === 'active' ? 'active' : subscription.status === 'past_due' ? 'past_due' : subscription.status === 'trialing' ? 'trialing' : 'cancelled'
136
+ });
137
+ break;
138
+ }
139
+
140
+ case 'customer.subscription.deleted': {
141
+ const subscription = event.data.object;
142
+ const sub = getStripeSubscriptionBySubId(subscription.id);
143
+ if (sub) {
144
+ updateStripeSubscription(subscription.id, { status: 'cancelled' });
145
+ updateSiteTier.run('free', sub.site_id, sub.user_id);
146
+ }
147
+ break;
148
+ }
149
+
150
+ case 'invoice.payment_failed': {
151
+ const invoice = event.data.object;
152
+ if (invoice.subscription) {
153
+ updateStripeSubscription(invoice.subscription, { status: 'past_due' });
154
+ }
155
+ break;
156
+ }
157
+ }
158
+ }
159
+
160
+ function isStripeConfigured() {
161
+ const key = process.env.STRIPE_SECRET_KEY || getPlatformSetting('stripe_secret_key');
162
+ return !!key;
163
+ }
164
+
165
+ /**
166
+ * Express webhook handler: verifies Stripe signature, then dispatches business logic.
167
+ */
168
+ function handleWebhookRequest(req) {
169
+ const sig = req.headers['stripe-signature'];
170
+ const raw = req.body;
171
+ const whSecret = process.env.STRIPE_WEBHOOK_SECRET || getPlatformSetting('stripe_webhook_secret');
172
+ if (!whSecret) {
173
+ throw new Error('Stripe webhook secret not configured (STRIPE_WEBHOOK_SECRET or platform stripe_webhook_secret)');
174
+ }
175
+ if (!sig) {
176
+ throw new Error('Missing Stripe-Signature header');
177
+ }
178
+ const s = getStripe();
179
+ if (!s) throw new Error('Stripe not configured');
180
+ const event = s.webhooks.constructEvent(raw, sig, whSecret);
181
+ handleWebhookEvent(event);
182
+ }
183
+
184
+ module.exports = {
185
+ getStripe,
186
+ createCheckoutSession,
187
+ createPortalSession,
188
+ handleWebhookEvent,
189
+ handleWebhookRequest,
190
+ isStripeConfigured,
191
+ getStripePrices
192
+ };