app-manager-edge-worker 1.0.5 → 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 CHANGED
File without changes
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "app-manager-edge-worker",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
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
5
  "type": "module",
6
6
  "bin": {
7
- "app-manager-edge-worker": "./bin/worker.js",
8
- "apps-manager-worker": "./bin/worker.js"
7
+ "app-manager-edge-worker": "bin/worker.js",
8
+ "apps-manager-worker": "bin/worker.js"
9
9
  },
10
10
  "main": "./src/client.js",
11
11
  "scripts": {
@@ -40,6 +40,7 @@
40
40
  "puppeteer-core": "^24.3.0",
41
41
  "puppeteer-extra": "^3.3.6",
42
42
  "puppeteer-extra-plugin-stealth": "^2.11.2",
43
- "socket.io-client": "^4.8.1"
43
+ "socket.io-client": "^4.8.1",
44
+ "nodemailer": "^6.9.16"
44
45
  }
45
46
  }
package/src/banner.js CHANGED
@@ -1,3 +1,12 @@
1
+ import { createRequire } from "module";
2
+
3
+ const require = createRequire(import.meta.url);
4
+ let workerVersion = "1.0.7";
5
+ try {
6
+ const pkg = require("../package.json");
7
+ if (pkg?.version) workerVersion = pkg.version;
8
+ } catch (_) { }
9
+
1
10
  // ANSI color helpers
2
11
  const colors = {
3
12
  reset: "\x1b[0m",
@@ -12,13 +21,18 @@ const colors = {
12
21
  };
13
22
 
14
23
  /**
15
- * Returns a formatted timestamp string: [YYYY-MM-DD HH:mm:ss]
24
+ * Returns a formatted timestamp string using the device's local time: [YYYY-MM-DD HH:mm:ss]
16
25
  */
17
26
  function timestamp() {
18
27
  const now = new Date();
19
- const date = now.toISOString().slice(0, 10);
20
- const time = now.toISOString().slice(11, 19);
21
- return `${colors.gray}[${date} ${time}]${colors.reset}`;
28
+ const pad = (n) => String(n).padStart(2, "0");
29
+ const year = now.getFullYear();
30
+ const month = pad(now.getMonth() + 1);
31
+ const day = pad(now.getDate());
32
+ const hours = pad(now.getHours());
33
+ const minutes = pad(now.getMinutes());
34
+ const seconds = pad(now.getSeconds());
35
+ return `${colors.gray}[${year}-${month}-${day} ${hours}:${minutes}:${seconds}]${colors.reset}`;
22
36
  }
23
37
 
24
38
  export function printBanner({ workerName, serverUrl, concurrency, platform, isTermux, keepAliveMinutes }) {
@@ -31,7 +45,7 @@ export function printBanner({ workerName, serverUrl, concurrency, platform, isTe
31
45
  console.log(" ██║ ██║██║ ██║ ███████║██╗██║ ╚═╝ ██║██║ ██║██║ ╚████║██║ ██║╚██████╔╝███████╗██║ ██║");
32
46
  console.log(" ╚═╝ ╚═╝╚═╝ ╚═╝ ╚══════╝╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝");
33
47
  console.log(`${colors.reset}`);
34
- console.log(`${colors.bright} 🌐 Distributed Scraper Edge Worker Client v1.0.4${colors.reset}`);
48
+ console.log(`${colors.bright} 🌐 Distributed Scraper Edge Worker Client v${workerVersion}${colors.reset}`);
35
49
  console.log(`${colors.dim} Zero-cost, persistent tunneling & residential edge scraping${colors.reset}`);
36
50
  console.log("--------------------------------------------------------------------------------");
37
51
  console.log(` ${colors.bright}Device Name :${colors.reset} ${colors.green}${workerName}${colors.reset}`);
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 = payload.url || "(no url)";
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
+ }