Skip to content

refactor!: restructure server-kit hub-style & replace singletons with DI - #3112

Merged
tada5hi merged 1 commit into
masterfrom
refactor/server-kit-hub-structure-di
Jun 11, 2026
Merged

tada5hi merged 1 commit into
masterfrom
refactor/server-kit-hub-structure-di

Conversation

@tada5hi

@tada5hi tada5hi commented Jun 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Mirrors PrivateAIM/hub's server-kit design and removes all global mutable state from @authup/server-kit and apps/server-core (net −1,361 lines).

@authup/server-kit

  • services/{cache,logger,redis,vault} flattened to top-level folders (hub's one-folder-per-concern layout, module.ts/types.ts/index.ts convention); type.ts → types.ts.
  • Logger & vault singletons deleted (useLogger, setLogger(Factory), isLoggerUsable, vault accessors); singa dependency dropped.
  • Logger is now a winston-shaped structural type (error/warn/info/http/verbose/debug) — consumers no longer depend on winston.
  • DomainEventPublisher follows hub's EntityEventPublisher: optional logger ctx, register(handler), and safePublish() (failures logged, never propagated into the originating DB transaction); redis/socket publishers became IDomainEventHandlers (domain-event/handlers/).

apps/server-core

  • Logger injected via DIP everywhere it was service-located: error & request-logger middlewares take it via options; RealmService / WebClientProvisioner via context. (Also fixes a latent crash: the error middleware's useLogger() threw on 500s when no logger was configured.)
  • New declarative EntitySubscriber<T> base (hub BaseSubscriber pattern, adapters/database/subscriber/) replaces 22 hand-written TypeORM subscribers (~110 → ~30 lines each). DatabaseModule registers the publisher under DatabaseInjectionKey.DomainEventPublisher and injects it via setPublisher() after dataSource.initialize(); teardown disconnects the event redis client and unregisters the token. The event-publisher and data-source singa singletons are deleted.
  • typeorm-extension's global registry is gone: identity-provider mapper/account repositories and OAuth2KeyRepository receive DataSource via constructor; setDataSource/useDataSource/unsetDataSource have zero call sites.
  • Cache-invalidation bug fixes (dead keys nothing ever populated): permission afterRemove used an unprefixed key, policy afterUpdate used CachePrefix.REALM, scope used CachePrefix.USER (dropped — no scope cache exists). Same-realm junction events are no longer published twice to the same namespace.

Breaking changes (@authup/server-kit)

  • Removed: useLogger, setLogger, setLoggerFactory, isLoggerUsable, setVaultFactory, useVaultClient, isVaultClientUsable.
  • Renamed: DomainEventRedisPublisher/DomainEventSocketPublisher → DomainEventRedisHandler/DomainEventSocketHandler; DomainEventPublisher.mount() → register(); IDomainEventPublisher gained safePublish.
  • Logger type narrowed from winston's Logger to a structural type.

Behavioral notes

  • Event-bus failures no longer abort the API write (hub safePublish semantics): at-most-once delivery, logged on failure.
  • Subscribers without an injected publisher (CLI migrations, bare test DataSources) skip publishing — equivalent to the previous empty-singleton behavior.

Test plan

  • npm run build for server-kit, server-core, all server-adapter packages, server-test-kit, and the authup CLI
  • npm run test --workspace=apps/server-core — 88 files / 862 tests pass (integration suite against Docker MySQL/Postgres/Redis)
  • server-kit, server-adapter-kit, server-test-kit unit suites pass
  • ESLint clean on all changed files
  • Monorepo-wide sweep: zero references to singa, useLogger, useDataSource, setDataSource remain in source

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Improvements

    • Enhanced domain event publishing with error handling that catches failures and prevents transaction disruption.
    • Improved HTTP error middleware logging capabilities.
  • Refactoring

    • Transitioned from global singleton patterns to dependency injection for improved reliability and testability.
    • Restructured database subscribers for cleaner configuration and event handling.
  • Chores

    • Removed unused dependency; corrected type import paths.

Mirror PrivateAIM/hub's server-kit design:

- server-kit: flatten services/{cache,logger,redis,vault} to top-level
  folders (module.ts/types.ts/index.ts convention), rename type.ts ->
  types.ts, drop the singa-based logger & vault singletons (useLogger,
  setLogger(Factory), isLoggerUsable, vault accessors) and the singa dep.
- Logger is now a winston-shaped structural type; consumers no longer
  depend on winston types.
- domain-event: DomainEventPublisher gains { logger } ctx, register()
  and safePublish() (event-bus failures are logged, never fail the
  originating transaction); redis/socket publishers become
  IDomainEventHandlers under domain-event/handlers/.
- server-core: logger is injected via DI (middlewares, RealmService,
  WebClientProvisioner) instead of useLogger(); new declarative
  EntitySubscriber base (hub BaseSubscriber pattern) replaces 22
  hand-written TypeORM subscribers; DatabaseModule registers the
  publisher in the container and injects it via setPublisher() after
  dataSource.initialize(); event-publisher & data-source singa
  singletons deleted.
- typeorm-extension global registry removed: identity-provider
  mapper/account repositories and OAuth2KeyRepository take DataSource
  via constructor; setDataSource/useDataSource have no call sites left.
- Fix dead cache-invalidation keys: permission afterRemove unprefixed
  key, policy afterUpdate REALM->POLICY prefix, scope dead USER key
  (dropped); dedupe same-realm event destinations.

BREAKING CHANGE: @authup/server-kit no longer exports useLogger /
setLogger / setLoggerFactory / isLoggerUsable / vault singleton
accessors; DomainEventRedisPublisher/DomainEventSocketPublisher are
renamed to DomainEventRedisHandler/DomainEventSocketHandler (mount ->
register); Logger is a structural type instead of winston's Logger.
Copilot AI review requested due to automatic review settings June 11, 2026 13:16

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

This PR eliminates global singleton patterns from the Authup framework by migrating to constructor-based dependency injection. It removes the singa library, refactors 24 entity subscribers onto a declarative base class, restructures domain event publishing from a publisher-mount to handler-register architecture with error-safe wrapping, injects DataSource and Logger through the DI container instead of global factories, and updates all module wiring accordingly. Architecture documentation is revised to reflect DI-first design principles.

Changes

Singleton Infrastructure Removal and Dependency Cleanup

Layer / File(s) Summary
Remove singa and update type imports
apps/server-core/package.json, packages/server-kit/package.json, packages/server-kit/src/logger/types.ts, packages/server-kit/src/crypto/json-web-token/...
Removes singa dependency. Introduces new logger and domain-event handler types in logger/types.ts. Fixes type import paths from ./type to ./types across crypto modules.
Delete singleton helper modules
packages/server-kit/src/services/logger/singleton.ts, packages/server-kit/src/services/logger/types.ts, packages/server-kit/src/services/vault/singleton.ts
Removes all singleton wiring functions (useLogger, useVaultClient, setLoggerFactory, etc.) that relied on singa.
Reorganize public exports
packages/server-kit/src/index.ts, packages/server-kit/src/logger/index.ts, packages/server-kit/src/vault/index.ts, packages/server-kit/src/domain-event/handlers/index.ts
Updates barrel exports to skip singleton modules and re-export cache/logger/redis/vault modules directly from the top-level index.

Domain Event Handler Refactoring

Layer / File(s) Summary
Define handler interface and update publisher contract
packages/server-kit/src/domain-event/types.ts
Adds IDomainEventHandler interface with handle() method. Extends IDomainEventPublisher with safePublish() method.
Refactor Redis and Socket handlers
packages/server-kit/src/domain-event/handlers/redis/module.ts, packages/server-kit/src/domain-event/handlers/socket/module.ts
Renames DomainEventRedisPublisher → DomainEventRedisHandler and DomainEventSocketPublisher → DomainEventSocketHandler. Both now implement IDomainEventHandler with handle() instead of IDomainEventPublisher.publish().
Rewrite DomainEventPublisher core logic
packages/server-kit/src/domain-event/module.ts, packages/server-kit/src/domain-event/utils.ts
Changes from managing IDomainEventPublisher instances (mount pattern) to managing IDomainEventHandler handlers (register pattern). Adds safePublish() wrapper that catches and logs errors without disrupting callers. Core publish() iterates handlers and calls handler.handle(ctx).
Update domain-event barrel exports
packages/server-kit/src/domain-event/index.ts, packages/server-kit/src/domain-event/handlers/index.ts
Re-exports ./handlers and ./types instead of individual ./redis/./socket/./type to provide unified handler export surface.

Declarative Entity Subscriber Base Class

Layer / File(s) Summary
Create EntitySubscriber base and context types
apps/server-core/src/adapters/database/subscriber/module.ts, apps/server-core/src/adapters/database/subscriber/types.ts, apps/server-core/src/adapters/database/subscriber/index.ts
Introduces EntitySubscriber<T> base class implementing EntitySubscriberInterface. Adds buildEntityDestinations helper. Defines EntitySubscriberContext and EntitySubscriberCacheContext types.
Refactor 24 entity subscribers
apps/server-core/src/adapters/database/domains/{client-permission,client-role,...,user}/subscriber.ts
All 24 subscribers refactored from explicit listenTo() + lifecycle methods to extend EntitySubscriber<T> with constructor-based configuration (entity type/target, destinations, cache settings). Removes manual event publishing and cache invalidation logic.
Export subscriber module
apps/server-core/src/adapters/database/index.ts
Adds re-export of ./subscriber/index.ts to expose EntitySubscriber utilities.

Dependency Injection Wiring

Layer / File(s) Summary
DatabaseModule: register publisher and inject into subscribers
apps/server-core/src/app/modules/database/module.ts, apps/server-core/src/app/modules/database/constants.ts
DatabaseModule creates DomainEventPublisher with optional logger, conditionally creates Redis client and registers handlers, registers publisher in DI container under DatabaseInjectionKey.DomainEventPublisher, and calls setPublisher() on all EntitySubscriber instances. Removes global setDataSource calls. Tracks Redis client lifecycle. Adds DomainEventPublisher injection token.
LoggerModule: register via DI only
apps/server-core/src/app/modules/logger/module.ts
Removes setLoggerFactory() call. Logger registration now driven entirely through DI container.
HTTP middleware: inject logger
apps/server-core/src/adapters/http/middleware/built-in/error.ts, apps/server-core/src/adapters/http/middleware/built-in/logger.ts, apps/server-core/src/app/modules/http/modules/middleware.ts
Error and logger middleware now accept logger via options. HTTPMiddlewareModule resolves logger from LoggerInjectionKey and passes to middleware creation.
HTTP controller and provisioning: inject logger
apps/server-core/src/app/modules/http/modules/controller.ts, apps/server-core/src/app/modules/provisioning/module.ts, apps/server-core/src/core/entities/client/web-client.ts, apps/server-core/src/core/entities/realm/service.ts
WebClientProvisioner, RealmService, and HTTP controller now accept optional logger via context and store it. Conditional logging replaces global useLogger() calls.
Identity and OAuth2 modules: inject DataSource
apps/server-core/src/app/modules/identity/module.ts, apps/server-core/src/app/modules/identity/repositories/provider/{account,mapper}/{attribute,permission,role}.ts, apps/server-core/src/app/modules/oauth2/module.ts, apps/server-core/src/app/modules/oauth2/repositories/key/repository.ts, apps/server-core/test/unit/core/identity/provider/account.spec.ts
Modules resolve dataSource from DatabaseInjectionKey and pass to repository constructors. Repositories store injected dataSource and use it instead of useDataSource().

Documentation

Layer / File(s) Summary
Architecture documentation
.agents/architecture.md
Documents SSR UI sub-path deployment with prefix rebasing. Removes singleton guidance; explicitly states DI-based service provisioning. Adds section on cross-cutting services (logging, domain events, entity subscribers) with no-singleton constraints. Updates file-structure diagram with subscriber modules.
Structure documentation
.agents/structure.md
Documents server-kit's per-concern layout, factory-based service creation, structural Logger type, and DomainEventPublisher handler aggregation with safePublish fail-safe semantics.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • authup/authup#2903: Refactors identity repository wiring away from useDataSource() by injecting DataSource instances—aligned with the main PR's identity module DataSource injection.
  • authup/authup#2928: Touches the same permission subscriber implementation with overlapping cache/event routing and scope changes.
  • authup/authup#3041: Changes HTTP error middleware handling in registerErrorMiddleware(...) for logging adjustments.

Poem

🐰 Singletons fade like morning dew,
DI containers bloom anew—
Twenty-four subscribers dance with grace,
Publishers yield to handlers' embrace. 🌱
No globals linger, all's injected bright,
Safe domain events won't disrupt the night! ✨

✨ 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-hub-structure-di

@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@3112

@authup/client-web

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

@authup/server-core

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

@authup/access

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

@authup/client-web-kit

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

@authup/client-web-kit-theme

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

@authup/client-web-nuxt

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

@authup/client-web-theme

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

@authup/core-http-kit

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

@authup/core-kit

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

@authup/core-realtime-kit

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

@authup/errors

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

@authup/i18n

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

@authup/kit

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

@authup/server-adapter-kit

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

@authup/server-adapter-node

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

@authup/server-adapter-socket-io

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

@authup/server-adapter-web

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

@authup/server-kit

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

@authup/server-test-kit

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

@authup/specs

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

commit: c17e8c6

@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.

Actionable comments posted: 1

Caution

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

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

93-95: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Declare ModuleName.LOGGER as a module dependency before resolving LoggerInjectionKey.

At Line 245, setup now requires LoggerInjectionKey, but Line 94 does not include ModuleName.LOGGER. This can break startup ordering and throw during provisioning setup.

Proposed fix
     constructor(sources: IProvisioningSource[] = []) {
         this.name = ModuleName.PROVISIONING;
-        this.dependencies = [ModuleName.CONFIG, ModuleName.DATABASE];
+        this.dependencies = [ModuleName.CONFIG, ModuleName.DATABASE, ModuleName.LOGGER];
         this.sources = sources;
     }

Also applies to: 245-245

🤖 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/provisioning/module.ts` around lines 93 -
95, The ModuleName.LOGGER dependency is missing from the provisioning module's
dependency list which causes LoggerInjectionKey resolution during setup (in
ModuleName.PROVISIONING's provisioning setup code) to race; update the
dependencies array in module.ts (where this.name = ModuleName.PROVISIONING and
this.dependencies = [...]) to include ModuleName.LOGGER alongside
ModuleName.CONFIG and ModuleName.DATABASE so the logger module is initialized
before LoggerInjectionKey is resolved in the setup logic.
apps/server-core/src/app/modules/database/module.ts (1)

96-109: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Ensure teardown cleanup runs even when DataSource.destroy() fails.

At Line 99, a thrown destroy error skips later cleanup, leaving DatabaseInjectionKey.DomainEventPublisher registered and eventRedisClient undisconnected. Move unregister/disconnect into a finally block.

Suggested fix
 async teardown(container: IContainer): Promise<void> {
-    const dataSource = container.tryResolve(DatabaseInjectionKey.DataSource);
-    if (dataSource.success) {
-        await dataSource.data.destroy();
-
-        container.unregister(DatabaseInjectionKey.DataSource);
-    }
-
-    container.unregister(DatabaseInjectionKey.DomainEventPublisher);
-
-    if (this.eventRedisClient) {
-        this.eventRedisClient.disconnect();
-        this.eventRedisClient = undefined;
-    }
+    try {
+        const dataSource = container.tryResolve(DatabaseInjectionKey.DataSource);
+        if (dataSource.success) {
+            await dataSource.data.destroy();
+            container.unregister(DatabaseInjectionKey.DataSource);
+        }
+    } finally {
+        container.unregister(DatabaseInjectionKey.DomainEventPublisher);
+        if (this.eventRedisClient) {
+            await 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 96 - 109,
The teardown method can bail out if dataSource.data.destroy() throws, preventing
cleanup; modify teardown in the module.ts to wrap the destroy call in a
try/finally (or try/catch/finally) so that
container.unregister(DatabaseInjectionKey.DomainEventPublisher) and the
eventRedisClient.disconnect()/undefined assignment always run in the finally
block, while still awaiting DataSource.destroy() and rethrowing or logging
errors as appropriate; reference the teardown function,
DatabaseInjectionKey.DataSource, DatabaseInjectionKey.DomainEventPublisher,
eventRedisClient, and DataSource.destroy() when making the change.
🧹 Nitpick comments (1)
packages/server-kit/src/domain-event/module.ts (1)

59-67: 💤 Low value

Consider simpler iteration syntax.

The while(true) loop with manual iterator is functionally correct but verbose. A for...of loop would be more idiomatic.

Suggested simplification
-        const handlers = this.handlers.values();
-        while (true) {
-            const it = handlers.next();
-            if (it.done) {
-                return;
-            }
-
-            await it.value.handle(ctx);
-        }
+        for (const handler of this.handlers) {
+            await handler.handle(ctx);
+        }
🤖 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 `@packages/server-kit/src/domain-event/module.ts` around lines 59 - 67, The
loop using an explicit iterator over this.handlers.values() (variables:
handlers, it) is verbose; replace the manual while(true) iterator in the method
with an idiomatic for...of over this.handlers.values() and await each
handler.handle(ctx) inside the loop (keep the same await semantics and early
return behavior by simply finishing the loop). This simplifies the code while
preserving behavior for the handlers iteration.
🤖 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.

Inline comments:
In `@packages/server-kit/src/domain-event/handlers/socket/module.ts`:
- Around line 23-24: The handler is mutating the shared
DomainEventPublishContext by assigning ctx.content =
transformDomainEventData(ctx.content); avoid this by creating a local const
content = transformDomainEventData(ctx.content) and then use that local content
for all subsequent operations inside async handle(ctx:
DomainEventPublishContext): Promise<void>, leaving ctx.content untouched so
other handlers get the original data; update all references in this module
(inside handle) to use the local content variable and keep
transformDomainEventData and DomainEventPublisher.publish usage unchanged.

---

Outside diff comments:
In `@apps/server-core/src/app/modules/database/module.ts`:
- Around line 96-109: The teardown method can bail out if
dataSource.data.destroy() throws, preventing cleanup; modify teardown in the
module.ts to wrap the destroy call in a try/finally (or try/catch/finally) so
that container.unregister(DatabaseInjectionKey.DomainEventPublisher) and the
eventRedisClient.disconnect()/undefined assignment always run in the finally
block, while still awaiting DataSource.destroy() and rethrowing or logging
errors as appropriate; reference the teardown function,
DatabaseInjectionKey.DataSource, DatabaseInjectionKey.DomainEventPublisher,
eventRedisClient, and DataSource.destroy() when making the change.

In `@apps/server-core/src/app/modules/provisioning/module.ts`:
- Around line 93-95: The ModuleName.LOGGER dependency is missing from the
provisioning module's dependency list which causes LoggerInjectionKey resolution
during setup (in ModuleName.PROVISIONING's provisioning setup code) to race;
update the dependencies array in module.ts (where this.name =
ModuleName.PROVISIONING and this.dependencies = [...]) to include
ModuleName.LOGGER alongside ModuleName.CONFIG and ModuleName.DATABASE so the
logger module is initialized before LoggerInjectionKey is resolved in the setup
logic.

---

Nitpick comments:
In `@packages/server-kit/src/domain-event/module.ts`:
- Around line 59-67: The loop using an explicit iterator over
this.handlers.values() (variables: handlers, it) is verbose; replace the manual
while(true) iterator in the method with an idiomatic for...of over
this.handlers.values() and await each handler.handle(ctx) inside the loop (keep
the same await semantics and early return behavior by simply finishing the
loop). This simplifies the code while preserving behavior for the handlers
iteration.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b954c267-e3b6-406f-b249-ed08d82598a2

📥 Commits

Reviewing files that changed from the base of the PR and between 7fa7a68 and c17e8c6.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (84)
  • .agents/architecture.md
  • .agents/structure.md
  • apps/server-core/package.json
  • apps/server-core/src/adapters/database/data-source/index.ts
  • apps/server-core/src/adapters/database/data-source/singleton.ts
  • apps/server-core/src/adapters/database/domains/client-permission/subscriber.ts
  • apps/server-core/src/adapters/database/domains/client-role/subscriber.ts
  • apps/server-core/src/adapters/database/domains/client-scope/subscriber.ts
  • apps/server-core/src/adapters/database/domains/client/subscriber.ts
  • apps/server-core/src/adapters/database/domains/identity-provider-account/subscriber.ts
  • apps/server-core/src/adapters/database/domains/identity-provider-attribute/subscriber.ts
  • apps/server-core/src/adapters/database/domains/identity-provider-role-mapping/subscriber.ts
  • apps/server-core/src/adapters/database/domains/identity-provider/subscriber.ts
  • apps/server-core/src/adapters/database/domains/permission/subscriber.ts
  • apps/server-core/src/adapters/database/domains/policy-attribute/subscriber.ts
  • apps/server-core/src/adapters/database/domains/policy/subscriber.ts
  • apps/server-core/src/adapters/database/domains/realm/subscriber.ts
  • apps/server-core/src/adapters/database/domains/robot-permission/subscriber.ts
  • apps/server-core/src/adapters/database/domains/robot-role/subscriber.ts
  • apps/server-core/src/adapters/database/domains/robot/subscriber.ts
  • apps/server-core/src/adapters/database/domains/role-attribute/subscriber.ts
  • apps/server-core/src/adapters/database/domains/role-permission/subscriber.ts
  • apps/server-core/src/adapters/database/domains/role/subscriber.ts
  • apps/server-core/src/adapters/database/domains/scope/subscriber.ts
  • apps/server-core/src/adapters/database/domains/user-attribute/subscriber.ts
  • apps/server-core/src/adapters/database/domains/user-permission/subscriber.ts
  • apps/server-core/src/adapters/database/domains/user-role/subscriber.ts
  • apps/server-core/src/adapters/database/domains/user/subscriber.ts
  • apps/server-core/src/adapters/database/event-publisher/module.ts
  • apps/server-core/src/adapters/database/index.ts
  • apps/server-core/src/adapters/database/subscriber/index.ts
  • apps/server-core/src/adapters/database/subscriber/module.ts
  • apps/server-core/src/adapters/database/subscriber/types.ts
  • apps/server-core/src/adapters/http/middleware/built-in/error.ts
  • apps/server-core/src/adapters/http/middleware/built-in/logger.ts
  • apps/server-core/src/app/modules/database/constants.ts
  • apps/server-core/src/app/modules/database/module.ts
  • apps/server-core/src/app/modules/http/modules/controller.ts
  • apps/server-core/src/app/modules/http/modules/middleware.ts
  • apps/server-core/src/app/modules/identity/module.ts
  • apps/server-core/src/app/modules/identity/repositories/provider/account/module.ts
  • apps/server-core/src/app/modules/identity/repositories/provider/mapper/attribute.ts
  • apps/server-core/src/app/modules/identity/repositories/provider/mapper/permission.ts
  • apps/server-core/src/app/modules/identity/repositories/provider/mapper/role.ts
  • apps/server-core/src/app/modules/logger/module.ts
  • apps/server-core/src/app/modules/oauth2/module.ts
  • apps/server-core/src/app/modules/oauth2/repositories/key/repository.ts
  • apps/server-core/src/app/modules/provisioning/module.ts
  • apps/server-core/src/core/entities/client/web-client.ts
  • apps/server-core/src/core/entities/realm/service.ts
  • apps/server-core/test/unit/core/identity/provider/account.spec.ts
  • packages/server-kit/package.json
  • packages/server-kit/src/cache/adapters/index.ts
  • packages/server-kit/src/cache/adapters/memory.ts
  • packages/server-kit/src/cache/adapters/redis.ts
  • packages/server-kit/src/cache/helper.ts
  • packages/server-kit/src/cache/index.ts
  • packages/server-kit/src/cache/types.ts
  • packages/server-kit/src/crypto/json-web-token/index.ts
  • packages/server-kit/src/crypto/json-web-token/sign/types.ts
  • packages/server-kit/src/crypto/json-web-token/types.ts
  • packages/server-kit/src/crypto/json-web-token/verify/types.ts
  • packages/server-kit/src/domain-event/handlers/index.ts
  • packages/server-kit/src/domain-event/handlers/redis/index.ts
  • packages/server-kit/src/domain-event/handlers/redis/module.ts
  • packages/server-kit/src/domain-event/handlers/socket/index.ts
  • packages/server-kit/src/domain-event/handlers/socket/module.ts
  • packages/server-kit/src/domain-event/index.ts
  • packages/server-kit/src/domain-event/module.ts
  • packages/server-kit/src/domain-event/types.ts
  • packages/server-kit/src/domain-event/utils.ts
  • packages/server-kit/src/index.ts
  • packages/server-kit/src/logger/index.ts
  • packages/server-kit/src/logger/module.ts
  • packages/server-kit/src/logger/types.ts
  • packages/server-kit/src/redis/check.ts
  • packages/server-kit/src/redis/factory.ts
  • packages/server-kit/src/redis/index.ts
  • packages/server-kit/src/redis/module.ts
  • packages/server-kit/src/services/logger/singleton.ts
  • packages/server-kit/src/services/logger/types.ts
  • packages/server-kit/src/services/vault/singleton.ts
  • packages/server-kit/src/vault/index.ts
  • packages/server-kit/src/vault/module.ts
💤 Files with no reviewable changes (10)
  • apps/server-core/src/adapters/database/event-publisher/module.ts
  • packages/server-kit/src/vault/index.ts
  • packages/server-kit/src/services/vault/singleton.ts
  • packages/server-kit/src/services/logger/singleton.ts
  • packages/server-kit/package.json
  • packages/server-kit/src/services/logger/types.ts
  • apps/server-core/src/adapters/database/data-source/index.ts
  • apps/server-core/src/adapters/database/data-source/singleton.ts
  • apps/server-core/package.json
  • packages/server-kit/src/logger/index.ts

Comment on lines +23 to 24
async handle(ctx: DomainEventPublishContext) : Promise<void> {
ctx.content = transformDomainEventData(ctx.content);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Avoid mutating the shared context object.

ctx.content is mutated directly, but the same ctx object is passed to all registered handlers by DomainEventPublisher.publish(). If multiple handlers are registered, the mutation affects subsequent handlers—potentially causing double-transformation or inconsistent event data depending on handler execution order.

Proposed fix
 async handle(ctx: DomainEventPublishContext) : Promise<void> {
-    ctx.content = transformDomainEventData(ctx.content);
+    const content = transformDomainEventData(ctx.content);

     for (let i = 0; i < ctx.destinations.length; i++) {
         const destination = ctx.destinations[i];
         // ... rest uses `content` instead of `ctx.content`

Then update all references to ctx.content within this method to use the local content variable.

🤖 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 `@packages/server-kit/src/domain-event/handlers/socket/module.ts` around lines
23 - 24, The handler is mutating the shared DomainEventPublishContext by
assigning ctx.content = transformDomainEventData(ctx.content); avoid this by
creating a local const content = transformDomainEventData(ctx.content) and then
use that local content for all subsequent operations inside async handle(ctx:
DomainEventPublishContext): Promise<void>, leaving ctx.content untouched so
other handlers get the original data; update all references in this module
(inside handle) to use the local content variable and keep
transformDomainEventData and DomainEventPublisher.publish usage unchanged.

@tada5hi
tada5hi merged commit 2654d03 into master Jun 11, 2026
14 checks passed
@tada5hi
tada5hi deleted the refactor/server-kit-hub-structure-di branch June 11, 2026 15:53
@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