app-manager-edge-worker 1.1.1 → 1.1.3

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.
@@ -158,6 +158,10 @@ export class WhatsAppWorkerHandler {
158
158
  syncFullHistory: false,
159
159
  markOnlineOnConnect: false, // Stealth Presence: Does NOT broadcast green online dot
160
160
  generateHighQualityLinkPreview: true,
161
+ defaultQueryTimeoutMs: 60000,
162
+ connectTimeoutMs: 60000,
163
+ keepAliveIntervalMs: 25000,
164
+ getMessage: async () => undefined,
161
165
  };
162
166
  if (version) socketConfig.version = version;
163
167
 
@@ -212,6 +216,8 @@ export class WhatsAppWorkerHandler {
212
216
 
213
217
  this._resetIdleTimer();
214
218
 
219
+ console.log(`[WhatsApp Worker] Companion Device paired successfully! User: ${this.user.name || "WhatsApp User"} (+${this.user.phone})`);
220
+
215
221
  this.onStatusChange({
216
222
  status: "CONNECTED",
217
223
  phone: this.user.phone,
@@ -222,12 +228,15 @@ export class WhatsAppWorkerHandler {
222
228
 
223
229
  if (connection === "close") {
224
230
  this.isInitializing = false;
225
- const statusCode = (lastDisconnect?.error)?.output?.statusCode;
231
+ const error = lastDisconnect?.error;
232
+ const statusCode = error?.output?.statusCode;
226
233
  const isLoggedOut =
227
234
  statusCode === DisconnectReason.loggedOut ||
228
235
  statusCode === 401 ||
229
236
  statusCode === DisconnectReason.badSession;
230
237
 
238
+ console.log(`[WhatsApp Worker] Connection closed. StatusCode: ${statusCode}. LoggedOut: ${isLoggedOut}`);
239
+
231
240
  if (isLoggedOut) {
232
241
  // Mobile App or Meta unlinked this companion device
233
242
  this.status = "DISCONNECTED";
@@ -247,8 +256,21 @@ export class WhatsAppWorkerHandler {
247
256
  reason: "LOGGED_OUT_BY_PHONE",
248
257
  });
249
258
  } else {
250
- // Temporary disconnect / network blip
251
- this.status = "STANDBY";
259
+ // Post-scan restart (code 515 restartRequired) or temporary network glitch:
260
+ // WhatsApp protocol REQUIRES immediate socket reconnection to finalize the multi-device key exchange!
261
+ if (this.sock) {
262
+ try {
263
+ this.sock.end(undefined);
264
+ } catch (_) {}
265
+ this.sock = null;
266
+ }
267
+
268
+ console.log("[WhatsApp Worker] Reconnecting to finalize credentials and establish active session...");
269
+ setTimeout(() => {
270
+ this.initialize(false).catch((err) => {
271
+ console.error("[WhatsApp Worker] Reconnection error:", err.message);
272
+ });
273
+ }, 1000);
252
274
  }
253
275
  }
254
276
  });
@@ -400,15 +422,23 @@ export class WhatsAppWorkerHandler {
400
422
  // 3. Stream PDF from authenticated URL (Zero buffer in central WebSocket)
401
423
  const response = await axios.get(downloadUrl, {
402
424
  responseType: "arraybuffer",
403
- timeout: 20000,
425
+ timeout: 25000,
404
426
  });
405
427
 
406
428
  const buffer = Buffer.from(response.data);
429
+ if (!buffer || buffer.length === 0) {
430
+ throw new Error(`Failed to download document: received 0 bytes from ${downloadUrl}`);
431
+ }
407
432
 
408
433
  // 4. SHA-256 Integrity Verification
434
+ const actualSha256 = crypto.createHash("sha256").update(buffer).digest("hex");
435
+ const serverSha256 = response.headers?.["x-sha256"] || response.headers?.["x-checksum-sha256"];
436
+
409
437
  if (expectedSha256) {
410
- const actualSha256 = crypto.createHash("sha256").update(buffer).digest("hex");
411
- if (actualSha256.toLowerCase() !== expectedSha256.toLowerCase()) {
438
+ const matchesExpected = actualSha256.toLowerCase() === expectedSha256.toLowerCase();
439
+ const matchesServerHeader = serverSha256 && actualSha256.toLowerCase() === String(serverSha256).toLowerCase();
440
+
441
+ if (!matchesExpected && !matchesServerHeader) {
412
442
  throw new Error(
413
443
  `Document integrity check failed. Expected SHA-256 ${expectedSha256}, got ${actualSha256}`
414
444
  );
package/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Chetan Mohite
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.