web-agent-bridge 1.2.0 → 2.1.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 (111) hide show
  1. package/LICENSE +21 -21
  2. package/README.ar.md +572 -446
  3. package/README.md +968 -933
  4. package/bin/agent-runner.js +465 -0
  5. package/bin/cli.js +138 -80
  6. package/bin/wab.js +80 -80
  7. package/examples/bidi-agent.js +119 -119
  8. package/examples/mcp-agent.js +94 -94
  9. package/examples/next-app-router/README.md +44 -0
  10. package/examples/puppeteer-agent.js +108 -108
  11. package/examples/saas-dashboard/README.md +55 -0
  12. package/examples/shopify-hydrogen/README.md +74 -0
  13. package/examples/vision-agent.js +171 -171
  14. package/examples/wordpress-elementor/README.md +77 -0
  15. package/package.json +71 -78
  16. package/public/.well-known/ai-assets.json +59 -0
  17. package/public/admin/login.html +84 -84
  18. package/public/ai.html +196 -0
  19. package/public/cookies.html +208 -208
  20. package/public/css/premium.css +317 -0
  21. package/public/css/styles.css +1235 -1235
  22. package/public/dashboard.html +704 -704
  23. package/public/demo.html +259 -0
  24. package/public/docs.html +585 -585
  25. package/public/feed.xml +89 -0
  26. package/public/index.html +581 -332
  27. package/public/js/auth-nav.js +31 -31
  28. package/public/js/auth-redirect.js +12 -12
  29. package/public/js/cookie-consent.js +56 -56
  30. package/public/js/wab-demo-page.js +721 -0
  31. package/public/js/ws-client.js +74 -74
  32. package/public/llms-full.txt +309 -0
  33. package/public/llms.txt +85 -0
  34. package/public/login.html +83 -83
  35. package/public/openapi.json +580 -0
  36. package/public/premium-dashboard.html +2487 -0
  37. package/public/premium.html +791 -0
  38. package/public/privacy.html +295 -295
  39. package/public/register.html +103 -103
  40. package/public/robots.txt +87 -0
  41. package/public/script/wab-consent.d.ts +36 -0
  42. package/public/script/wab-consent.js +104 -0
  43. package/public/script/wab-schema.js +131 -0
  44. package/public/script/wab.d.ts +108 -0
  45. package/public/script/wab.min.js +405 -0
  46. package/public/sitemap.xml +93 -0
  47. package/public/sovereign.html +660 -0
  48. package/public/terms.html +254 -254
  49. package/public/video/tutorial.mp4 +0 -0
  50. package/script/ai-agent-bridge.js +1558 -1513
  51. package/sdk/README.md +55 -55
  52. package/sdk/index.d.ts +118 -0
  53. package/sdk/index.js +257 -203
  54. package/sdk/package.json +14 -14
  55. package/sdk/schema-discovery.js +83 -0
  56. package/server/config/secrets.js +94 -92
  57. package/server/index.js +2 -9
  58. package/server/middleware/adminAuth.js +30 -30
  59. package/server/middleware/auth.js +41 -41
  60. package/server/middleware/rateLimits.js +24 -24
  61. package/server/migrations/001_add_analytics_indexes.sql +7 -7
  62. package/server/migrations/002_premium_features.sql +418 -0
  63. package/server/models/adapters/index.js +33 -33
  64. package/server/models/adapters/mysql.js +183 -183
  65. package/server/models/adapters/postgresql.js +172 -172
  66. package/server/models/adapters/sqlite.js +7 -7
  67. package/server/models/db.js +561 -561
  68. package/server/routes/admin-premium.js +671 -0
  69. package/server/routes/admin.js +247 -247
  70. package/server/routes/api.js +131 -138
  71. package/server/routes/auth.js +51 -51
  72. package/server/routes/billing.js +45 -45
  73. package/server/routes/discovery.js +406 -329
  74. package/server/routes/license.js +240 -240
  75. package/server/routes/noscript.js +543 -543
  76. package/server/routes/premium-v2.js +686 -0
  77. package/server/routes/premium.js +724 -0
  78. package/server/routes/sovereign.js +307 -0
  79. package/server/routes/wab-api.js +476 -476
  80. package/server/services/agent-memory.js +625 -0
  81. package/server/services/email.js +204 -204
  82. package/server/services/fairness.js +420 -420
  83. package/server/services/negotiation.js +439 -0
  84. package/server/services/plugins.js +747 -0
  85. package/server/services/premium.js +1883 -0
  86. package/server/services/reputation.js +465 -0
  87. package/server/services/self-healing.js +843 -0
  88. package/server/services/stripe.js +192 -192
  89. package/server/services/swarm.js +788 -0
  90. package/server/services/verification.js +481 -0
  91. package/server/services/vision.js +871 -0
  92. package/server/utils/cache.js +125 -125
  93. package/server/utils/migrate.js +81 -81
  94. package/server/utils/secureFields.js +50 -50
  95. package/server/ws.js +101 -101
  96. package/templates/artisan-marketplace.yaml +104 -0
  97. package/templates/book-price-scout.yaml +98 -0
  98. package/templates/electronics-price-tracker.yaml +108 -0
  99. package/templates/flight-deal-hunter.yaml +113 -0
  100. package/templates/freelancer-direct.yaml +116 -0
  101. package/templates/grocery-price-compare.yaml +93 -0
  102. package/templates/hotel-direct-booking.yaml +113 -0
  103. package/templates/local-services.yaml +98 -0
  104. package/templates/olive-oil-tunisia.yaml +88 -0
  105. package/templates/organic-farm-fresh.yaml +101 -0
  106. package/templates/restaurant-direct.yaml +97 -0
  107. package/docs/DEPLOY.md +0 -118
  108. package/docs/SPEC.md +0 -1540
  109. package/wab-mcp-adapter/README.md +0 -136
  110. package/wab-mcp-adapter/index.js +0 -555
  111. package/wab-mcp-adapter/package.json +0 -17
package/sdk/index.js CHANGED
@@ -1,203 +1,257 @@
1
- /**
2
- * WAB Agent SDK
3
- *
4
- * Helpers for building AI agents that interact with Web Agent Bridge.
5
- * Works with Puppeteer, Playwright, or any browser automation tool.
6
- *
7
- * Usage:
8
- * const { WABAgent } = require('./sdk');
9
- * const agent = new WABAgent(page);
10
- * await agent.waitForBridge();
11
- * const actions = await agent.getActions();
12
- * await agent.execute('signup', { email: 'test@example.com' });
13
- */
14
-
15
- class WABAgent {
16
- /**
17
- * @param {object} page — A Puppeteer or Playwright page object
18
- * @param {object} [options]
19
- * @param {number} [options.timeout=10000] — Default timeout in ms
20
- * @param {boolean} [options.useBiDi=false] — Use BiDi interface instead of AICommands
21
- */
22
- constructor(page, options = {}) {
23
- this.page = page;
24
- this.timeout = options.timeout || 10000;
25
- this.useBiDi = options.useBiDi || false;
26
- this._biDiId = 0;
27
- }
28
-
29
- /**
30
- * Wait for the WAB bridge to be ready on the page.
31
- * @returns {Promise<boolean>}
32
- */
33
- async waitForBridge() {
34
- const iface = this.useBiDi ? '__wab_bidi' : 'AICommands';
35
- await this.page.waitForFunction(
36
- (name) => typeof window[name] !== 'undefined',
37
- { timeout: this.timeout },
38
- iface
39
- );
40
- return true;
41
- }
42
-
43
- /**
44
- * Check if the bridge is loaded on the current page.
45
- * @returns {Promise<boolean>}
46
- */
47
- async hasBridge() {
48
- const iface = this.useBiDi ? '__wab_bidi' : 'AICommands';
49
- return this.page.evaluate((name) => typeof window[name] !== 'undefined', iface);
50
- }
51
-
52
- /**
53
- * Get all available actions.
54
- * @param {string} [category] — Optional category filter
55
- * @returns {Promise<Array>}
56
- */
57
- async getActions(category) {
58
- if (this.useBiDi) {
59
- const result = await this._bidiSend('wab.getActions', category ? { category } : {});
60
- return result.result || [];
61
- }
62
- return this.page.evaluate((cat) => window.AICommands.getActions(cat), category);
63
- }
64
-
65
- /**
66
- * Get a single action by name.
67
- * @param {string} name
68
- * @returns {Promise<object|null>}
69
- */
70
- async getAction(name) {
71
- return this.page.evaluate((n) => window.AICommands.getAction(n), name);
72
- }
73
-
74
- /**
75
- * Execute an action by name.
76
- * @param {string} name — Action name
77
- * @param {object} [params] — Action parameters
78
- * @returns {Promise<object>}
79
- */
80
- async execute(name, params) {
81
- if (this.useBiDi) {
82
- const result = await this._bidiSend('wab.executeAction', { name, data: params || {} });
83
- return result.result || result;
84
- }
85
- return this.page.evaluate(
86
- (n, p) => window.AICommands.execute(n, p),
87
- name, params
88
- );
89
- }
90
-
91
- /**
92
- * Read text content of an element.
93
- * @param {string} selector — CSS selector
94
- * @returns {Promise<object>}
95
- */
96
- async readContent(selector) {
97
- if (this.useBiDi) {
98
- const result = await this._bidiSend('wab.readContent', { selector });
99
- return result.result || result;
100
- }
101
- return this.page.evaluate((sel) => window.AICommands.readContent(sel), selector);
102
- }
103
-
104
- /**
105
- * Get page info and bridge metadata.
106
- * @returns {Promise<object>}
107
- */
108
- async getPageInfo() {
109
- if (this.useBiDi) {
110
- const result = await this._bidiSend('wab.getPageInfo');
111
- return result.result || result;
112
- }
113
- return this.page.evaluate(() => window.AICommands.getPageInfo());
114
- }
115
-
116
- /**
117
- * Authenticate an agent with the bridge.
118
- * @param {string} apiKey
119
- * @param {object} [meta] — Agent metadata
120
- * @returns {Promise<object>}
121
- */
122
- async authenticate(apiKey, meta) {
123
- return this.page.evaluate(
124
- (key, m) => window.AICommands.authenticate(key, m),
125
- apiKey, meta
126
- );
127
- }
128
-
129
- /**
130
- * Navigate to a URL and wait for the bridge.
131
- * @param {string} url
132
- * @returns {Promise<void>}
133
- */
134
- async navigateAndWait(url) {
135
- await this.page.goto(url, { waitUntil: 'networkidle2' });
136
- await this.waitForBridge();
137
- }
138
-
139
- /**
140
- * Execute multiple actions in sequence.
141
- * @param {Array<{name: string, params?: object}>} steps
142
- * @returns {Promise<Array>}
143
- */
144
- async executeSteps(steps) {
145
- const results = [];
146
- for (const step of steps) {
147
- results.push(await this.execute(step.name, step.params));
148
- }
149
- return results;
150
- }
151
-
152
- /**
153
- * Get the WAB discovery document for the current page.
154
- * @returns {Promise<object>}
155
- */
156
- async discover() {
157
- if (this.useBiDi) {
158
- const result = await this._bidiSend('wab.discover');
159
- return result.result || result;
160
- }
161
- return this.page.evaluate(() => window.AICommands.discover());
162
- }
163
-
164
- /**
165
- * Ping the bridge for a health check.
166
- * @returns {Promise<object>}
167
- */
168
- async ping() {
169
- if (this.useBiDi) {
170
- const result = await this._bidiSend('wab.ping');
171
- return result.result || result;
172
- }
173
- return this.page.evaluate(() => window.AICommands.ping());
174
- }
175
-
176
- /**
177
- * Get BiDi context (only available when useBiDi is true).
178
- * @returns {Promise<object>}
179
- */
180
- async getBiDiContext() {
181
- return this.page.evaluate(() => window.__wab_bidi.getContext());
182
- }
183
-
184
- /**
185
- * Get the WAB protocol interface data.
186
- * @returns {Promise<object>}
187
- */
188
- async getProtocolInfo() {
189
- return this.page.evaluate(() => window.__wab_protocol ? {
190
- version: window.__wab_protocol.version,
191
- protocol: window.__wab_protocol.protocol,
192
- discovery: window.__wab_protocol.discover()
193
- } : null);
194
- }
195
-
196
- /** @private */
197
- async _bidiSend(method, params = {}) {
198
- const cmd = { id: ++this._biDiId, method, params };
199
- return this.page.evaluate((c) => window.__wab_bidi.send(c), cmd);
200
- }
201
- }
202
-
203
- module.exports = { WABAgent };
1
+ /**
2
+ * WAB Agent SDK
3
+ *
4
+ * Helpers for building AI agents that interact with Web Agent Bridge.
5
+ * Works with Puppeteer, Playwright, or any browser automation tool.
6
+ *
7
+ * Usage:
8
+ * const { WABAgent } = require('./sdk');
9
+ * const agent = new WABAgent(page);
10
+ * await agent.waitForBridge();
11
+ * const actions = await agent.getActions();
12
+ * await agent.execute('signup', { email: 'test@example.com' });
13
+ */
14
+
15
+ class WABAgent {
16
+ /**
17
+ * @param {object} page — A Puppeteer or Playwright page object
18
+ * @param {object} [options]
19
+ * @param {number} [options.timeout=10000] — Default timeout in ms
20
+ * @param {boolean} [options.useBiDi=false] — Use BiDi interface instead of AICommands
21
+ */
22
+ constructor(page, options = {}) {
23
+ this.page = page;
24
+ this.timeout = options.timeout || 10000;
25
+ this.useBiDi = options.useBiDi || false;
26
+ this._biDiId = 0;
27
+ }
28
+
29
+ /**
30
+ * Wait for the WAB bridge to be ready on the page.
31
+ * @returns {Promise<boolean>}
32
+ */
33
+ async waitForBridge() {
34
+ const iface = this.useBiDi ? '__wab_bidi' : 'AICommands';
35
+ await this.page.waitForFunction(
36
+ (name) => typeof window[name] !== 'undefined',
37
+ { timeout: this.timeout },
38
+ iface
39
+ );
40
+ return true;
41
+ }
42
+
43
+ /**
44
+ * Check if the bridge is loaded on the current page.
45
+ * @returns {Promise<boolean>}
46
+ */
47
+ async hasBridge() {
48
+ const iface = this.useBiDi ? '__wab_bidi' : 'AICommands';
49
+ return this.page.evaluate((name) => typeof window[name] !== 'undefined', iface);
50
+ }
51
+
52
+ /**
53
+ * Get all available actions.
54
+ * @param {string} [category] — Optional category filter
55
+ * @returns {Promise<Array>}
56
+ */
57
+ async getActions(category) {
58
+ if (this.useBiDi) {
59
+ const result = await this._bidiSend('wab.getActions', category ? { category } : {});
60
+ return result.result || [];
61
+ }
62
+ return this.page.evaluate((cat) => window.AICommands.getActions(cat), category);
63
+ }
64
+
65
+ /**
66
+ * Get a single action by name.
67
+ * @param {string} name
68
+ * @returns {Promise<object|null>}
69
+ */
70
+ async getAction(name) {
71
+ return this.page.evaluate((n) => window.AICommands.getAction(n), name);
72
+ }
73
+
74
+ /**
75
+ * Execute an action by name.
76
+ * @param {string} name — Action name
77
+ * @param {object} [params] — Action parameters
78
+ * @returns {Promise<object>}
79
+ */
80
+ async execute(name, params) {
81
+ if (this.useBiDi) {
82
+ const result = await this._bidiSend('wab.executeAction', { name, data: params || {} });
83
+ return result.result || result;
84
+ }
85
+ return this.page.evaluate(
86
+ (n, p) => window.AICommands.execute(n, p),
87
+ name, params
88
+ );
89
+ }
90
+
91
+ /**
92
+ * Read text content of an element.
93
+ * @param {string} selector — CSS selector
94
+ * @returns {Promise<object>}
95
+ */
96
+ async readContent(selector) {
97
+ if (this.useBiDi) {
98
+ const result = await this._bidiSend('wab.readContent', { selector });
99
+ return result.result || result;
100
+ }
101
+ return this.page.evaluate((sel) => window.AICommands.readContent(sel), selector);
102
+ }
103
+
104
+ /**
105
+ * Get page info and bridge metadata.
106
+ * @returns {Promise<object>}
107
+ */
108
+ async getPageInfo() {
109
+ if (this.useBiDi) {
110
+ const result = await this._bidiSend('wab.getPageInfo');
111
+ return result.result || result;
112
+ }
113
+ return this.page.evaluate(() => window.AICommands.getPageInfo());
114
+ }
115
+
116
+ /**
117
+ * Authenticate an agent with the bridge.
118
+ * @param {string} apiKey
119
+ * @param {object} [meta] — Agent metadata
120
+ * @returns {Promise<object>}
121
+ */
122
+ async authenticate(apiKey, meta) {
123
+ return this.page.evaluate(
124
+ (key, m) => window.AICommands.authenticate(key, m),
125
+ apiKey, meta
126
+ );
127
+ }
128
+
129
+ /**
130
+ * Navigate to a URL and wait for the bridge.
131
+ * @param {string} url
132
+ * @returns {Promise<void>}
133
+ */
134
+ async navigateAndWait(url) {
135
+ await this.page.goto(url, { waitUntil: 'networkidle2' });
136
+ await this.waitForBridge();
137
+ }
138
+
139
+ /**
140
+ * Execute multiple actions in sequence.
141
+ * @param {Array<{name: string, params?: object}>} steps
142
+ * @returns {Promise<Array>}
143
+ */
144
+ async executeSteps(steps) {
145
+ const results = [];
146
+ for (const step of steps) {
147
+ results.push(await this.execute(step.name, step.params));
148
+ }
149
+ return results;
150
+ }
151
+
152
+ /**
153
+ * Get BiDi context (only available when useBiDi is true).
154
+ * @returns {Promise<object>}
155
+ */
156
+ async getBiDiContext() {
157
+ return this.page.evaluate(() => window.__wab_bidi.getContext());
158
+ }
159
+
160
+ /**
161
+ * Check if the page has granted consent for agent interactions.
162
+ * @returns {Promise<boolean>}
163
+ */
164
+ async hasConsent() {
165
+ return this.page.evaluate(() => {
166
+ if (typeof window.WABConsent !== 'undefined') return window.WABConsent.hasConsent();
167
+ // If no consent script, treat as allowed
168
+ return true;
169
+ });
170
+ }
171
+
172
+ /**
173
+ * Wait until consent is granted (blocks until user clicks Allow).
174
+ * @param {number} [pollMs=500]
175
+ * @returns {Promise<boolean>}
176
+ */
177
+ async waitForConsent(pollMs = 500) {
178
+ return this.page.waitForFunction(
179
+ () => {
180
+ if (typeof window.WABConsent === 'undefined') return true;
181
+ return window.WABConsent.hasConsent();
182
+ },
183
+ { timeout: this.timeout, polling: pollMs }
184
+ ).then(() => true);
185
+ }
186
+
187
+ /**
188
+ * Discover the page and return the list of actions.
189
+ * Combines bridge discovery with runtime getActions().
190
+ * @returns {Promise<object>}
191
+ */
192
+ async discover() {
193
+ return this.page.evaluate(() => {
194
+ if (window.WAB && typeof window.WAB.discover === 'function') return window.WAB.discover();
195
+ if (window.AICommands && typeof window.AICommands.getActions === 'function') {
196
+ return { actions: window.AICommands.getActions(), meta: window.AICommands.getPageInfo ? window.AICommands.getPageInfo() : {} };
197
+ }
198
+ return { actions: [] };
199
+ });
200
+ }
201
+
202
+ /**
203
+ * Run a sequence of actions, stopping on the first failure.
204
+ * @param {Array<{name: string, params?: object}>} steps
205
+ * @param {{ stopOnError?: boolean }} [options]
206
+ * @returns {Promise<Array<{ name: string, ok: boolean, result?: any, error?: string }>>}
207
+ */
208
+ async runPipeline(steps, options = {}) {
209
+ const stopOnError = options.stopOnError !== false;
210
+ const results = [];
211
+ for (const step of steps) {
212
+ try {
213
+ const res = await this.execute(step.name, step.params);
214
+ results.push({ name: step.name, ok: true, result: res });
215
+ } catch (err) {
216
+ results.push({ name: step.name, ok: false, error: err.message || String(err) });
217
+ if (stopOnError) break;
218
+ }
219
+ }
220
+ return results;
221
+ }
222
+
223
+ /**
224
+ * Execute multiple actions in parallel.
225
+ * @param {Array<{name: string, params?: object}>} actions
226
+ * @returns {Promise<Array<{ name: string, status: string, value?: any, reason?: string }>>}
227
+ */
228
+ async executeParallel(actions) {
229
+ const promises = actions.map((a) =>
230
+ this.execute(a.name, a.params)
231
+ .then((value) => ({ name: a.name, status: 'fulfilled', value }))
232
+ .catch((err) => ({ name: a.name, status: 'rejected', reason: err.message || String(err) }))
233
+ );
234
+ return Promise.all(promises);
235
+ }
236
+
237
+ /**
238
+ * Take a screenshot and return as base64 (useful for vision agents).
239
+ * @param {{ fullPage?: boolean }} [opts]
240
+ * @returns {Promise<string>}
241
+ */
242
+ async screenshot(opts = {}) {
243
+ const buf = await this.page.screenshot({
244
+ encoding: 'base64',
245
+ fullPage: opts.fullPage || false
246
+ });
247
+ return buf;
248
+ }
249
+
250
+ /** @private */
251
+ async _bidiSend(method, params = {}) {
252
+ const cmd = { id: ++this._biDiId, method, params };
253
+ return this.page.evaluate((c) => window.__wab_bidi.send(c), cmd);
254
+ }
255
+ }
256
+
257
+ module.exports = { WABAgent };
package/sdk/package.json CHANGED
@@ -1,14 +1,14 @@
1
- {
2
- "name": "@anthropic-wab/agent-sdk",
3
- "version": "1.0.0",
4
- "description": "SDK for building AI agents that interact with Web Agent Bridge (WAB)",
5
- "main": "index.js",
6
- "license": "MIT",
7
- "keywords": ["wab", "ai-agent", "sdk", "web-automation", "bridge"],
8
- "peerDependencies": {
9
- "puppeteer": ">=20.0.0"
10
- },
11
- "peerDependenciesMeta": {
12
- "puppeteer": { "optional": true }
13
- }
14
- }
1
+ {
2
+ "name": "web-agent-bridge-sdk",
3
+ "version": "2.0.0",
4
+ "description": "SDK for building AI agents that interact with Web Agent Bridge (WAB)",
5
+ "main": "index.js",
6
+ "license": "MIT",
7
+ "keywords": ["wab", "ai-agent", "sdk", "web-automation", "bridge"],
8
+ "peerDependencies": {
9
+ "puppeteer": ">=20.0.0"
10
+ },
11
+ "peerDependenciesMeta": {
12
+ "puppeteer": { "optional": true }
13
+ }
14
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Server-side / Node: extract schema.org Product nodes from HTML (JSON-LD blocks).
3
+ * No extra dependencies — regex-based script extraction (same semantics as browser WABSchema).
4
+ *
5
+ * @example
6
+ * const { extractProductsFromHtml, suggestWabActionsFromProducts } = require('./schema-discovery');
7
+ * const products = extractProductsFromHtml(htmlString);
8
+ * const hints = suggestWabActionsFromProducts(products);
9
+ */
10
+
11
+ function extractJsonLdBlocks(html) {
12
+ if (!html || typeof html !== 'string') return [];
13
+ const re = /<script[^>]*type=["']application\/ld\+json["'][^>]*>([\s\S]*?)<\/script>/gi;
14
+ const blocks = [];
15
+ let m;
16
+ while ((m = re.exec(html)) !== null) {
17
+ blocks.push(m[1].trim());
18
+ }
19
+ return blocks;
20
+ }
21
+
22
+ function flattenGraph(data) {
23
+ if (Array.isArray(data)) return data;
24
+ if (data && Array.isArray(data['@graph'])) return data['@graph'];
25
+ return [data];
26
+ }
27
+
28
+ /**
29
+ * @param {string} html
30
+ * @returns {Array<{ type: string, name?: string, sku?: string, offers?: unknown }>}
31
+ */
32
+ function extractProductsFromHtml(html) {
33
+ const out = [];
34
+ const blocks = extractJsonLdBlocks(html);
35
+ for (const text of blocks) {
36
+ let data;
37
+ try {
38
+ data = JSON.parse(text);
39
+ } catch {
40
+ continue;
41
+ }
42
+ const items = flattenGraph(data);
43
+ for (const node of items) {
44
+ if (!node || typeof node !== 'object') continue;
45
+ let types = node['@type'];
46
+ if (typeof types === 'string') types = [types];
47
+ if (!Array.isArray(types)) types = [];
48
+ if (!types.includes('Product')) continue;
49
+ out.push({
50
+ type: 'Product',
51
+ name: node.name,
52
+ sku: node.sku,
53
+ offers: node.offers
54
+ });
55
+ }
56
+ }
57
+ return out;
58
+ }
59
+
60
+ function suggestWabActionsFromProducts(products) {
61
+ const actions = [];
62
+ if (products.length) {
63
+ actions.push({
64
+ name: 'getProductFromSchema',
65
+ description: 'Structured products from schema.org JSON-LD',
66
+ source: 'schema.org'
67
+ });
68
+ }
69
+ if (products.some((p) => p.offers)) {
70
+ actions.push({
71
+ name: 'getOfferPrice',
72
+ description: 'Prices from schema.org Offer',
73
+ source: 'schema.org'
74
+ });
75
+ }
76
+ return actions;
77
+ }
78
+
79
+ module.exports = {
80
+ extractJsonLdBlocks,
81
+ extractProductsFromHtml,
82
+ suggestWabActionsFromProducts
83
+ };