Skip to content

V5 refactor#3327

Open
smashah wants to merge 197 commits intomasterfrom
v5-refactor
Open

V5 refactor#3327
smashah wants to merge 197 commits intomasterfrom
v5-refactor

Conversation

@smashah
Copy link
Copy Markdown
Member

@smashah smashah commented Apr 20, 2026

No description provided.

git-subtree-dir: packages/socket-client
git-subtree-split: c3dc5c344f58dbd1966681a94cc08b914e2599bf
git-subtree-dir: packages/orchestrator
git-subtree-split: 06d295d777f2b60d7174b305ce77a6ee94f0d2f8
git-subtree-dir: apps/docker
git-subtree-split: 5e3cf42b9a5549e85804c31c05cc05f1c58fda47
git-subtree-dir: packages/wa-decrypt
git-subtree-split: 5bc722f45f39fb49c29c55eb9c777daa09361d68
git-subtree-dir: integrations/node-red
git-subtree-split: b6cb711ff9cfc296e865fe46ec2a2ed6baad006b
- Changed clientRegistry from Map<ZodFunction, meta> to Map<string, MethodDefinition>
- Added MethodDefinition interface: {schema, meta}
- Made functionName required in ClientFunctionMetadata
- Stored inputSchema and outputSchema directly in metadata for generator access
- Updated registry API: register(def), get(name), getBySchema(schema), getAll()
- Updated implementor to use getBySchema() for backward compatibility
- Updated gen-client-implementation.ts to destructure MethodDefinition
- Updated hono-server.ts to use new registry API and extract schemas correctly
- Updated socket-manager.ts to use new registry API and access metadata via def.meta
- Renamed executeCapability to executeMethod for consistency
- Created registry.contract.test.ts for registry API validation
- Created generators.contract.test.ts for generated file validation (types.ts, BaseClient.ts)
- Created routes.contract.test.ts for server route registration tests
- Created verify-v5-pipeline.ts for E2E verification script
- Added Jest configuration with ts-jest preset
- Updated package.json with test:contracts, verify, and ci scripts
- All 21 tests passing (6 skipped for OpenAPI generation - union type not supported without .openapi() metadata)
- Verification script passes with 121 methods across 9 namespaces
#3)

- Created event registry system symmetric with method registry
- Added EventMetadata, EventDefinition interfaces in schema
- Implemented defineListenerV2() for type-safe event callback schemas
- Created 10 core events: message, anyMessage, messageDeleted, ack,
  reaction, stateChanged, chatState, logout, participantsChanged, addedToGroup
- Added QueueOptionsSchema for p-queue integration with event handlers
- Created EventManager runtime class in core with:
  * PQueue-based rate limiting per event subscription
  * Type-safe payload validation using event schemas
  * Error isolation (fail loud but keep process alive)
  * Dynamic registry loading to avoid circular dependencies
- Integrated EventManager into Client class (client.events property)
- Both @open-wa/schema and @open-wa/core build successfully
- All contract tests passing (21 passed, 6 skipped)

PARTIAL IMPLEMENTATION of Issue #3:
- Schema layer: COMPLETE
- EventManager runtime: COMPLETE
- Client integration: BASIC (property added, initialized)
- WAPI event wiring: DEFERRED (requires deeper WAPI integration knowledge)
- Legacy wrapper methods: NOT NEEDED (existing methods work)
- Refactored EventManager to use dependency injection (no dynamic imports)
- EventManager now accepts optional EventRegistry in constructor
- Created WapiBridge class for open-source event marshalling layer
- WapiBridge sets up Puppeteer exposeFunction bridges (OSS)
- Actual WAPI injection remains proprietary (not in repo)
- Client.ts passes eventRegistry to EventManager via require()
- Added comprehensive architecture documentation (WapiBridge.md)

CLEAN ARCHITECTURE:
- Proprietary: wapi.js/patch.js injection + WhatsApp DOM scraping
- Open Source: WapiBridge (Puppeteer setup) + EventManager (distribution)
- Clear boundary: WAPI calls window.__onMessage → exposed fn → events.emit()

All builds passing, contract tests passing (21/27)
Schema definitions for 4 critical complex methods:
- decryptMedia: Decrypt media from messages
- downloadMedia: Download and save decrypted media
- sendFileFromUrl: Download and send files from URLs
- loadEarlierMessages: Load message history

All methods:
- Use defineMethodV2 with proper Zod schemas
- Include parameter descriptions and ordering
- Set appropriate action/namespace/license metadata
- Ready for runtime implementation in core package

Schema builds successfully, generates BaseClient with new methods.

PARTIAL: Schema layer complete, runtime implementations deferred.
- Updated .gitignore to exclude build artifacts (*.js, *.d.ts, *.map in src/)
- Added package-level .gitignore files for schema, core, and wa-automate
- Relocated generated files from src/generated to root-level generated/
- Updated generator scripts to write to new location
- Created tsconfig.generated.json for separate generated file compilation
- Updated package.json exports to include ./generated path
- Untracked old src/generated files from git

Fixes #05a (gitignore hygiene) and #05b (relocate generated files)
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 20, 2026

Important

Review skipped

Too many files!

This PR contains 297 files, which is 147 over the limit of 150.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 04abb161-bb2c-4f3e-ab51-a49456e6a733

📥 Commits

Reviewing files that changed from the base of the PR and between a8eefbe and 52b0ca9.

⛔ Files ignored due to path filters (3)
  • apps/dashboard-neo/public/favicon.ico is excluded by !**/*.ico
  • apps/dashboard-neo/src/logo.svg is excluded by !**/*.svg
  • docs/blog/2021-08-26-welcome/docusaurus-plushie-banner.jpeg is excluded by !**/*.jpeg
📒 Files selected for processing (297)
  • .changeset/README.md
  • .changeset/config.json
  • .changeset/pre.json
  • .codeium/windsurf-instructions.md
  • .coderabbit.yaml
  • .eslintrc.json
  • .github/agents/switchboard.agent.md
  • .github/copilot-instructions.md
  • .github/workflows/pr-docs-check.yml
  • .github/workflows/release.yml
  • .gitignore
  • .npmrc
  • .oxlintrc.json
  • .prettierrc.json
  • .release-it.json
  • .repomixignore
  • .serena/memories/audit-checklist.md
  • .serena/memories/session-ultrawork.md
  • AGENTS.md
  • MIGRATION-LOG.md
  • README.md
  • TODO.md
  • apps/cli/CHANGELOG.md
  • apps/cli/bin/wa
  • apps/cli/package.json
  • apps/cli/src/index.ts
  • apps/cli/tsconfig.json
  • apps/dashboard-neo/.cta.json
  • apps/dashboard-neo/.gitignore
  • apps/dashboard-neo/.prettierignore
  • apps/dashboard-neo/.prettierrc
  • apps/dashboard-neo/README.md
  • apps/dashboard-neo/components.json
  • apps/dashboard-neo/eslint.config.js
  • apps/dashboard-neo/index.html
  • apps/dashboard-neo/package.json
  • apps/dashboard-neo/public/manifest.json
  • apps/dashboard-neo/public/robots.txt
  • apps/dashboard-neo/src/components/app-sidebar.test.tsx
  • apps/dashboard-neo/src/components/app-sidebar.tsx
  • apps/dashboard-neo/src/components/connection-badge.tsx
  • apps/dashboard-neo/src/components/demo-toggle.tsx
  • apps/dashboard-neo/src/components/launch-console.tsx
  • apps/dashboard-neo/src/components/privacy-toggle.tsx
  • apps/dashboard-neo/src/components/search-form.tsx
  • apps/dashboard-neo/src/components/session-status-badge.tsx
  • apps/dashboard-neo/src/components/theme-provider.tsx
  • apps/dashboard-neo/src/components/theme-toggle.tsx
  • apps/dashboard-neo/src/components/ui/breadcrumb.tsx
  • apps/dashboard-neo/src/components/ui/button.tsx
  • apps/dashboard-neo/src/components/ui/dropdown-menu.tsx
  • apps/dashboard-neo/src/components/ui/input.tsx
  • apps/dashboard-neo/src/components/ui/label.tsx
  • apps/dashboard-neo/src/components/ui/separator.tsx
  • apps/dashboard-neo/src/components/ui/sheet.tsx
  • apps/dashboard-neo/src/components/ui/sidebar.tsx
  • apps/dashboard-neo/src/components/ui/skeleton.tsx
  • apps/dashboard-neo/src/components/ui/sonner.tsx
  • apps/dashboard-neo/src/components/ui/tooltip.tsx
  • apps/dashboard-neo/src/components/version-switcher.tsx
  • apps/dashboard-neo/src/dummy2.test.ts
  • apps/dashboard-neo/src/hooks/use-mobile.ts
  • apps/dashboard-neo/src/lib/api-client.ts
  • apps/dashboard-neo/src/lib/demo/demo-data.ts
  • apps/dashboard-neo/src/lib/demo/use-demo.ts
  • apps/dashboard-neo/src/lib/hooks/use-events.ts
  • apps/dashboard-neo/src/lib/hooks/use-health.ts
  • apps/dashboard-neo/src/lib/hooks/use-message-toasts.ts
  • apps/dashboard-neo/src/lib/hooks/use-privacy.tsx
  • apps/dashboard-neo/src/lib/hooks/use-session.ts
  • apps/dashboard-neo/src/lib/hooks/use-socket.ts
  • apps/dashboard-neo/src/lib/utils.ts
  • apps/dashboard-neo/src/main.tsx
  • apps/dashboard-neo/src/routeTree.gen.ts
  • apps/dashboard-neo/src/router.tsx
  • apps/dashboard-neo/src/routes/-mcp.test.tsx
  • apps/dashboard-neo/src/routes/__root.tsx
  • apps/dashboard-neo/src/routes/api-docs.tsx
  • apps/dashboard-neo/src/routes/apps.tsx
  • apps/dashboard-neo/src/routes/chat.tsx
  • apps/dashboard-neo/src/routes/contacts.tsx
  • apps/dashboard-neo/src/routes/debug.tsx
  • apps/dashboard-neo/src/routes/events.tsx
  • apps/dashboard-neo/src/routes/health.tsx
  • apps/dashboard-neo/src/routes/index.tsx
  • apps/dashboard-neo/src/routes/integrations.tsx
  • apps/dashboard-neo/src/routes/mcp.tsx
  • apps/dashboard-neo/src/routes/playground.tsx
  • apps/dashboard-neo/src/routes/plugins.$name.tsx
  • apps/dashboard-neo/src/routes/portal.tsx
  • apps/dashboard-neo/src/styles.css
  • apps/dashboard-neo/tsconfig.json
  • apps/dashboard-neo/vite.config.ts
  • apps/docker/.do/deploy.template.yaml
  • apps/docker/.dockerignore
  • apps/docker/.github/workflows/multireg.yml
  • apps/docker/.gitignore
  • apps/docker/Dockerfile
  • apps/docker/Dockerfile.legacy
  • apps/docker/README.md
  • apps/docker/docker-compose.yaml
  • apps/docker/env.js
  • apps/docker/flightcontrol.json
  • apps/docker/package.json
  • apps/docker/scripts/postinstall.js
  • apps/docker/start.sh
  • apps/docs/.source/browser.ts
  • apps/docs/.source/dynamic.ts
  • apps/docs/.source/server.ts
  • apps/docs/.source/source.config.mjs
  • apps/docs/LEGACY_DOCS_INVENTORY.md
  • apps/docs/cli.json
  • apps/docs/content/docs/client-and-integrations/cf-proxy.mdx
  • apps/docs/content/docs/client-and-integrations/chatwoot.mdx
  • apps/docs/content/docs/client-and-integrations/meta.json
  • apps/docs/content/docs/client-and-integrations/proxying-a-session.mdx
  • apps/docs/content/docs/client-and-integrations/socket-client.mdx
  • apps/docs/content/docs/client-and-integrations/webhook-payloads.mdx
  • apps/docs/content/docs/concepts/data-models.mdx
  • apps/docs/content/docs/concepts/glossary.mdx
  • apps/docs/content/docs/concepts/how-it-works.mdx
  • apps/docs/content/docs/concepts/meta.json
  • apps/docs/content/docs/concepts/packages.mdx
  • apps/docs/content/docs/getting-started/custom-code.mdx
  • apps/docs/content/docs/getting-started/docker.mdx
  • apps/docs/content/docs/getting-started/easy-api.mdx
  • apps/docs/content/docs/getting-started/link-code.mdx
  • apps/docs/content/docs/getting-started/meta.json
  • apps/docs/content/docs/guides/config-schema.mdx
  • apps/docs/content/docs/guides/configuration-and-cli.mdx
  • apps/docs/content/docs/guides/groups.mdx
  • apps/docs/content/docs/guides/media.mdx
  • apps/docs/content/docs/guides/messages.mdx
  • apps/docs/content/docs/guides/meta.json
  • apps/docs/content/docs/guides/multiple-sessions.mdx
  • apps/docs/content/docs/guides/session-events.mdx
  • apps/docs/content/docs/index.mdx
  • apps/docs/content/docs/licensing/licensed-features.mdx
  • apps/docs/content/docs/licensing/meta.json
  • apps/docs/content/docs/licensing/pricing.mdx
  • apps/docs/content/docs/meta.json
  • apps/docs/content/docs/operations-and-troubleshooting/best-practices.mdx
  • apps/docs/content/docs/operations-and-troubleshooting/detect-logouts.mdx
  • apps/docs/content/docs/operations-and-troubleshooting/error-handling.mdx
  • apps/docs/content/docs/operations-and-troubleshooting/meta.json
  • apps/docs/content/docs/reference/core.mdx
  • apps/docs/content/docs/reference/events.mdx
  • apps/docs/content/docs/reference/index.mdx
  • apps/docs/content/docs/reference/messaging.mdx
  • apps/docs/content/docs/reference/meta.json
  • apps/docs/package.json
  • apps/docs/public/_headers
  • apps/docs/scripts/copy-openapi.js
  • apps/docs/scripts/update-package-json.js
  • apps/docs/source.config.ts
  • apps/docs/src/components/ai/page-actions.tsx
  • apps/docs/src/components/ai/search.tsx
  • apps/docs/src/components/docs-mdx.tsx
  • apps/docs/src/components/docs-primitives.tsx
  • apps/docs/src/components/homepage.tsx
  • apps/docs/src/components/licensing.tsx
  • apps/docs/src/components/markdown.tsx
  • apps/docs/src/components/not-found.tsx
  • apps/docs/src/components/search.tsx
  • apps/docs/src/components/ui/button.tsx
  • apps/docs/src/components/ui/popover.tsx
  • apps/docs/src/lib/cn.ts
  • apps/docs/src/lib/get-llm-text.ts
  • apps/docs/src/lib/layout.shared.tsx
  • apps/docs/src/lib/site.ts
  • apps/docs/src/lib/source.ts
  • apps/docs/src/routeTree.gen.ts
  • apps/docs/src/router.tsx
  • apps/docs/src/routes/[.]well-known.agent-skills.index[.]json.ts
  • apps/docs/src/routes/[.]well-known.api-catalog.ts
  • apps/docs/src/routes/[.]well-known.mcp.server-card[.]json.ts
  • apps/docs/src/routes/[.]well-known.oauth-authorization-server.ts
  • apps/docs/src/routes/[.]well-known.oauth-protected-resource.ts
  • apps/docs/src/routes/__root.tsx
  • apps/docs/src/routes/api.chat.ts
  • apps/docs/src/routes/api/search.ts
  • apps/docs/src/routes/docs/$.tsx
  • apps/docs/src/routes/docs/-loader.server.ts
  • apps/docs/src/routes/index.tsx
  • apps/docs/src/routes/llms-full[.]txt.ts
  • apps/docs/src/routes/llms[.]mdx.docs.$.ts
  • apps/docs/src/routes/llms[.]txt.ts
  • apps/docs/src/routes/robots[.]txt.ts
  • apps/docs/src/routes/sitemap[.]xml.ts
  • apps/docs/src/start.ts
  • apps/docs/src/styles/app.css
  • apps/docs/test-gen.ts
  • apps/docs/tsconfig.json
  • apps/docs/vite.config.ts
  • apps/docs/wrangler.jsonc
  • compact-keepachangelog.hbs
  • dev.ts
  • docs/.gitignore
  • docs/README.md
  • docs/babel.config.js
  • docs/blog/2019-05-28-first-blog-post.md
  • docs/blog/2019-05-29-long-blog-post.md
  • docs/blog/2021-08-01-mdx-blog-post.mdx
  • docs/blog/2021-08-26-welcome/index.md
  • docs/blog/authors.yml
  • docs/blog/tags.yml
  • docs/components.json
  • docs/docs/Integrations/_category_.yml
  • docs/docs/Integrations/chatwoot.md
  • docs/docs/advanced/_category_.yml
  • docs/docs/advanced/best-practices.md
  • docs/docs/api/index.md
  • docs/docs/api/typedoc-sidebar.cjs
  • docs/docs/concepts/_category_.json
  • docs/docs/concepts/glossary.md
  • docs/docs/concepts/how-it-works.md
  • docs/docs/configuration/_category_.json
  • docs/docs/configuration/capture-qr.md
  • docs/docs/configuration/capture-sd.md
  • docs/docs/configuration/command-line-options.md
  • docs/docs/configuration/config-object.md
  • docs/docs/configuration/launch-events.md
  • docs/docs/configuration/licensed-features.mdx
  • docs/docs/configuration/multiple-sessions.md
  • docs/docs/configuration/the-client.md
  • docs/docs/get-started/_category_.json
  • docs/docs/get-started/docker.md
  • docs/docs/get-started/installation.md
  • docs/docs/get-started/link-code.md
  • docs/docs/get-started/quick-run.md
  • docs/docs/get-started/socketmode.md
  • docs/docs/how-to/_category_.yml
  • docs/docs/how-to/create-api.md
  • docs/docs/how-to/decrypt-media.md
  • docs/docs/how-to/detect-logout.md
  • docs/docs/how-to/groups.md
  • docs/docs/how-to/handle-errors.md
  • docs/docs/how-to/incoming-calls.md
  • docs/docs/how-to/location.md
  • docs/docs/how-to/manage-participants.md
  • docs/docs/how-to/misc.md
  • docs/docs/how-to/react-to-group-events.md
  • docs/docs/how-to/read-state.md
  • docs/docs/how-to/receive-files.md
  • docs/docs/how-to/receive-messages.md
  • docs/docs/how-to/send-files.md
  • docs/docs/how-to/send-messages.md
  • docs/docs/how-to/send-videos.md
  • docs/docs/how-to/sendfile.md
  • docs/docs/how-to/use-a-proxy.md
  • docs/docs/intro.md
  • docs/docs/reference/api/Client/classes/Client.md
  • docs/docs/reference/api/Client/enumerations/namespace.md
  • docs/docs/reference/api/Client/index.md
  • docs/docs/reference/api/Client/variables/useragent.md
  • docs/docs/reference/api/functions/exposed.enum/enumerations/ExposedFn.md
  • docs/docs/reference/api/functions/exposed.enum/index.md
  • docs/docs/reference/api/model/aliases/index.md
  • docs/docs/reference/api/model/aliases/type-aliases/AccountNumber.md
  • docs/docs/reference/api/model/aliases/type-aliases/AdvancedFile.md
  • docs/docs/reference/api/model/aliases/type-aliases/Base64.md
  • docs/docs/reference/api/model/aliases/type-aliases/ChatId.md
  • docs/docs/reference/api/model/aliases/type-aliases/ChatServer.md
  • docs/docs/reference/api/model/aliases/type-aliases/ContactId.md
  • docs/docs/reference/api/model/aliases/type-aliases/Content.md
  • docs/docs/reference/api/model/aliases/type-aliases/CountryCode.md
  • docs/docs/reference/api/model/aliases/type-aliases/DataURL.md
  • docs/docs/reference/api/model/aliases/type-aliases/FilePath.md
  • docs/docs/reference/api/model/aliases/type-aliases/GetURL.md
  • docs/docs/reference/api/model/aliases/type-aliases/GroupChatId.md
  • docs/docs/reference/api/model/aliases/type-aliases/GroupChatServer.md
  • docs/docs/reference/api/model/aliases/type-aliases/GroupId.md
  • docs/docs/reference/api/model/aliases/type-aliases/MessageId.md
  • docs/docs/reference/api/model/aliases/type-aliases/NonSerializedId.md
  • docs/docs/reference/api/model/aliases/type-aliases/WaServers.md
  • docs/docs/reference/api/model/button/index.md
  • docs/docs/reference/api/model/button/interfaces/AdvancedButton.md
  • docs/docs/reference/api/model/button/interfaces/Button.md
  • docs/docs/reference/api/model/button/interfaces/LocationButtonBody.md
  • docs/docs/reference/api/model/button/interfaces/Row.md
  • docs/docs/reference/api/model/button/interfaces/Section.md
  • docs/docs/reference/api/model/call/enumerations/CallState.md
  • docs/docs/reference/api/model/call/index.md
  • docs/docs/reference/api/model/call/interfaces/Call.md
  • docs/docs/reference/api/model/chat/enumerations/ChatMuteDuration.md
  • docs/docs/reference/api/model/chat/enumerations/ChatState.md
  • docs/docs/reference/api/model/chat/enumerations/ChatTypes.md
  • docs/docs/reference/api/model/chat/index.md
  • docs/docs/reference/api/model/chat/interfaces/BaseChat.md
  • docs/docs/reference/api/model/chat/interfaces/GroupChat.md
  • docs/docs/reference/api/model/chat/interfaces/GroupChatCreationParticipantAddResponse.md
  • docs/docs/reference/api/model/chat/interfaces/GroupChatCreationResponse.md
  • docs/docs/reference/api/model/chat/interfaces/LiveLocationChangedEvent.md
  • docs/docs/reference/api/model/chat/interfaces/SingleChat.md
  • docs/docs/reference/api/model/chat/type-aliases/Chat.md
  • docs/docs/reference/api/model/chat/type-aliases/EphemeralDuration.md
  • docs/docs/reference/api/model/config/enumerations/CLOUD_PROVIDERS.md

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch v5-refactor

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.

@smashah
Copy link
Copy Markdown
Member Author

smashah commented Apr 20, 2026

@coderabbitai please review!!!!

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 20, 2026

@smashah Sure! I'll kick off a review of the V5 refactor PR right away. 🚀

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@smashah
Copy link
Copy Markdown
Member Author

smashah commented Apr 21, 2026

@coderabbitai PLEASE REVIEW THIS PR!!!

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 2026

@smashah Absolutely! Triggering a full review of the V5 refactor PR right now! 🚀

✅ Actions performed

Full review triggered.

@smashah
Copy link
Copy Markdown
Member Author

smashah commented Apr 22, 2026

@coderabbitai WTF BRO I TOLD YOU TO REVIEW THE PR TWICE U DIDN DO IT YET

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

@smashah I sincerely apologize for the frustration — that's completely understandable. I'm triggering a full review of the PR right now. You should see the review comments appearing shortly. Sorry for the delays! 🙏

✅ Actions performed

Full review triggered.

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