@memberjunction/core-actions 2.50.0 → 2.51.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/dist/custom/{send-single-message.action.d.ts → communication/send-single-message.action.d.ts} +1 -0
- package/dist/custom/communication/send-single-message.action.d.ts.map +1 -0
- package/dist/custom/{send-single-message.action.js → communication/send-single-message.action.js} +8 -7
- package/dist/custom/communication/send-single-message.action.js.map +1 -0
- package/dist/custom/demo/calculate-expression.action.d.ts.map +1 -0
- package/dist/custom/{calculate-expression.action.js → demo/calculate-expression.action.js} +1 -1
- package/dist/custom/demo/calculate-expression.action.js.map +1 -0
- package/dist/custom/demo/color-converter.action.d.ts.map +1 -0
- package/dist/custom/{color-converter.action.js → demo/color-converter.action.js} +1 -1
- package/dist/custom/demo/color-converter.action.js.map +1 -0
- package/dist/custom/demo/get-stock-price.action.d.ts.map +1 -0
- package/dist/custom/{get-stock-price.action.js → demo/get-stock-price.action.js} +1 -1
- package/dist/custom/demo/get-stock-price.action.js.map +1 -0
- package/dist/custom/{get-weather.action.d.ts → demo/get-weather.action.d.ts} +9 -0
- package/dist/custom/demo/get-weather.action.d.ts.map +1 -0
- package/dist/custom/{get-weather.action.js → demo/get-weather.action.js} +104 -14
- package/dist/custom/demo/get-weather.action.js.map +1 -0
- package/dist/custom/demo/text-analyzer.action.d.ts.map +1 -0
- package/dist/custom/{text-analyzer.action.js → demo/text-analyzer.action.js} +2 -2
- package/dist/custom/demo/text-analyzer.action.js.map +1 -0
- package/dist/custom/demo/unit-converter.action.d.ts.map +1 -0
- package/dist/custom/{unit-converter.action.js → demo/unit-converter.action.js} +3 -3
- package/dist/custom/demo/unit-converter.action.js.map +1 -0
- package/dist/custom/utilities/business-days-calculator.action.d.ts.map +1 -0
- package/dist/custom/{business-days-calculator.action.js → utilities/business-days-calculator.action.js} +6 -6
- package/dist/custom/utilities/business-days-calculator.action.js.map +1 -0
- package/dist/custom/utilities/census-data-lookup.action.d.ts.map +1 -0
- package/dist/custom/{census-data-lookup.action.js → utilities/census-data-lookup.action.js} +4 -4
- package/dist/custom/utilities/census-data-lookup.action.js.map +1 -0
- package/dist/custom/{external-change-detection.action.d.ts → utilities/external-change-detection.action.d.ts} +1 -0
- package/dist/custom/utilities/external-change-detection.action.d.ts.map +1 -0
- package/dist/custom/{external-change-detection.action.js → utilities/external-change-detection.action.js} +3 -2
- package/dist/custom/utilities/external-change-detection.action.js.map +1 -0
- package/dist/custom/utilities/ip-geolocation.action.d.ts.map +1 -0
- package/dist/custom/{ip-geolocation.action.js → utilities/ip-geolocation.action.js} +1 -1
- package/dist/custom/utilities/ip-geolocation.action.js.map +1 -0
- package/dist/custom/utilities/qr-code.action.d.ts +89 -0
- package/dist/custom/utilities/qr-code.action.d.ts.map +1 -0
- package/dist/custom/utilities/qr-code.action.js +300 -0
- package/dist/custom/utilities/qr-code.action.js.map +1 -0
- package/dist/custom/utilities/vectorize-entity.action.d.ts.map +1 -0
- package/dist/custom/{vectorize-entity.action.js → utilities/vectorize-entity.action.js} +1 -1
- package/dist/custom/utilities/vectorize-entity.action.js.map +1 -0
- package/dist/custom/web/url-link-validator.action.d.ts +74 -0
- package/dist/custom/web/url-link-validator.action.d.ts.map +1 -0
- package/dist/custom/web/url-link-validator.action.js +286 -0
- package/dist/custom/web/url-link-validator.action.js.map +1 -0
- package/dist/custom/web/url-metadata-extractor.action.d.ts +104 -0
- package/dist/custom/web/url-metadata-extractor.action.d.ts.map +1 -0
- package/dist/custom/web/url-metadata-extractor.action.js +438 -0
- package/dist/custom/web/url-metadata-extractor.action.js.map +1 -0
- package/dist/custom/web/web-page-content.action.d.ts +90 -0
- package/dist/custom/web/web-page-content.action.d.ts.map +1 -0
- package/dist/custom/web/web-page-content.action.js +416 -0
- package/dist/custom/web/web-page-content.action.js.map +1 -0
- package/dist/custom/web/web-search.action.d.ts +69 -0
- package/dist/custom/web/web-search.action.d.ts.map +1 -0
- package/dist/custom/web/web-search.action.js +382 -0
- package/dist/custom/web/web-search.action.js.map +1 -0
- package/dist/index.d.ts +17 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +58 -11
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/dist/custom/business-days-calculator.action.d.ts.map +0 -1
- package/dist/custom/business-days-calculator.action.js.map +0 -1
- package/dist/custom/calculate-expression.action.d.ts.map +0 -1
- package/dist/custom/calculate-expression.action.js.map +0 -1
- package/dist/custom/census-data-lookup.action.d.ts.map +0 -1
- package/dist/custom/census-data-lookup.action.js.map +0 -1
- package/dist/custom/color-converter.action.d.ts.map +0 -1
- package/dist/custom/color-converter.action.js.map +0 -1
- package/dist/custom/external-change-detection.action.d.ts.map +0 -1
- package/dist/custom/external-change-detection.action.js.map +0 -1
- package/dist/custom/get-stock-price.action.d.ts.map +0 -1
- package/dist/custom/get-stock-price.action.js.map +0 -1
- package/dist/custom/get-weather.action.d.ts.map +0 -1
- package/dist/custom/get-weather.action.js.map +0 -1
- package/dist/custom/ip-geolocation.action.d.ts.map +0 -1
- package/dist/custom/ip-geolocation.action.js.map +0 -1
- package/dist/custom/send-single-message.action.d.ts.map +0 -1
- package/dist/custom/send-single-message.action.js.map +0 -1
- package/dist/custom/text-analyzer.action.d.ts.map +0 -1
- package/dist/custom/text-analyzer.action.js.map +0 -1
- package/dist/custom/unit-converter.action.d.ts.map +0 -1
- package/dist/custom/unit-converter.action.js.map +0 -1
- package/dist/custom/vectorize-entity.action.d.ts.map +0 -1
- package/dist/custom/vectorize-entity.action.js.map +0 -1
- /package/dist/custom/{calculate-expression.action.d.ts → demo/calculate-expression.action.d.ts} +0 -0
- /package/dist/custom/{color-converter.action.d.ts → demo/color-converter.action.d.ts} +0 -0
- /package/dist/custom/{get-stock-price.action.d.ts → demo/get-stock-price.action.d.ts} +0 -0
- /package/dist/custom/{text-analyzer.action.d.ts → demo/text-analyzer.action.d.ts} +0 -0
- /package/dist/custom/{unit-converter.action.d.ts → demo/unit-converter.action.d.ts} +0 -0
- /package/dist/custom/{business-days-calculator.action.d.ts → utilities/business-days-calculator.action.d.ts} +0 -0
- /package/dist/custom/{census-data-lookup.action.d.ts → utilities/census-data-lookup.action.d.ts} +0 -0
- /package/dist/custom/{ip-geolocation.action.d.ts → utilities/ip-geolocation.action.d.ts} +0 -0
- /package/dist/custom/{vectorize-entity.action.d.ts → utilities/vectorize-entity.action.d.ts} +0 -0
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.LoadWebPageContentAction = exports.WebPageContentAction = void 0;
|
|
10
|
+
const actions_1 = require("@memberjunction/actions");
|
|
11
|
+
const global_1 = require("@memberjunction/global");
|
|
12
|
+
/**
|
|
13
|
+
* Action that retrieves and processes web page content with various output formats
|
|
14
|
+
* Supports text extraction, HTML parsing, and basic document conversion
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // Get page content as text
|
|
19
|
+
* await runAction({
|
|
20
|
+
* ActionName: 'Web Page Content',
|
|
21
|
+
* Params: [{
|
|
22
|
+
* Name: 'URL',
|
|
23
|
+
* Value: 'https://example.com'
|
|
24
|
+
* }, {
|
|
25
|
+
* Name: 'ContentType',
|
|
26
|
+
* Value: 'text'
|
|
27
|
+
* }]
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Get main content only (removes navigation, ads, etc.)
|
|
31
|
+
* await runAction({
|
|
32
|
+
* ActionName: 'Web Page Content',
|
|
33
|
+
* Params: [{
|
|
34
|
+
* Name: 'URL',
|
|
35
|
+
* Value: 'https://news.example.com/article'
|
|
36
|
+
* }, {
|
|
37
|
+
* Name: 'ContentType',
|
|
38
|
+
* Value: 'markdown'
|
|
39
|
+
* }, {
|
|
40
|
+
* Name: 'ExtractMainContent',
|
|
41
|
+
* Value: true
|
|
42
|
+
* }]
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
let WebPageContentAction = class WebPageContentAction extends actions_1.BaseAction {
|
|
47
|
+
MAX_CONTENT_SIZE = 5 * 1024 * 1024; // 5MB limit
|
|
48
|
+
MAX_IMAGE_SIZE = 2 * 1024 * 1024; // 2MB limit for images
|
|
49
|
+
/**
|
|
50
|
+
* Executes the web page content retrieval and processing
|
|
51
|
+
*
|
|
52
|
+
* @param params - The action parameters containing:
|
|
53
|
+
* - URL: Web page URL to fetch (required)
|
|
54
|
+
* - ContentType: Output format - 'text', 'html', 'markdown', 'json' (default: 'text')
|
|
55
|
+
* - ExtractMainContent: Extract only main content vs full page (default: false)
|
|
56
|
+
* - IncludeMetadata: Include page metadata in response (default: true)
|
|
57
|
+
* - MaxContentLength: Maximum content length to return (default: 50000 chars)
|
|
58
|
+
*
|
|
59
|
+
* @returns Processed web page content in the specified format
|
|
60
|
+
*/
|
|
61
|
+
async InternalRunAction(params) {
|
|
62
|
+
try {
|
|
63
|
+
const urlParam = params.Params.find(p => p.Name.trim().toLowerCase() === 'url');
|
|
64
|
+
const contentTypeParam = params.Params.find(p => p.Name.trim().toLowerCase() === 'contenttype');
|
|
65
|
+
const extractMainParam = params.Params.find(p => p.Name.trim().toLowerCase() === 'extractmaincontent');
|
|
66
|
+
const includeMetadataParam = params.Params.find(p => p.Name.trim().toLowerCase() === 'includemetadata');
|
|
67
|
+
const maxLengthParam = params.Params.find(p => p.Name.trim().toLowerCase() === 'maxcontentlength');
|
|
68
|
+
if (!urlParam || !urlParam.Value) {
|
|
69
|
+
return {
|
|
70
|
+
Success: false,
|
|
71
|
+
Message: "URL parameter is required",
|
|
72
|
+
ResultCode: "MISSING_PARAMETERS"
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const url = urlParam.Value.toString().trim();
|
|
76
|
+
const contentType = contentTypeParam?.Value?.toString().toLowerCase() || 'text';
|
|
77
|
+
const extractMain = extractMainParam?.Value === true || extractMainParam?.Value === 'true';
|
|
78
|
+
const includeMetadata = includeMetadataParam?.Value !== false && includeMetadataParam?.Value !== 'false';
|
|
79
|
+
const maxLength = parseInt(maxLengthParam?.Value?.toString() || '50000');
|
|
80
|
+
// Validate URL
|
|
81
|
+
let parsedUrl;
|
|
82
|
+
try {
|
|
83
|
+
parsedUrl = new URL(url);
|
|
84
|
+
if (!['http:', 'https:'].includes(parsedUrl.protocol)) {
|
|
85
|
+
throw new Error('Only HTTP and HTTPS URLs are supported');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
return {
|
|
90
|
+
Success: false,
|
|
91
|
+
Message: "Invalid URL format",
|
|
92
|
+
ResultCode: "INVALID_URL"
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
// Validate content type
|
|
96
|
+
if (!['text', 'html', 'markdown', 'json'].includes(contentType)) {
|
|
97
|
+
return {
|
|
98
|
+
Success: false,
|
|
99
|
+
Message: "ContentType must be one of: text, html, markdown, json",
|
|
100
|
+
ResultCode: "INVALID_CONTENT_TYPE"
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
// Fetch the web page
|
|
104
|
+
const response = await fetch(url, {
|
|
105
|
+
headers: {
|
|
106
|
+
'User-Agent': 'Mozilla/5.0 (compatible; MemberJunction/1.0; +https://memberjunction.org)',
|
|
107
|
+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
|
108
|
+
'Accept-Language': 'en-US,en;q=0.5',
|
|
109
|
+
'Accept-Encoding': 'gzip, deflate'
|
|
110
|
+
},
|
|
111
|
+
redirect: 'follow'
|
|
112
|
+
});
|
|
113
|
+
if (!response.ok) {
|
|
114
|
+
return {
|
|
115
|
+
Success: false,
|
|
116
|
+
Message: `Failed to fetch URL: ${response.status} ${response.statusText}`,
|
|
117
|
+
ResultCode: "FETCH_FAILED"
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
// Check content type and size
|
|
121
|
+
const responseContentType = response.headers.get('content-type') || '';
|
|
122
|
+
const contentLength = parseInt(response.headers.get('content-length') || '0');
|
|
123
|
+
if (contentLength > this.MAX_CONTENT_SIZE) {
|
|
124
|
+
return {
|
|
125
|
+
Success: false,
|
|
126
|
+
Message: `Content too large: ${contentLength} bytes (max: ${this.MAX_CONTENT_SIZE})`,
|
|
127
|
+
ResultCode: "CONTENT_TOO_LARGE"
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
// Handle different content types
|
|
131
|
+
if (responseContentType.startsWith('image/')) {
|
|
132
|
+
if (contentLength > this.MAX_IMAGE_SIZE) {
|
|
133
|
+
return {
|
|
134
|
+
Success: false,
|
|
135
|
+
Message: `Image too large: ${contentLength} bytes (max: ${this.MAX_IMAGE_SIZE})`,
|
|
136
|
+
ResultCode: "IMAGE_TOO_LARGE"
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
// For images, return base64 encoded data
|
|
140
|
+
const buffer = await response.arrayBuffer();
|
|
141
|
+
const base64 = Buffer.from(buffer).toString('base64');
|
|
142
|
+
const result = {
|
|
143
|
+
url,
|
|
144
|
+
contentType: responseContentType,
|
|
145
|
+
contentLength,
|
|
146
|
+
isImage: true,
|
|
147
|
+
base64Data: base64,
|
|
148
|
+
dataUrl: `data:${responseContentType};base64,${base64}`
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
Success: true,
|
|
152
|
+
ResultCode: "SUCCESS",
|
|
153
|
+
Message: JSON.stringify(result, null, 2)
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
// Handle text-based content
|
|
157
|
+
if (!responseContentType.includes('text/html') && !responseContentType.includes('application/xhtml') && !responseContentType.includes('text/')) {
|
|
158
|
+
return {
|
|
159
|
+
Success: false,
|
|
160
|
+
Message: `Unsupported content type: ${responseContentType}`,
|
|
161
|
+
ResultCode: "UNSUPPORTED_CONTENT_TYPE"
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const html = await response.text();
|
|
165
|
+
if (html.length > this.MAX_CONTENT_SIZE) {
|
|
166
|
+
return {
|
|
167
|
+
Success: false,
|
|
168
|
+
Message: `Content too large: ${html.length} characters (max: ${this.MAX_CONTENT_SIZE})`,
|
|
169
|
+
ResultCode: "CONTENT_TOO_LARGE"
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
// Process the content based on requested format
|
|
173
|
+
const processedContent = await this.processContent(html, contentType, extractMain, includeMetadata, maxLength);
|
|
174
|
+
processedContent.url = url;
|
|
175
|
+
processedContent.fetchedAt = new Date().toISOString();
|
|
176
|
+
return {
|
|
177
|
+
Success: true,
|
|
178
|
+
ResultCode: "SUCCESS",
|
|
179
|
+
Message: JSON.stringify(processedContent, null, 2)
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
return {
|
|
184
|
+
Success: false,
|
|
185
|
+
Message: `Failed to retrieve web page content: ${error instanceof Error ? error.message : String(error)}`,
|
|
186
|
+
ResultCode: "FAILED"
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Processes HTML content into the requested format
|
|
192
|
+
*/
|
|
193
|
+
async processContent(html, contentType, extractMain, includeMetadata, maxLength) {
|
|
194
|
+
const result = {
|
|
195
|
+
contentType,
|
|
196
|
+
extractMainContent: extractMain,
|
|
197
|
+
includeMetadata
|
|
198
|
+
};
|
|
199
|
+
// Extract metadata if requested
|
|
200
|
+
if (includeMetadata) {
|
|
201
|
+
result.metadata = this.extractMetadata(html);
|
|
202
|
+
}
|
|
203
|
+
// Extract main content or use full HTML
|
|
204
|
+
let contentHtml = html;
|
|
205
|
+
if (extractMain) {
|
|
206
|
+
contentHtml = this.extractMainContent(html);
|
|
207
|
+
}
|
|
208
|
+
// Convert based on content type
|
|
209
|
+
switch (contentType) {
|
|
210
|
+
case 'html':
|
|
211
|
+
result.content = this.truncateContent(contentHtml, maxLength);
|
|
212
|
+
break;
|
|
213
|
+
case 'text':
|
|
214
|
+
result.content = this.truncateContent(this.htmlToText(contentHtml), maxLength);
|
|
215
|
+
break;
|
|
216
|
+
case 'markdown':
|
|
217
|
+
result.content = this.truncateContent(this.htmlToMarkdown(contentHtml), maxLength);
|
|
218
|
+
break;
|
|
219
|
+
case 'json':
|
|
220
|
+
result.content = {
|
|
221
|
+
html: this.truncateContent(contentHtml, maxLength),
|
|
222
|
+
text: this.truncateContent(this.htmlToText(contentHtml), maxLength),
|
|
223
|
+
structure: this.extractStructure(contentHtml)
|
|
224
|
+
};
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
result.contentLength = typeof result.content === 'string' ? result.content.length : JSON.stringify(result.content).length;
|
|
228
|
+
return result;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Extracts page metadata from HTML
|
|
232
|
+
*/
|
|
233
|
+
extractMetadata(html) {
|
|
234
|
+
const metadata = {};
|
|
235
|
+
// Title
|
|
236
|
+
const titleMatch = html.match(/<title[^>]*>(.*?)<\/title>/is);
|
|
237
|
+
if (titleMatch) {
|
|
238
|
+
metadata.title = this.stripHtml(titleMatch[1]).trim();
|
|
239
|
+
}
|
|
240
|
+
// Meta tags
|
|
241
|
+
const metaRegex = /<meta[^>]+>/gi;
|
|
242
|
+
const metas = html.match(metaRegex) || [];
|
|
243
|
+
for (const meta of metas) {
|
|
244
|
+
const nameMatch = meta.match(/name=['"]([^'"]+)['"]/i);
|
|
245
|
+
const propertyMatch = meta.match(/property=['"]([^'"]+)['"]/i);
|
|
246
|
+
const contentMatch = meta.match(/content=['"]([^'"]*)['"]/i);
|
|
247
|
+
if (contentMatch) {
|
|
248
|
+
const content = contentMatch[1];
|
|
249
|
+
if (nameMatch) {
|
|
250
|
+
metadata[nameMatch[1]] = content;
|
|
251
|
+
}
|
|
252
|
+
else if (propertyMatch) {
|
|
253
|
+
metadata[propertyMatch[1]] = content;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
// Canonical URL
|
|
258
|
+
const canonicalMatch = html.match(/<link[^>]+rel=['"]canonical['"][^>]+href=['"]([^'"]+)['"]/i);
|
|
259
|
+
if (canonicalMatch) {
|
|
260
|
+
metadata.canonical = canonicalMatch[1];
|
|
261
|
+
}
|
|
262
|
+
return metadata;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Attempts to extract main content from HTML (removes navigation, ads, etc.)
|
|
266
|
+
*/
|
|
267
|
+
extractMainContent(html) {
|
|
268
|
+
// Remove scripts and styles
|
|
269
|
+
let content = html.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');
|
|
270
|
+
content = content.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '');
|
|
271
|
+
// Try to find main content containers
|
|
272
|
+
const mainSelectors = [
|
|
273
|
+
/<main[^>]*>([\s\S]*?)<\/main>/i,
|
|
274
|
+
/<article[^>]*>([\s\S]*?)<\/article>/i,
|
|
275
|
+
/<div[^>]*class=['"][^'"]*content[^'"]*['"][^>]*>([\s\S]*?)<\/div>/i,
|
|
276
|
+
/<div[^>]*id=['"][^'"]*content[^'"]*['"][^>]*>([\s\S]*?)<\/div>/i,
|
|
277
|
+
/<div[^>]*class=['"][^'"]*post[^'"]*['"][^>]*>([\s\S]*?)<\/div>/i
|
|
278
|
+
];
|
|
279
|
+
for (const selector of mainSelectors) {
|
|
280
|
+
const match = content.match(selector);
|
|
281
|
+
if (match && match[1].trim().length > 100) {
|
|
282
|
+
return match[1];
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
// If no main content found, remove common non-content elements
|
|
286
|
+
content = content.replace(/<nav[^>]*>[\s\S]*?<\/nav>/gi, '');
|
|
287
|
+
content = content.replace(/<header[^>]*>[\s\S]*?<\/header>/gi, '');
|
|
288
|
+
content = content.replace(/<footer[^>]*>[\s\S]*?<\/footer>/gi, '');
|
|
289
|
+
content = content.replace(/<aside[^>]*>[\s\S]*?<\/aside>/gi, '');
|
|
290
|
+
content = content.replace(/<div[^>]*class=['"][^'"]*nav[^'"]*['"][^>]*>[\s\S]*?<\/div>/gi, '');
|
|
291
|
+
return content;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Converts HTML to plain text
|
|
295
|
+
*/
|
|
296
|
+
htmlToText(html) {
|
|
297
|
+
return html
|
|
298
|
+
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
|
|
299
|
+
.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
|
|
300
|
+
.replace(/<br\s*\/?>/gi, '\n')
|
|
301
|
+
.replace(/<\/p>/gi, '\n\n')
|
|
302
|
+
.replace(/<\/h[1-6]>/gi, '\n\n')
|
|
303
|
+
.replace(/<\/div>/gi, '\n')
|
|
304
|
+
.replace(/<\/li>/gi, '\n')
|
|
305
|
+
.replace(/<[^>]*>/g, '')
|
|
306
|
+
.replace(/&/g, '&')
|
|
307
|
+
.replace(/</g, '<')
|
|
308
|
+
.replace(/>/g, '>')
|
|
309
|
+
.replace(/"/g, '"')
|
|
310
|
+
.replace(/'/g, "'")
|
|
311
|
+
.replace(/ /g, ' ')
|
|
312
|
+
.replace(/\s+/g, ' ')
|
|
313
|
+
.replace(/\n\s+/g, '\n')
|
|
314
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
315
|
+
.trim();
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Converts HTML to basic Markdown
|
|
319
|
+
*/
|
|
320
|
+
htmlToMarkdown(html) {
|
|
321
|
+
return html
|
|
322
|
+
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
|
|
323
|
+
.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
|
|
324
|
+
.replace(/<h1[^>]*>(.*?)<\/h1>/gi, '# $1\n\n')
|
|
325
|
+
.replace(/<h2[^>]*>(.*?)<\/h2>/gi, '## $1\n\n')
|
|
326
|
+
.replace(/<h3[^>]*>(.*?)<\/h3>/gi, '### $1\n\n')
|
|
327
|
+
.replace(/<h4[^>]*>(.*?)<\/h4>/gi, '#### $1\n\n')
|
|
328
|
+
.replace(/<h5[^>]*>(.*?)<\/h5>/gi, '##### $1\n\n')
|
|
329
|
+
.replace(/<h6[^>]*>(.*?)<\/h6>/gi, '###### $1\n\n')
|
|
330
|
+
.replace(/<strong[^>]*>(.*?)<\/strong>/gi, '**$1**')
|
|
331
|
+
.replace(/<b[^>]*>(.*?)<\/b>/gi, '**$1**')
|
|
332
|
+
.replace(/<em[^>]*>(.*?)<\/em>/gi, '*$1*')
|
|
333
|
+
.replace(/<i[^>]*>(.*?)<\/i>/gi, '*$1*')
|
|
334
|
+
.replace(/<a[^>]+href=['"]([^'"]+)['"][^>]*>(.*?)<\/a>/gi, '[$2]($1)')
|
|
335
|
+
.replace(/<img[^>]+src=['"]([^'"]+)['"][^>]*alt=['"]([^'"]*)['"]/gi, '')
|
|
336
|
+
.replace(/<img[^>]+src=['"]([^'"]+)['"][^>]*/gi, '')
|
|
337
|
+
.replace(/<br\s*\/?>/gi, '\n')
|
|
338
|
+
.replace(/<\/p>/gi, '\n\n')
|
|
339
|
+
.replace(/<\/div>/gi, '\n')
|
|
340
|
+
.replace(/<li[^>]*>(.*?)<\/li>/gi, '- $1\n')
|
|
341
|
+
.replace(/<[^>]*>/g, '')
|
|
342
|
+
.replace(/&/g, '&')
|
|
343
|
+
.replace(/</g, '<')
|
|
344
|
+
.replace(/>/g, '>')
|
|
345
|
+
.replace(/"/g, '"')
|
|
346
|
+
.replace(/'/g, "'")
|
|
347
|
+
.replace(/ /g, ' ')
|
|
348
|
+
.replace(/\s+/g, ' ')
|
|
349
|
+
.replace(/\n\s+/g, '\n')
|
|
350
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
351
|
+
.trim();
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Extracts basic document structure
|
|
355
|
+
*/
|
|
356
|
+
extractStructure(html) {
|
|
357
|
+
const structure = {
|
|
358
|
+
headings: [],
|
|
359
|
+
links: [],
|
|
360
|
+
images: []
|
|
361
|
+
};
|
|
362
|
+
// Extract headings
|
|
363
|
+
const headingRegex = /<h([1-6])[^>]*>(.*?)<\/h[1-6]>/gi;
|
|
364
|
+
let match;
|
|
365
|
+
while ((match = headingRegex.exec(html)) !== null) {
|
|
366
|
+
structure.headings.push({
|
|
367
|
+
level: parseInt(match[1]),
|
|
368
|
+
text: this.stripHtml(match[2]).trim()
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
// Extract links
|
|
372
|
+
const linkRegex = /<a[^>]+href=['"]([^'"]+)['"][^>]*>(.*?)<\/a>/gi;
|
|
373
|
+
while ((match = linkRegex.exec(html)) !== null) {
|
|
374
|
+
structure.links.push({
|
|
375
|
+
url: match[1],
|
|
376
|
+
text: this.stripHtml(match[2]).trim()
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
// Extract images
|
|
380
|
+
const imgRegex = /<img[^>]+src=['"]([^'"]+)['"][^>]*(?:alt=['"]([^'"]*)['"]*)?/gi;
|
|
381
|
+
while ((match = imgRegex.exec(html)) !== null) {
|
|
382
|
+
structure.images.push({
|
|
383
|
+
src: match[1],
|
|
384
|
+
alt: match[2] || ''
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
return structure;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Strips HTML tags from text
|
|
391
|
+
*/
|
|
392
|
+
stripHtml(html) {
|
|
393
|
+
return html.replace(/<[^>]*>/g, '');
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Truncates content to specified length
|
|
397
|
+
*/
|
|
398
|
+
truncateContent(content, maxLength) {
|
|
399
|
+
if (content.length <= maxLength) {
|
|
400
|
+
return content;
|
|
401
|
+
}
|
|
402
|
+
return content.substring(0, maxLength) + '...';
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
exports.WebPageContentAction = WebPageContentAction;
|
|
406
|
+
exports.WebPageContentAction = WebPageContentAction = __decorate([
|
|
407
|
+
(0, global_1.RegisterClass)(actions_1.BaseAction, "__WebPageContent")
|
|
408
|
+
], WebPageContentAction);
|
|
409
|
+
/**
|
|
410
|
+
* Loader function to ensure the WebPageContentAction class is included in the bundle.
|
|
411
|
+
*/
|
|
412
|
+
function LoadWebPageContentAction() {
|
|
413
|
+
// this function is a stub that is used to force the bundler to include the above class in the final bundle and not tree shake them out
|
|
414
|
+
}
|
|
415
|
+
exports.LoadWebPageContentAction = LoadWebPageContentAction;
|
|
416
|
+
//# sourceMappingURL=web-page-content.action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-page-content.action.js","sourceRoot":"","sources":["../../../src/custom/web/web-page-content.action.ts"],"names":[],"mappings":";;;;;;;;;AACA,qDAAqD;AACrD,mDAAuD;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEI,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,oBAAU;IAE/B,gBAAgB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,YAAY;IAChD,cAAc,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,uBAAuB;IAE1E;;;;;;;;;;;OAWG;IACO,KAAK,CAAC,iBAAiB,CAAC,MAAuB;QACrD,IAAI,CAAC;YACD,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,W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OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACxC,CAAC;IAED;;OAEG;IACK,eAAe,CAAC,OAAe,EAAE,SAAiB;QACtD,IAAI,OAAO,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;YAC9B,OAAO,OAAO,CAAC;QACnB,CAAC;QACD,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC;IACnD,CAAC;CACJ,CAAA;AAlZY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,sBAAa,EAAC,oBAAU,EAAE,kBAAkB,CAAC;GACjC,oBAAoB,CAkZhC;AAED;;GAEG;AACH,SAAgB,wBAAwB;IACpC,uIAAuI;AAC3I,CAAC;AAFD,4DAEC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ActionResultSimple, RunActionParams } from "@memberjunction/actions-base";
|
|
2
|
+
import { BaseAction } from "@memberjunction/actions";
|
|
3
|
+
/**
|
|
4
|
+
* Action that performs web search using DuckDuckGo's Instant Answer API
|
|
5
|
+
* Returns search results with titles, URLs, and snippets
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Basic web search
|
|
10
|
+
* await runAction({
|
|
11
|
+
* ActionName: 'Web Search',
|
|
12
|
+
* Params: [{
|
|
13
|
+
* Name: 'SearchTerms',
|
|
14
|
+
* Value: 'TypeScript programming'
|
|
15
|
+
* }]
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // Search with custom result count
|
|
19
|
+
* await runAction({
|
|
20
|
+
* ActionName: 'Web Search',
|
|
21
|
+
* Params: [{
|
|
22
|
+
* Name: 'SearchTerms',
|
|
23
|
+
* Value: 'machine learning tutorials'
|
|
24
|
+
* }, {
|
|
25
|
+
* Name: 'MaxResults',
|
|
26
|
+
* Value: 15
|
|
27
|
+
* }]
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare class WebSearchAction extends BaseAction {
|
|
32
|
+
/**
|
|
33
|
+
* Executes the web search using DuckDuckGo's API
|
|
34
|
+
*
|
|
35
|
+
* @param params - The action parameters containing:
|
|
36
|
+
* - SearchTerms: Keywords to search for (required)
|
|
37
|
+
* - MaxResults: Maximum number of results to return (default: 10, max: 30)
|
|
38
|
+
* - Region: Regional search preference (default: 'us-en')
|
|
39
|
+
* - SafeSearch: Safe search level - 'strict', 'moderate', 'off' (default: 'moderate')
|
|
40
|
+
*
|
|
41
|
+
* @returns Web search results with titles, URLs, and snippets
|
|
42
|
+
*/
|
|
43
|
+
protected InternalRunAction(params: RunActionParams): Promise<ActionResultSimple>;
|
|
44
|
+
/**
|
|
45
|
+
* Parses DuckDuckGo Instant Answer API JSON response
|
|
46
|
+
*/
|
|
47
|
+
private parseInstantResults;
|
|
48
|
+
/**
|
|
49
|
+
* Extracts domain from URL
|
|
50
|
+
*/
|
|
51
|
+
private extractDomain;
|
|
52
|
+
/**
|
|
53
|
+
* Parses DuckDuckGo HTML search results
|
|
54
|
+
*/
|
|
55
|
+
private parseSearchResults;
|
|
56
|
+
/**
|
|
57
|
+
* Decodes DuckDuckGo URL redirects
|
|
58
|
+
*/
|
|
59
|
+
private decodeUrl;
|
|
60
|
+
/**
|
|
61
|
+
* Strips HTML tags and decodes entities
|
|
62
|
+
*/
|
|
63
|
+
private stripHtml;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Loader function to ensure the WebSearchAction class is included in the bundle.
|
|
67
|
+
*/
|
|
68
|
+
export declare function LoadWebSearchAction(): void;
|
|
69
|
+
//# sourceMappingURL=web-search.action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-search.action.d.ts","sourceRoot":"","sources":["../../../src/custom/web/web-search.action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBACa,eAAgB,SAAQ,UAAU;IAE3C;;;;;;;;;;OAUG;cACa,iBAAiB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA8IvF;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAkE3B;;OAEG;IACH,OAAO,CAAC,aAAa;IAQrB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAiG1B;;OAEG;IACH,OAAO,CAAC,SAAS;IAcjB;;OAEG;IACH,OAAO,CAAC,SAAS;CAYpB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,SAElC"}
|