Skip to content

Grab bag of improvements#137

Merged
9cb14c1ec0 merged 3 commits intomasterfrom
updates
Dec 31, 2025
Merged

Grab bag of improvements#137
9cb14c1ec0 merged 3 commits intomasterfrom
updates

Conversation

@9cb14c1ec0
Copy link
Copy Markdown
Collaborator

@9cb14c1ec0 9cb14c1ec0 commented Dec 31, 2025

Fixes # .

Changes proposed in this pull request

To test (it takes a while): npm install github:<username>/venom#<branch>

Summary by CodeRabbit

  • Chores
    • Restructured build scripts to run library and app builds concurrently for faster CI/local builds
    • Implemented persistent filesystem caching for Webpack and TypeScript to speed rebuilds
    • Enabled incremental TypeScript compilation for quicker development iterations
    • Added dedicated cache cleanup commands (cache-only and full clean)
    • Simplified internal async handling across modules to streamline runtime behavior

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 31, 2025

Warning

Rate limit exceeded

@9cb14c1ec0 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 15 minutes and 28 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 430f817 and 7c36df3.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • package.json
📝 Walkthrough

Walkthrough

Adds build and cache optimizations (npm scripts, webpack filesystem caches, TypeScript incremental tsBuildInfo files) and refactors many async code paths across API layers and initializer to use async/await and throw-based error propagation instead of Promise constructor patterns.

Changes

Cohort / File(s) Summary
Build scripts
package.json
Added build:ts, build:libs, clean:cache, clean:all; updated build:venom, build, and build:test to run new concurrent flows and fix:imports.
Webpack cache configs
src/lib/middleware/webpack.config.mjs, src/lib/wapi/webpack.config.mjs
Added cache: { type: 'filesystem', cacheDirectory: ... } to both webpack configs, pointing into node_modules/.cache/webpack-*.
TypeScript incremental config
tsconfig.json, tsconfig.cjs.json, tsconfig.esm.json
Enabled incremental and/or added tsBuildInfoFile entries pointing to ./node_modules/.cache/tsbuildinfo-*.
Initializer / startup flow
src/controllers/initializer.ts
Removed Promise constructor boilerplate; converted to direct async/await, throw-based errors, updated implementation return type to Promise<Whatsapp>, consolidated option parsing and logger setup.
API layers — control flow refactor
src/api/layers/*
src/api/layers/controls.layer.ts, group.layer.ts, profile.layer.ts, retriever.layer.ts, sender.layer.ts, ui.layer.ts
Replaced manual new Promise patterns with async/await; switched from resolve/reject to direct returns and throw for errors; signature changes: sendListMenu (subtitle→subTitle), getAllMessagesDate expanded params, sendMute marked async.
WAPI message forwarding
src/lib/wapi/functions/forward-messages.js
Rewrote to async/await with try/catch, early validation, per-message processing via Store.addAndSendMsgToChat, and throw/return-based error signaling instead of Promise plumbing.
Middleware/Webpack usage
src/lib/middleware/... (configs)
Introduced persistent filesystem cache for middleware webpack config (same cohort as webpack cache but relevant to middleware usage).
Miscellaneous code-style refactors
various files under src/...
Import path consolidations, minor JSDoc/comment fixes, and small parameter/variable renames to align with refactored flows.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐇 I dug a cache where builds can rest,
Webpack and tsc now work their best.
Async paths trimmed, errors thrown true,
Faster hops ahead — a carrot or two! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'Grab bag of improvements' is vague and non-descriptive, using a generic phrase that doesn't convey meaningful information about the changeset. While the PR does contain multiple improvements, the title doesn't clearly communicate the main focus of the changes. Consider a more specific title that reflects the primary changes, such as 'Refactor to proper async/await patterns and optimize build configuration' or 'Simplify async patterns and add webpack caching'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Nitpick comments (6)
src/api/layers/group.layer.ts (1)

72-74: Consider using strict equality for error checks.

Using == instead of === works here but is inconsistent with TypeScript best practices. This pattern appears in multiple methods (setGroupSettings, setGroupTitle, setGroupDescription, getGroupMembers, getGroupAdmins).

🔎 Proposed fix
-    if (result['erro'] == true) {
+    if (result['erro'] === true) {
       throw result;
     }
src/api/layers/controls.layer.ts (1)

200-200: Inconsistent equality operator.

Line 200 uses strict equality (===) to check result['erro'], while other similar checks in this file (lines 67, 100) and across other layers use loose equality (==). For consistency, align with the pattern used elsewhere.

🔎 Suggested fix for consistency
-    if (result['erro'] === true) {
+    if (result['erro'] == true) {
src/api/layers/retriever.layer.ts (1)

132-137: Clarify the await pattern for consistency.

Lines 134-135 assign the Promise without awaiting, then await in the return statement: let chats = WAPI.getAllChats(); return (await chats).filter(...). This is functionally correct but less clear than the pattern used at line 123 in getAllChatsNewMsg, which awaits immediately: let chats = await WAPI.getAllChats();.

Apply the same pattern at lines 204-205 in getAllChatsTransmission for consistency.

🔎 Suggested refactor for clarity
   public async getAllChatsContacts() {
     return await this.page.evaluate(async () => {
-      let chats = WAPI.getAllChats();
-      return (await chats).filter((chat) => chat.kind === 'chat');
+      let chats = await WAPI.getAllChats();
+      return chats.filter((chat) => chat.kind === 'chat');
     });
   }

Apply the same pattern to getAllChatsTransmission (lines 202-207):

   public async getAllChatsTransmission() {
     return await this.page.evaluate(async () => {
-      let chats = WAPI.getAllChats();
-      return (await chats).filter((chat) => chat.kind === 'broadcast');
+      let chats = await WAPI.getAllChats();
+      return chats.filter((chat) => chat.kind === 'broadcast');
     });
   }
src/api/layers/sender.layer.ts (2)

753-758: Logic error: Condition allows sending with any MIME type.

The condition on lines 753-758 uses || which means it will proceed if !mimeType is true (but this case already throws at line 745-751) OR if the mimeType matches audio types. However, any non-audio mimeType that exists will still reach the else branch correctly.

Wait—re-analyzing: if mimeType is truthy but NOT audio, the condition is false, so the else branch (lines 769-775) correctly throws. The !mimeType check is redundant since we already threw for falsy mimeType above.

🔎 Suggested simplification (optional)
-    if (
-      !mimeType ||
-      mimeType.includes('audio/mpeg') ||
-      mimeType.includes('audio/mp3') ||
-      mimeType.includes('audio/ogg')
-    ) {
+    if (
+      mimeType.includes('audio/mpeg') ||
+      mimeType.includes('audio/mp3') ||
+      mimeType.includes('audio/ogg')
+    ) {

931-933: Clarify filename fallback condition.

The condition !filename && typeof filename !== 'string' is slightly confusing. It evaluates to:

  • true for undefined/null → uses basename
  • false for "" (empty string) → keeps empty string

If an empty string should also trigger the fallback, simplify to !filename. If preserving empty strings is intentional, a comment would help clarify.

src/controllers/initializer.ts (1)

305-306: Empty catch blocks swallow errors silently.

Multiple locations have empty catches (lines 305, 330, 354, 394) that discard all errors. While this may be intentional to prevent unhandled rejections from crashing the process, consider at least logging errors at debug level for troubleshooting.

Also, .catch() without a handler (lines 330, 354, 394) is unusual—explicitly use .catch(() => {}) or .catch((e) => { /* intentionally ignored */ }) for clarity.

Also applies to: 329-330, 353-354, 393-394

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 666b0ec and 430f817.

📒 Files selected for processing (9)
  • src/api/helpers/closes-browser.ts
  • src/api/layers/controls.layer.ts
  • src/api/layers/group.layer.ts
  • src/api/layers/profile.layer.ts
  • src/api/layers/retriever.layer.ts
  • src/api/layers/sender.layer.ts
  • src/api/layers/ui.layer.ts
  • src/controllers/initializer.ts
  • src/lib/wapi/functions/forward-messages.js
🧰 Additional context used
📓 Path-based instructions (5)
src/api/layers/*.layer.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Keep functionality layers in src/api/layers using the *.layer.ts naming (e.g., sender.layer.ts, listener.layer.ts, group.layer.ts, profile.layer.ts, controls.layer.ts, retriever.layer.ts)

Files:

  • src/api/layers/controls.layer.ts
  • src/api/layers/profile.layer.ts
  • src/api/layers/retriever.layer.ts
  • src/api/layers/ui.layer.ts
  • src/api/layers/group.layer.ts
  • src/api/layers/sender.layer.ts
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/initializer.ts
src/api/helpers/**/*.{ts,js}

📄 CodeRabbit inference engine (CLAUDE.md)

Put utility helpers (e.g., encryption, QR code utilities) under src/api/helpers

Files:

  • src/api/helpers/closes-browser.ts
src/lib/wapi/functions/**/*.js

📄 CodeRabbit inference engine (CLAUDE.md)

WAPI functions in src/lib/wapi/functions are JavaScript files injected into the browser; after changing them, run npm run build:wapi to rebuild

Files:

  • src/lib/wapi/functions/forward-messages.js
src/lib/wapi/**/*.js

📄 CodeRabbit inference engine (CLAUDE.md)

WAPI layer code is built with webpack and injected into the Puppeteer browser context

Files:

  • src/lib/wapi/functions/forward-messages.js
🧠 Learnings (5)
📓 Common learnings
Learnt from: CR
Repo: venomlib/venom PR: 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
📚 Learning: 2025-09-08T17:49:03.345Z
Learnt from: CR
Repo: venomlib/venom PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-09-08T17:49:03.345Z
Learning: Applies to src/api/layers/*.layer.ts : Keep functionality layers in src/api/layers using the *.layer.ts naming (e.g., sender.layer.ts, listener.layer.ts, group.layer.ts, profile.layer.ts, controls.layer.ts, retriever.layer.ts)

Applied to files:

  • src/api/layers/controls.layer.ts
  • src/api/layers/profile.layer.ts
  • src/api/layers/retriever.layer.ts
  • src/api/layers/group.layer.ts
  • src/api/layers/sender.layer.ts
📚 Learning: 2025-09-08T17:49:03.345Z
Learnt from: CR
Repo: venomlib/venom PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-09-08T17:49:03.345Z
Learning: Applies to src/controllers/*.ts : Controllers (initializer.ts for session creation, browser.ts for Puppeteer management, auth.ts for authentication/QR) live under src/controllers

Applied to files:

  • src/controllers/initializer.ts
  • src/api/layers/retriever.layer.ts
📚 Learning: 2025-09-08T17:49:03.345Z
Learnt from: CR
Repo: venomlib/venom PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-09-08T17:49:03.345Z
Learning: Applies to src/config/**/*.ts : Keep browser/Puppeteer and session management configuration under src/config

Applied to files:

  • src/api/layers/retriever.layer.ts
📚 Learning: 2025-09-08T17:49:03.345Z
Learnt from: CR
Repo: venomlib/venom PR: 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/layers/retriever.layer.ts
  • src/api/layers/sender.layer.ts
🧬 Code graph analysis (6)
src/api/layers/profile.layer.ts (3)
src/lib/wapi/functions/send-message.js (3)
  • result (83-83)
  • result (103-103)
  • result (116-118)
src/lib/wapi/functions/get-message-by-id.js (1)
  • result (36-36)
src/lib/wapi/functions/get-list-mute.js (1)
  • interfaceMute (34-37)
src/api/layers/retriever.layer.ts (5)
src/api/helpers/layers-interface.ts (1)
  • checkValuesSender (10-34)
src/lib/wapi/serializers/serialize-message.js (1)
  • chats (6-6)
src/lib/wapi/wapi.js (3)
  • chat (443-443)
  • chat (502-502)
  • chat (511-511)
src/api/model/index.ts (1)
  • WhatsappProfile (14-14)
src/api/model/whatsapp-profile.ts (1)
  • WhatsappProfile (3-10)
src/api/helpers/closes-browser.ts (3)
app.js (1)
  • browser (25-25)
src/controllers/browser.ts (1)
  • browser (540-543)
src/api/layers/host.layer.ts (1)
  • tryAutoClose (66-76)
src/api/layers/ui.layer.ts (1)
src/api/helpers/layers-interface.ts (1)
  • checkValuesSender (10-34)
src/api/layers/group.layer.ts (4)
src/api/helpers/layers-interface.ts (1)
  • checkValuesSender (10-34)
src/lib/wapi/functions/send-file.js (1)
  • result (107-223)
src/lib/wapi/functions/send-ptt.js (1)
  • result (69-170)
src/lib/wapi/functions/demote-participant.js (1)
  • demoteParticipant (1-30)
src/api/layers/sender.layer.ts (4)
src/api/helpers/layers-interface.ts (1)
  • checkValuesSender (10-34)
src/api/model/result.ts (1)
  • SendFileResult (19-24)
src/api/helpers/download-file.ts (1)
  • downloadFileToBase64 (3-43)
src/api/helpers/dowload-meta.ts (1)
  • dowloadMetaFileBase64 (5-79)
🪛 Biome (2.1.2)
src/lib/wapi/functions/forward-messages.js

[error] 66-66: Shouldn't redeclare 'obj'. Consider to delete it or rename it.

'obj' is defined here:

(lint/suspicious/noRedeclare)

🔇 Additional comments (14)
src/api/layers/group.layer.ts (5)

10-11: LGTM!

Import paths simplified to consolidated modules, which improves maintainability.


125-161: LGTM!

Clean refactor to async/await with proper validation and error propagation for string parameters.


168-207: LGTM!

Consistent async/await refactor with correct type validation.


246-272: The time parameter is not validated.

The time parameter is passed to WAPI.getGroupParticipant but is not included in the validation check array, unlike groupId. If time is a required string parameter, it should be validated for consistency with the other methods.

🔎 Proposed fix if validation is needed
     const check = [
       {
         param: 'groupId',
         type: type,
         value: groupId,
         function: typeFunction,
         isUser: true
+      },
+      {
+        param: 'time',
+        type: type,
+        value: time,
+        function: typeFunction,
+        isUser: false
       }
     ];

405-429: LGTM!

Consistent async/await refactor with proper validation.

src/api/layers/ui.layer.ts (1)

44-69: LGTM! Clean async/await refactor.

The refactoring from Promise constructor to direct async/await with throw-based error handling is well-executed and consistent with the broader PR changes across other layers.

src/api/helpers/closes-browser.ts (1)

4-31: LGTM! Simplified monitoring loop.

The refactor from Promise-based nested loops to a straightforward infinite loop with async/await improves readability while preserving the monitoring behavior. The exit conditions are properly handled with early returns.

src/api/layers/profile.layer.ts (1)

38-53: LGTM! Consistent async refactor.

The migration from Promise constructor to direct async/await with throw-based error handling aligns with the patterns applied across other layers in this PR.

src/api/layers/controls.layer.ts (1)

45-71: LGTM! Consistent async/await refactoring.

The refactoring of markUnseenMessage, markMarkSeenMessage, and pinChat from Promise constructors to direct async/await with throw-based error handling is clean and aligns with the PR objectives.

Also applies to: 78-104, 138-149

src/api/layers/retriever.layer.ts (3)

1-3: LGTM! Import organization.

The import reordering improves code organization without functional impact.


30-42: LGTM! Thorough async/await refactoring.

The refactoring of getAllMessagesDate, getNewMessageId, checkNumberStatus, and getNumberProfile consistently applies the direct async/await pattern with throw-based error handling, aligning with the PR objectives.

Also applies to: 44-70, 144-153, 272-296


111-115: LGTM! Simplified return path.

The simplification to directly return the WAPI result improves readability without changing behavior.

src/api/layers/sender.layer.ts (1)

53-70: Consistent async/await conversion looks good.

The refactor to async/await with throw-based error handling is applied consistently across all methods. The pattern of validating parameters, executing the WAPI call, and throwing on error is clear and maintainable.

src/controllers/initializer.ts (1)

131-139: Clean async/await refactor.

The conversion from Promise constructor pattern to a direct async function improves readability significantly. The error handling via throw and the linear flow make the initialization sequence much easier to follow. Status callbacks are properly integrated throughout.

@9cb14c1ec0 9cb14c1ec0 merged commit 925dedb into master Dec 31, 2025
3 checks passed
@9cb14c1ec0 9cb14c1ec0 deleted the updates branch December 31, 2025 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant