Skip to content

refactor(server-kit)!: drop vault re-export & add domain-event handler dispose contract - #3113

Merged
tada5hi merged 1 commit into
masterfrom
refactor/server-kit-vault-dispose
Jun 12, 2026
Merged

tada5hi merged 1 commit into
masterfrom
refactor/server-kit-vault-dispose

Conversation

@tada5hi

@tada5hi tada5hi commented Jun 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #3112, resolving the two open review points:

  • Vault module removed: packages/server-kit/src/vault was a pure re-export of @hapic/vault (VaultClient, createVaultClient) with zero consumers in the monorepo after the singleton removal. The folder and the @hapic/vault dependency are gone; downstream users should import @hapic/vault directly. (packages/core-http-kit's own @hapic/vault dependency is unrelated and untouched.)
  • Handler lifecycle contract: IDomainEventHandler gains an optional dispose?(): Promise<void>; DomainEventPublisher.dispose() invokes it on every registered handler and clears the registry, and DatabaseModule.teardown() disposes the publisher before disconnecting the redis client it owns — so a future resource-owning handler (own connection, AMQP channel, …) cleans up on shutdown instead of leaking.

Breaking changes

  • @authup/server-kit no longer exports VaultClient / createVaultClient.

Test plan

  • server-kit & server-core build clean
  • npm run test --workspace=apps/server-core — 88 files / 865 tests pass
  • server-kit unit suite passes
  • ESLint clean; lockfile refreshed (@hapic/vault removed from server-kit's tree)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Breaking Changes

    • Vault client re-exports removed from package. Import directly from @hapic/vault instead.
  • New Features

    • Event handlers can now implement optional cleanup/disposal method.
    • Event publisher properly disposes all registered handlers on shutdown.
  • Improvements

    • Updated module exports to include logger, redis, and utilities.
    • Enhanced resource cleanup during module teardown.

… dispose contract

- Remove the vault module entirely (pure @hapic/vault re-export with no
  monorepo consumers; import @hapic/vault directly instead) and the
  @hapic/vault dependency.
- IDomainEventHandler gains an optional dispose() hook;
  DomainEventPublisher.dispose() invokes it on every registered handler
  and clears the registry. DatabaseModule.teardown() disposes the
  publisher before disconnecting the owned redis client, so future
  resource-owning handlers clean up on shutdown.

BREAKING CHANGE: @authup/server-kit no longer exports VaultClient /
createVaultClient.
Copilot AI review requested due to automatic review settings June 11, 2026 17:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR implements event publisher disposal lifecycle management by adding optional dispose hooks to domain event handlers, integrating publisher tracking into DatabaseModule for graceful teardown, and removes vault from server-kit's public API while updating documentation to reflect the architectural change.

Changes

Event Publisher Disposal and Server-Kit Cleanup

Layer / File(s) Summary
Event Handler Disposal Contract
packages/server-kit/src/domain-event/types.ts
IDomainEventHandler adds an optional dispose?(): Promise<void> method for handler cleanup beyond event handling.
DomainEventPublisher Disposal Implementation
packages/server-kit/src/domain-event/module.ts
DomainEventPublisher adds an async dispose() method that awaits each handler's optional dispose and clears the handler set.
DatabaseModule Event Publisher Lifecycle Tracking
apps/server-core/src/app/modules/database/module.ts
Module tracks the created publisher via new eventPublisher field, assigns it during registration, and asynchronously disposes it in teardown.
Server-Kit Public API Refactoring
packages/server-kit/package.json, packages/server-kit/src/index.ts
Removes @hapic/vault dependency and stops re-exporting vault module; adds exports for logger, redis, and utils.
Architecture Documentation Update
.agents/structure.md
Removes vault from described folder layout; clarifies that vault access now occurs through @hapic/vault directly rather than factory methods.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • authup/authup#2978: Complements this PR's vault removal by also dropping VaultModule from server-core and removing robot synchronization service dependencies on vault.

Poem

🐰 Disposing publishers with grace,
Event handlers find their closing place,
No vault locks hide away,
Just hapic's light to guide the way—
Cleanup complete, the code runs clean. 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: dropping vault re-exports and adding domain-event handler dispose contract, matching the substantive refactoring across multiple files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/server-kit-vault-dispose

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed due to a network error.


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.

@pkg-pr-new

pkg-pr-new Bot commented Jun 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

authup

npm i https://pkg.pr.new/authup@3113

@authup/client-web

npm i https://pkg.pr.new/@authup/client-web@3113

@authup/server-core

npm i https://pkg.pr.new/@authup/server-core@3113

@authup/access

npm i https://pkg.pr.new/@authup/access@3113

@authup/client-web-kit

npm i https://pkg.pr.new/@authup/client-web-kit@3113

@authup/client-web-kit-theme

npm i https://pkg.pr.new/@authup/client-web-kit-theme@3113

@authup/client-web-nuxt

npm i https://pkg.pr.new/@authup/client-web-nuxt@3113

@authup/client-web-theme

npm i https://pkg.pr.new/@authup/client-web-theme@3113

@authup/core-http-kit

npm i https://pkg.pr.new/@authup/core-http-kit@3113

@authup/core-kit

npm i https://pkg.pr.new/@authup/core-kit@3113

@authup/core-realtime-kit

npm i https://pkg.pr.new/@authup/core-realtime-kit@3113

@authup/errors

npm i https://pkg.pr.new/@authup/errors@3113

@authup/i18n

npm i https://pkg.pr.new/@authup/i18n@3113

@authup/kit

npm i https://pkg.pr.new/@authup/kit@3113

@authup/server-adapter-kit

npm i https://pkg.pr.new/@authup/server-adapter-kit@3113

@authup/server-adapter-node

npm i https://pkg.pr.new/@authup/server-adapter-node@3113

@authup/server-adapter-socket-io

npm i https://pkg.pr.new/@authup/server-adapter-socket-io@3113

@authup/server-adapter-web

npm i https://pkg.pr.new/@authup/server-adapter-web@3113

@authup/server-kit

npm i https://pkg.pr.new/@authup/server-kit@3113

@authup/server-test-kit

npm i https://pkg.pr.new/@authup/server-test-kit@3113

@authup/specs

npm i https://pkg.pr.new/@authup/specs@3113

commit: 77231fb

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/server-core/src/app/modules/database/module.ts (1)

108-116: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Guarantee Redis cleanup even when publisher disposal fails.

At Line 109, a thrown error from await this.eventPublisher.dispose() aborts teardown before Line 114, so the Redis client may never disconnect. Wrap disposal and disconnect paths in try/finally so connection cleanup is guaranteed.

Suggested patch
-        if (this.eventPublisher) {
-            await this.eventPublisher.dispose();
-            this.eventPublisher = undefined;
-        }
-
-        if (this.eventRedisClient) {
-            this.eventRedisClient.disconnect();
-            this.eventRedisClient = undefined;
-        }
+        try {
+            if (this.eventPublisher) {
+                await this.eventPublisher.dispose();
+            }
+        } finally {
+            this.eventPublisher = undefined;
+
+            if (this.eventRedisClient) {
+                this.eventRedisClient.disconnect();
+                this.eventRedisClient = undefined;
+            }
+        }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/server-core/src/app/modules/database/module.ts` around lines 108 - 116,
The teardown currently calls await this.eventPublisher.dispose() then
this.eventRedisClient.disconnect(), but if dispose throws the disconnect is
skipped; update the block around this.eventPublisher.dispose() and
this.eventRedisClient.disconnect() to ensure Redis is always disconnected by
using try/finally: call await this.eventPublisher.dispose() inside the try
(guarding null checks on this.eventPublisher), and in the finally ensure
this.eventRedisClient.disconnect() and clear this.eventRedisClient regardless of
errors; also clear this.eventPublisher = undefined after successful dispose or
in a catch as appropriate so both this.eventPublisher and this.eventRedisClient
are deterministically cleaned up.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@apps/server-core/src/app/modules/database/module.ts`:
- Around line 108-116: The teardown currently calls await
this.eventPublisher.dispose() then this.eventRedisClient.disconnect(), but if
dispose throws the disconnect is skipped; update the block around
this.eventPublisher.dispose() and this.eventRedisClient.disconnect() to ensure
Redis is always disconnected by using try/finally: call await
this.eventPublisher.dispose() inside the try (guarding null checks on
this.eventPublisher), and in the finally ensure
this.eventRedisClient.disconnect() and clear this.eventRedisClient regardless of
errors; also clear this.eventPublisher = undefined after successful dispose or
in a catch as appropriate so both this.eventPublisher and this.eventRedisClient
are deterministically cleaned up.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1d8c1302-47ef-4380-939f-0375b2fc79bc

📥 Commits

Reviewing files that changed from the base of the PR and between 2654d03 and 77231fb.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (8)
  • .agents/structure.md
  • apps/server-core/src/app/modules/database/module.ts
  • packages/server-kit/package.json
  • packages/server-kit/src/domain-event/module.ts
  • packages/server-kit/src/domain-event/types.ts
  • packages/server-kit/src/index.ts
  • packages/server-kit/src/vault/index.ts
  • packages/server-kit/src/vault/module.ts
💤 Files with no reviewable changes (4)
  • packages/server-kit/package.json
  • packages/server-kit/src/vault/module.ts
  • packages/server-kit/src/vault/index.ts
  • packages/server-kit/src/index.ts

@tada5hi
tada5hi merged commit 1773875 into master Jun 12, 2026
13 checks passed
@tada5hi
tada5hi deleted the refactor/server-kit-vault-dispose branch June 12, 2026 08:00
@github-actions github-actions Bot mentioned this pull request Jun 11, 2026
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.

2 participants