app-manager-edge-worker 1.0.6 → 1.0.7
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/bin/worker.js +0 -0
- package/package.json +46 -45
- package/src/banner.js +2 -2
- package/src/client.js +6 -1
- package/src/handlers/mailHandler.js +74 -0
- package/src/handlers/previewHandler.js +484 -484
- package/src/handlers/scrapeHandler.js +801 -801
- package/src/handlers/transformUtils.js +340 -340
package/bin/worker.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,45 +1,46 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "app-manager-edge-worker",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Distributed Scraper Edge Worker for Apps Manager. Run on any local machine, VPS, or Termux Android device to serve browser and HTTP scraping jobs.",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"bin": {
|
|
7
|
-
"app-manager-edge-worker": "
|
|
8
|
-
"apps-manager-worker": "
|
|
9
|
-
},
|
|
10
|
-
"main": "./src/client.js",
|
|
11
|
-
"scripts": {
|
|
12
|
-
"start": "node ./bin/worker.js"
|
|
13
|
-
},
|
|
14
|
-
"keywords": [
|
|
15
|
-
"app-manager-edge-worker",
|
|
16
|
-
"apps-manager",
|
|
17
|
-
"scraper",
|
|
18
|
-
"edge-worker",
|
|
19
|
-
"puppeteer",
|
|
20
|
-
"residential-proxy",
|
|
21
|
-
"distributed-scraping",
|
|
22
|
-
"termux"
|
|
23
|
-
],
|
|
24
|
-
"author": "Chetan Mohite <chetanmohite2128@gmail.com> (https://github.com/codes-by-chetan)",
|
|
25
|
-
"license": "MIT",
|
|
26
|
-
"homepage": "https://apps-manager.onrender.com",
|
|
27
|
-
"repository": {
|
|
28
|
-
"type": "git",
|
|
29
|
-
"url": "git+https://github.com/codes-by-chetan/Apps_Manager.git",
|
|
30
|
-
"directory": "packages/worker"
|
|
31
|
-
},
|
|
32
|
-
"publishConfig": {
|
|
33
|
-
"access": "public"
|
|
34
|
-
},
|
|
35
|
-
"dependencies": {
|
|
36
|
-
"@puppeteer/browsers": "^3.2.2",
|
|
37
|
-
"axios": "^1.8.1",
|
|
38
|
-
"cheerio": "^1.0.0",
|
|
39
|
-
"puppeteer": "^24.3.0",
|
|
40
|
-
"puppeteer-core": "^24.3.0",
|
|
41
|
-
"puppeteer-extra": "^3.3.6",
|
|
42
|
-
"puppeteer-extra-plugin-stealth": "^2.11.2",
|
|
43
|
-
"socket.io-client": "^4.8.1"
|
|
44
|
-
|
|
45
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "app-manager-edge-worker",
|
|
3
|
+
"version": "1.0.7",
|
|
4
|
+
"description": "Distributed Scraper Edge Worker for Apps Manager. Run on any local machine, VPS, or Termux Android device to serve browser and HTTP scraping jobs.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"app-manager-edge-worker": "bin/worker.js",
|
|
8
|
+
"apps-manager-worker": "bin/worker.js"
|
|
9
|
+
},
|
|
10
|
+
"main": "./src/client.js",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"start": "node ./bin/worker.js"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"app-manager-edge-worker",
|
|
16
|
+
"apps-manager",
|
|
17
|
+
"scraper",
|
|
18
|
+
"edge-worker",
|
|
19
|
+
"puppeteer",
|
|
20
|
+
"residential-proxy",
|
|
21
|
+
"distributed-scraping",
|
|
22
|
+
"termux"
|
|
23
|
+
],
|
|
24
|
+
"author": "Chetan Mohite <chetanmohite2128@gmail.com> (https://github.com/codes-by-chetan)",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"homepage": "https://apps-manager.onrender.com",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/codes-by-chetan/Apps_Manager.git",
|
|
30
|
+
"directory": "packages/worker"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@puppeteer/browsers": "^3.2.2",
|
|
37
|
+
"axios": "^1.8.1",
|
|
38
|
+
"cheerio": "^1.0.0",
|
|
39
|
+
"puppeteer": "^24.3.0",
|
|
40
|
+
"puppeteer-core": "^24.3.0",
|
|
41
|
+
"puppeteer-extra": "^3.3.6",
|
|
42
|
+
"puppeteer-extra-plugin-stealth": "^2.11.2",
|
|
43
|
+
"socket.io-client": "^4.8.1",
|
|
44
|
+
"nodemailer": "^6.9.16"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/banner.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createRequire } from "module";
|
|
2
2
|
|
|
3
3
|
const require = createRequire(import.meta.url);
|
|
4
|
-
let workerVersion = "1.0.
|
|
4
|
+
let workerVersion = "1.0.7";
|
|
5
5
|
try {
|
|
6
6
|
const pkg = require("../package.json");
|
|
7
7
|
if (pkg?.version) workerVersion = pkg.version;
|
|
8
|
-
} catch (_) {}
|
|
8
|
+
} catch (_) { }
|
|
9
9
|
|
|
10
10
|
// ANSI color helpers
|
|
11
11
|
const colors = {
|
package/src/client.js
CHANGED
|
@@ -6,6 +6,7 @@ import { execSync } from "child_process";
|
|
|
6
6
|
import localBrowserManager from "./browser.js";
|
|
7
7
|
import { handleChromiumScrape, handleHttpScrape } from "./handlers/scrapeHandler.js";
|
|
8
8
|
import { handlePreviewPage, handleInspectElement } from "./handlers/previewHandler.js";
|
|
9
|
+
import { handleSendEmail } from "./handlers/mailHandler.js";
|
|
9
10
|
import { printBanner, logInfo, logSuccess, logWarn, logError, logJob } from "./banner.js";
|
|
10
11
|
|
|
11
12
|
export async function startWorkerClient(config) {
|
|
@@ -134,7 +135,9 @@ export async function startWorkerClient(config) {
|
|
|
134
135
|
const jobId = job.jobId;
|
|
135
136
|
const jobType = job.jobType || job.type;
|
|
136
137
|
const payload = job.payload || {};
|
|
137
|
-
const targetUrl =
|
|
138
|
+
const targetUrl = jobType === "SEND_EMAIL"
|
|
139
|
+
? (payload.mailOptions?.to ? `to: ${payload.mailOptions.to}` : "email")
|
|
140
|
+
: (payload.url || "(no url)");
|
|
138
141
|
|
|
139
142
|
logJob(jobType, targetUrl);
|
|
140
143
|
activeJobs++;
|
|
@@ -152,6 +155,8 @@ export async function startWorkerClient(config) {
|
|
|
152
155
|
resultData = await handlePreviewPage(payload);
|
|
153
156
|
} else if (jobType === "INSPECT_ELEMENT") {
|
|
154
157
|
resultData = await handleInspectElement(payload);
|
|
158
|
+
} else if (jobType === "SEND_EMAIL") {
|
|
159
|
+
resultData = await handleSendEmail(payload);
|
|
155
160
|
} else {
|
|
156
161
|
throw new Error(`Unsupported job type: ${jobType}`);
|
|
157
162
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import nodemailer from "nodemailer";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Handles incoming SEND_EMAIL job from the cluster server.
|
|
5
|
+
*
|
|
6
|
+
* Security & Reliability Guarantees:
|
|
7
|
+
* 1. Zero credential retention: Credentials are received in-memory and destroyed after sending.
|
|
8
|
+
* 2. Fail-fast timeouts: Prevents socket hanging with strict 10s connection & socket timeouts.
|
|
9
|
+
* 3. Structured result payload: Returns delivery metadata (messageId, accepted, response).
|
|
10
|
+
*
|
|
11
|
+
* @param {Object} payload
|
|
12
|
+
* @param {Object} payload.mailOptions - { to, subject, html, text, fromName, fromEmail }
|
|
13
|
+
* @param {Object} payload.smtpConfig - { host, port, secure, auth: { user, pass } }
|
|
14
|
+
* @returns {Promise<Object>}
|
|
15
|
+
*/
|
|
16
|
+
export async function handleSendEmail(payload = {}) {
|
|
17
|
+
const { mailOptions, smtpConfig } = payload;
|
|
18
|
+
|
|
19
|
+
if (!mailOptions || !mailOptions.to || !mailOptions.subject) {
|
|
20
|
+
throw new Error("Invalid mailOptions: 'to' and 'subject' are required.");
|
|
21
|
+
}
|
|
22
|
+
if (!smtpConfig || !smtpConfig.auth?.user || !smtpConfig.auth?.pass) {
|
|
23
|
+
throw new Error("Invalid smtpConfig: credentials missing.");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const host = smtpConfig.host || "smtp.titan.email";
|
|
27
|
+
const port = Number(smtpConfig.port) || 465;
|
|
28
|
+
const secure = smtpConfig.secure !== undefined ? Boolean(smtpConfig.secure) : port === 465;
|
|
29
|
+
|
|
30
|
+
// Ephemeral Nodemailer transporter created strictly for this in-memory dispatch
|
|
31
|
+
const transporter = nodemailer.createTransport({
|
|
32
|
+
host,
|
|
33
|
+
port,
|
|
34
|
+
secure,
|
|
35
|
+
auth: {
|
|
36
|
+
user: smtpConfig.auth.user,
|
|
37
|
+
pass: smtpConfig.auth.pass,
|
|
38
|
+
},
|
|
39
|
+
connectionTimeout: 10000,
|
|
40
|
+
greetingTimeout: 10000,
|
|
41
|
+
socketTimeout: 15000,
|
|
42
|
+
tls: {
|
|
43
|
+
rejectUnauthorized: false, // Prevents certificate mismatches on custom domain mail
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const fromName = mailOptions.fromName || "Apps Manager";
|
|
49
|
+
const fromAddress = mailOptions.fromEmail || smtpConfig.auth.user;
|
|
50
|
+
|
|
51
|
+
const info = await transporter.sendMail({
|
|
52
|
+
from: `"${fromName}" <${fromAddress}>`,
|
|
53
|
+
to: mailOptions.to,
|
|
54
|
+
subject: mailOptions.subject,
|
|
55
|
+
text: mailOptions.text,
|
|
56
|
+
html: mailOptions.html,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
success: true,
|
|
61
|
+
messageId: info.messageId,
|
|
62
|
+
accepted: info.accepted,
|
|
63
|
+
rejected: info.rejected,
|
|
64
|
+
response: info.response,
|
|
65
|
+
};
|
|
66
|
+
} finally {
|
|
67
|
+
// Explicitly close transporter socket to prevent lingering connections
|
|
68
|
+
try {
|
|
69
|
+
transporter.close();
|
|
70
|
+
} catch (_) {
|
|
71
|
+
// Best effort cleanup
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|