fix: address PR review comments

Fixes from code review:

1. Fix #1,6: Use connection.update event instead of overriding sock.end()
   - Listens for 'close' event to cleanup interval
   - Handles both explicit close and internal disconnections

2. Fix #3: Exit code 2 when fetch fails (not 0)
   - Allows CI to distinguish success/error/fetch-failed
   - Properly signals fetch failures to workflows

3. Fix #4: Document revision bounds + add env vars
   - Added detailed comments explaining min/max revision values
   - Made configurable via WA_MIN_REVISION/WA_MAX_REVISION env vars

4. Fix #5,9: Remove unused fetchLatestVersion option
   - Removed from SocketConfig and defaults
   - Updated versionCheckIntervalMs docs to clarify it's only for makeWASocketAutoVersion

5. Fix #7: Use separate variable for version tracking
   - trackedVersion instead of mutating mergedConfig
   - Prevents unexpected side effects

6. Fix #8: Check socket state before emitting events
   - isSocketClosed flag to prevent race conditions
   - Double-check after async operations

7. Fix #10: Implement force parameter in workflow
   - Creates PR even without version changes when force=true
   - Useful for re-triggering updates manually

Note: Test coverage (Fix #2) deferred to separate PR due to
ESM mocking complexity with Jest.
This commit is contained in:
Claude
2026-01-21 17:21:49 +00:00
parent 805fdd3525
commit 46ffaf027c
5 changed files with 172 additions and 52 deletions
+4 -7
View File
@@ -49,17 +49,14 @@ export type SocketConfig = {
logger: ILogger
/** version to connect with */
version: WAVersion
/**
* Automatically fetch the latest WhatsApp Web version on connect.
* When enabled, fetches from web.whatsapp.com before connecting.
* Falls back to bundled version if fetch fails.
* @default false
*/
fetchLatestVersion: boolean
/**
* Interval in milliseconds to check for new WhatsApp Web versions.
* When a new version is detected, it will be used on the next reconnection.
* Set to 0 to disable periodic checks.
*
* Note: This option is only used by `makeWASocketAutoVersion()`.
* The standard `makeWASocket()` does not perform automatic version checks.
*
* @default 21600000 (6 hours)
*/
versionCheckIntervalMs: number