Conversation
WalkthroughAdds an internal QRCode library and ASCII QR renderer, switches auth to use the internal renderer, makes WhatsApp asset loading runtime-agnostic, and updates build scripts to copy vendor assets into dist. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant AuthController as Auth Controller
participant QRUtil as generateASCIIQR
participant Vendor as Vendor QR Modules
User->>AuthController: request QR for pairing (code)
AuthController->>QRUtil: generateASCIIQR(code, opts)
note right of QRUtil: dynamic import of vendor modules (QRCode, QRUtil, etc.)
QRUtil->>Vendor: instantiate QRCode(), addData(), make()
Vendor-->>QRUtil: QR matrix
QRUtil-->>AuthController: ASCII QR string
AuthController-->>User: print/return ASCII QR
sequenceDiagram
autonumber
participant WAAPI as src/api/whatsapp.ts
participant Resolver as getDirname()
participant FS as filesystem
WAAPI->>Resolver: compute base dirname (__dirname or import.meta.url)
Resolver-->>WAAPI: base path
WAAPI->>FS: checkFileExists(../../lib/wapi/wapi.js)
alt asset exists in package
FS-->>WAAPI: true
WAAPI->>FS: load ../../lib/wapi/wapi.js & ../../lib/middleware/middleware.js
else fallback
FS-->>WAAPI: false
WAAPI->>FS: load node_modules/venom-bot/dist/lib/.../wapi.js & middleware.js
end
WAAPI->>WAAPI: page.evaluate(...) to inject/evaluate scripts
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
vendor/QRCode/QRMath.js (1)
31-42: Avoid redeclaring the loop variable 'i'.The variable
iis redeclared in three consecutive for loops. While this works in JavaScript withvar, it's better practice to use unique variable names orletfor block-scoped declarations to improve code clarity and avoid potential confusion.Apply this diff to use distinct variable names:
-for (var i = 0; i < 8; i++) { +for (var i = 0; i < 8; i++) { QRMath.EXP_TABLE[i] = 1 << i; } -for (var i = 8; i < 256; i++) { +for (var j = 8; j < 256; j++) { - QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4] - ^ QRMath.EXP_TABLE[i - 5] - ^ QRMath.EXP_TABLE[i - 6] - ^ QRMath.EXP_TABLE[i - 8]; + QRMath.EXP_TABLE[j] = QRMath.EXP_TABLE[j - 4] + ^ QRMath.EXP_TABLE[j - 5] + ^ QRMath.EXP_TABLE[j - 6] + ^ QRMath.EXP_TABLE[j - 8]; } -for (var i = 0; i < 255; i++) { +for (var k = 0; k < 255; k++) { - QRMath.LOG_TABLE[QRMath.EXP_TABLE[i] ] = i; + QRMath.LOG_TABLE[QRMath.EXP_TABLE[k] ] = k; }Based on learnings
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (14)
package.json(1 hunks)src/api/whatsapp.ts(2 hunks)src/controllers/auth.ts(3 hunks)src/utils/qr-generator.ts(1 hunks)vendor/QRCode/QR8bitByte.js(1 hunks)vendor/QRCode/QRBitBuffer.js(1 hunks)vendor/QRCode/QRErrorCorrectLevel.js(1 hunks)vendor/QRCode/QRMaskPattern.js(1 hunks)vendor/QRCode/QRMath.js(1 hunks)vendor/QRCode/QRMode.js(1 hunks)vendor/QRCode/QRPolynomial.js(1 hunks)vendor/QRCode/QRRSBlock.js(1 hunks)vendor/QRCode/QRUtil.js(1 hunks)vendor/QRCode/index.js(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/controllers/*.ts
📄 CodeRabbit inference engine (CLAUDE.md)
Controllers (initializer.ts for session creation, browser.ts for Puppeteer management, auth.ts for authentication/QR) live under src/controllers
Files:
src/controllers/auth.ts
🧠 Learnings (1)
📚 Learning: 2025-09-08T17:49:03.345Z
Learnt from: CR
PR: venomlib/venom#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-08T17:49:03.345Z
Learning: Applies to src/lib/wapi/**/*.js : WAPI layer code is built with webpack and injected into the Puppeteer browser context
Applied to files:
src/api/whatsapp.ts
🧬 Code graph analysis (2)
src/api/whatsapp.ts (1)
scripts/create-wrappers.js (1)
__dirname(8-8)
src/controllers/auth.ts (1)
src/utils/qr-generator.ts (1)
generateASCIIQR(30-118)
🪛 Biome (2.1.2)
vendor/QRCode/QRMath.js
[error] 34-34: Shouldn't redeclare 'i'. Consider to delete it or rename it.
'i' is defined here:
(lint/suspicious/noRedeclare)
[error] 40-40: Shouldn't redeclare 'i'. Consider to delete it or rename it.
'i' is defined here:
(lint/suspicious/noRedeclare)
🔇 Additional comments (9)
package.json (1)
28-30: LGTM!The build pipeline correctly chains the vendor asset copying step after compiling CJS, ESM, and wrapper code. This ensures the vendor QRCode modules are available at runtime.
vendor/QRCode/QRMode.js (1)
1-6: LGTM!The QR mode constants are correctly defined using bit flags, following the standard QR code specification.
vendor/QRCode/QRMaskPattern.js (1)
1-10: LGTM!The mask pattern constants are correctly mapped to their respective integer values (0-7) as per the QR code specification.
vendor/QRCode/QRErrorCorrectLevel.js (1)
1-6: LGTM!The error correction level constants are correctly mapped according to the QR code specification (L=1, M=0, Q=3, H=2).
src/controllers/auth.ts (2)
16-18: Verify the simplified interface status detection.The interface status check has been simplified to only check for canvas presence to determine UNPAIRED status. Ensure this logic correctly identifies all UNPAIRED states and doesn't produce false positives.
96-101: Good error handling.The try/catch block with error logging and fallback to empty string provides robust error handling for QR generation failures.
vendor/QRCode/QRMath.js (1)
1-29: LGTM!The GF(256) finite field arithmetic implementation is correct and follows the standard algorithm for QR code error correction. The
glogandgexpfunctions properly handle edge cases.src/api/whatsapp.ts (2)
15-22: Remove the incorrect__dirnamewarning. The try/catch properly catches the runtimeReferenceErrorin ESM, so the fallback covers both module systems and no change is needed.Likely an incorrect or invalid review comment.
73-73: Verify WAPI and middleware asset paths for CJS and ESM outputs
After a local build, confirm that
dist/lib/wapi/wapi.jsanddist/lib/middleware/middleware.jsexist- the relative paths (
../../lib/wapi/wapi.jsat line 73 and../../lib/middleware/middleware.jsat line 81 insrc/api/whatsapp.ts) resolve correctly from bothdist/cjs/api/whatsapp.jsanddist/esm/api/whatsapp.js
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/controllers/auth.ts(3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/controllers/*.ts
📄 CodeRabbit inference engine (CLAUDE.md)
Controllers (initializer.ts for session creation, browser.ts for Puppeteer management, auth.ts for authentication/QR) live under src/controllers
Files:
src/controllers/auth.ts
🧬 Code graph analysis (1)
src/controllers/auth.ts (1)
src/utils/qr-generator.ts (1)
generateASCIIQR(30-118)
🔇 Additional comments (2)
src/controllers/auth.ts (2)
3-3: LGTM! Import change aligns with PR objectives.The switch from external
qrcode-terminalto the internalgenerateASCIIQRimplementation supports the PR's goal of making asset loading runtime-agnostic.
16-18: Confirm canvas-only UNPAIRED detection covers all edge cases
I couldn’t find any other DOM wrapper or status checks in auth.ts; manually verify that relying solely ondocument.querySelector('canvas')correctly captures all UNPAIRED scenarios.
Fixes # .
Changes proposed in this pull request
To test (it takes a while):
npm install github:<username>/venom#<branch>Summary by CodeRabbit
New Features
Bug Fixes
Chores